本文整理汇总了Python中pyjamas.Timer.Timer类的典型用法代码示例。如果您正苦于以下问题:Python Timer类的具体用法?Python Timer怎么用?Python Timer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Timer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
class Feed:
def __init__(self, url, callback):
global frameId
frame = DOM.createElement("iframe")
frameid = "__pygwt_feedFrame%d" % frameId
frameId += 1
DOM.setAttribute(frame, "id", frameid)
DOM.setAttribute(frame, "src", url)
#DOM.setStyleAttribute(frame, 'width', '0')
#DOM.setStyleAttribute(frame, 'height', '0')
#DOM.setStyleAttribute(frame, 'border', '0')
#DOM.setStyleAttribute(frame, 'position', 'absolute')
self.frameId = frameId
self.frame = frame
self.timer = Timer(notify=self)
doc().parent.body.appendChild(frame)
self.callback = callback
self.timer.scheduleRepeating(100)
def getFrameTxt(self):
return str(self.frame.contentWindow.document.body.innerHTML)
def onTimer(self, *args):
txt = self.getFrameTxt()
if txt == '':
return
self.callback(self, txt)
self.timer.cancel()
示例2: __init__
def __init__(self, countdown=1000):
Timer.__init__(self)
Label.__init__(self)
self.countdown = countdown
self.task_id = None
self.wait_cnt = 0
self.remote_py = \
EchoServicePython(server="flask", flask_view_type="celery")
示例3: __init__
def __init__(self, max_tries = 10, interval = 500):
Timer.__init__(self)
self.interval = interval
self.max_tries = max_tries
self.tries = 0
self.func = func
self.params = params
self.scheduleRepeating(self.interval)
示例4: Spinner
class Spinner(PopupPanel):
def __init__(self, text=''):
PopupPanel.__init__(self)
self.width = 15
self.r1 = 35
self.r2 = 60
self.cx = self.r2 + self.width
self.cy = self.r2 + self.width
self.numSectors = 12
self.size = self.r2*2 + self.width*2
self.speed = 1.5 # seconds per rotation
self._timer = None
self.canvas = Raphael(self.size, self.size)
self.sectors = []
self.opacity = []
vp = VerticalPanel()
vp.add(self.canvas)
blurb = HTML(text)
blurb.setStyleAttribute('text-align', 'center')
vp.add(blurb)
self.add(vp)
def draw(self):
colour = "#000000"
beta = 2 * math.pi / self.numSectors
pathParams = {'stroke' : colour,
'stroke-width' : self.width,
'stroke-linecap' : "round"}
for i in range(self.numSectors):
alpha = beta * i - math.pi/2
cos = math.cos(alpha)
sin = math.sin(alpha)
data = ','.join(['M',
str(self.cx + self.r1 * cos),
str(self.cy + self.r1 * sin),
'L',
str(self.cx + self.r2 * cos),
str(self.cy + self.r2 * sin)])
path = self.canvas.path(data=data, attrs=pathParams)
self.opacity.append(1.0 * i / self.numSectors )
self.sectors.append(path)
period = (self.speed * 1000) / self.numSectors
self._timer = Timer(notify=self)
self._timer.scheduleRepeating(period)
def onTimer(self, _):
self.opacity.insert(0, self.opacity.pop())
for i in range(self.numSectors):
self.sectors[i].setAttr("opacity", self.opacity[i])
示例5: delay
def delay(s):
if STATMODE:
return # NO TIME FOR SLEEP IN STATMODE
if USING_PYGAME:
from time import sleep
sleep(s)
else:
from pyjamas.Timer import Timer
timer = Timer(notify=update)
timer.schedule(s * 1000)
示例6: __init__
def __init__(self, countdown):
# It's a Timer, no it's a Button, WAIT! It's BOTH!!
Timer.__init__(self)
Button.__init__(self)
# save the countdown value
self.countdown_save = countdown
# this instance handles the clicks
self.addClickListener(self)
# the box the popups go into
self.box = SimplePanel(StyleName='popupbox')
# kickstart
self.reset()
示例7: TestPanel
class TestPanel(SimplePanel):
""" Our testing panel.
"""
def __init__(self):
""" Standard initialiser.
"""
SimplePanel.__init__(self)
# Taken from the "spinner" Raphael demo:
colour = "#000000"
width = 15
r1 = 35
r2 = 60
cx = r2 + width
cy = r2 + width
self.numSectors = 12
self.canvas = Raphael(r2*2 + width*2, r2*2 + width*2)
self.sectors = []
self.opacity = []
beta = 2 * math.pi / self.numSectors
pathParams = {'stroke' : colour,
'stroke-width' : width,
'stroke-linecap' : "round"}
for i in range(self.numSectors):
alpha = beta * i - math.pi/2
cos = math.cos(alpha)
sin = math.sin(alpha)
path = self.canvas.path(data=None, attrs=pathParams)
path.moveTo(cx + r1 * cos, cy + r1 * sin)
path.lineTo(cx + r2 * cos, cy + r2 * sin)
self.opacity.append(1 / self.numSectors * i)
self.sectors.append(path)
period = 1000/self.numSectors
self._timer = Timer(notify=self)
self._timer.scheduleRepeating(period)
self.add(self.canvas)
def onTimer(self, timer):
""" Respond to our timer firing.
"""
self.opacity.insert(0, self.opacity.pop())
for i in range(self.numSectors):
self.sectors[i].setAttr("opacity", self.opacity[i])
示例8: Timer
class Clock:
# pyjamas doesn't generate __doc__
__doc__ = '''This demonstrates using Timer instantiated with the
notify keyword, as in:<pre> timer = Timer(notify=func) </pre>When
the timer fires it will call func() with no arguments (or
<code>self</code> if it is a bound method as in this example).
This timer is scheduled with the <code>scheduleRepeating()</code>
method, so after func() is called, it is automatically rescheduled
to fire again after the specified period. The timer can be
cancelled by calling the <code>cancel()</code> method; this
happens when you click on the button.
'''
start_txt = 'Click to start the clock'
stop_txt = 'Click to stop the clock'
def __init__(self):
# the button
self.button = Button(listener=self)
# set an attr on the button to keep track of its state
self.button.stop = False
# date label
self.datelabel = Label(StyleName='clock')
# the timer
self.timer = Timer(notify=self.updateclock)
# kick start
self.onClick(self.button)
def onClick(self, button):
if self.button.stop:
# we're stopping the clock
self.button.stop = False
self.timer.cancel()
self.button.setText(self.start_txt)
else:
# we're starting the clock
self.button.stop = True
self.timer.scheduleRepeating(1000)
self.button.setText(self.stop_txt)
def updateclock(self, timer):
# the callable attached to the timer with notify
dt = datetime.now().replace(microsecond=0)
self.datelabel.setText(dt.isoformat(' '))
示例9: __init__
def __init__(self, symbol_shape, message_symbol_coder, symbol_signal_coder):
self.timer = Timer(notify=self)
self.setTimer(self.timer)
self.symbol_shape = symbol_shape
self.message_symbol_coder = message_symbol_coder
self.symbol_signal_coder = symbol_signal_coder
self.decoded = {}
示例10: draw
def draw(self):
colour = "#000000"
beta = 2 * math.pi / self.numSectors
pathParams = {'stroke' : colour,
'stroke-width' : self.width,
'stroke-linecap' : "round"}
for i in range(self.numSectors):
alpha = beta * i - math.pi/2
cos = math.cos(alpha)
sin = math.sin(alpha)
data = ','.join(['M',
str(self.cx + self.r1 * cos),
str(self.cy + self.r1 * sin),
'L',
str(self.cx + self.r2 * cos),
str(self.cy + self.r2 * sin)])
path = self.canvas.path(data=data, attrs=pathParams)
self.opacity.append(1.0 * i / self.numSectors )
self.sectors.append(path)
period = (self.speed * 1000) / self.numSectors
self._timer = Timer(notify=self)
self._timer.scheduleRepeating(period)
示例11: Spinner
class Spinner(SimplePanel):
""" Our testing panel.
"""
def __init__(self,width=600,height=300):
""" Standard initialiser.
"""
SimplePanel.__init__(self)
# Taken from the "spinner" Raphael demo:
self.width = 15
self.r1 = 35
self.r2 = 60
self.cx = self.r2 + self.width
self.cy = self.r2 + self.width
self.numSectors = 12
self.canvas = Raphael(self.r2*2 + self.width*2, self.r2*2 + self.width*2)
self.sectors = []
self.opacity = []
self.add(self.canvas)
def draw(self):
colour = "#000000"
beta = 2 * math.pi / self.numSectors
pathParams = {'stroke' : colour,
'stroke-width' : self.width,
'stroke-linecap' : "round"}
for i in range(self.numSectors):
alpha = beta * i - math.pi/2
cos = math.cos(alpha)
sin = math.sin(alpha)
data=','.join(['M',str(self.cx + self.r1 * cos),str(self.cy + self.r1 * sin),'L',str(self.cx + self.r2 * cos),str(self.cy + self.r2 * sin)])
path = self.canvas.path(data=data,attrs=pathParams)
self.opacity.append(1.0 * i / self.numSectors )
self.sectors.append(path)
period = 1000/self.numSectors
self._timer = Timer(notify=self)
self._timer.scheduleRepeating(period)
def onTimer(self, timerID):
""" Respond to our timer firing.
"""
self.opacity.insert(0, self.opacity.pop())
for i in range(self.numSectors):
self.sectors[i].setAttr("opacity", self.opacity[i])
示例12: Tooltip
class Tooltip(PopupPanel):
def __init__(self, sender, offsetX, offsetY, contents,
show_delay, hide_delay, styleName, **kwargs):
""" contents may be a text string or it may be a widget
"""
PopupPanel.__init__(self, True, **kwargs)
self.show_delay = show_delay
self.hide_delay = hide_delay
if isinstance(contents, basestring):
contents = HTML(contents)
self.add(contents)
left = sender.getAbsoluteLeft() + offsetX
top = sender.getAbsoluteTop() + offsetY
self.setPopupPosition(left, top)
self.setStyleName(styleName)
if tooltip_hide_timer:
self.tooltip_show_timer = Timer(1, self)
else:
self.tooltip_show_timer = Timer(self.show_delay, self)
def show(self):
global tooltip_hide_timer
# activate fast tooltips
tooltip_hide_timer = Timer(self.hide_delay, self)
PopupPanel.show(self)
def hide(self, autoClosed=False):
self.tooltip_show_timer.cancel()
PopupPanel.hide(self, autoClosed)
def onTimer(self, timer):
global tooltip_hide_timer
# deactivate fast tooltips on last timer
if timer is tooltip_hide_timer:
tooltip_hide_timer = None
if timer is self.tooltip_show_timer:
self.show()
else:
self.hide()
示例13: start_game
def start_game(self, view):
self.view = view
self.model.start_game(view)
self.model.reset()
#setup a timer
self.timer = Timer(notify=self.update)
self.timer.scheduleRepeating(1000/FPS)
示例14: queuereduce
def queuereduce(sender, maxlines=1000):
showOutputMeta("Reducing...")
outputPanel.add(HTML(" "))
outputPanel.add(HTML(" "))
outputPanel.add(
HTML(
"""
<p>Takes too long? Try the <a href="https://bitbucket.org/bgeron
</continuation-calculus-paper/">Python evaluator.</a>.</p>
""".strip()
)
)
# Schedule reduceterm(maxlines) really soon.
timer = Timer(notify=functools.partial(reduceterm, maxlines=maxlines))
timer.schedule(50) # after 50 milliseconds
示例15: transfer_tinymce
def transfer_tinymce(self):
new_script = DOM.createElement("script")
new_script.innerHTML = """
var ed = tinyMCE.get('%s');
var data = ed.getContent({'format': 'raw'});
frame = document.getElementById('__edit_%s');
frame.innerText = data;
ed.save();
ed.remove();
""" % (self.editor_id, self.editor_id)
self.editor_created = False
DOM.setElemAttribute(new_script, "type","text/javascript")
doc().body.appendChild(new_script)
self.hide()
t = Timer(notify=self)
t.scheduleRepeating(1000)