本文整理汇总了Python中pyjamas.Timer.Timer类的典型用法代码示例。如果您正苦于以下问题:Python Timer类的具体用法?Python Timer怎么用?Python Timer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Timer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:Afey,项目名称:pyjs,代码行数:29,代码来源:Feed.py
示例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")
开发者ID:brodybits,项目名称:pyjs,代码行数:8,代码来源:FLASKCELERYExample.py
示例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)
开发者ID:cy245,项目名称:TextbookConnect,代码行数:8,代码来源:page_book_comments.py
示例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])
开发者ID:sean-m-brennan,项目名称:pysysdevel,代码行数:56,代码来源:spinner.py
示例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)
开发者ID:ThatSnail,项目名称:OthelloBot,代码行数:12,代码来源:main.py
示例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()
开发者ID:anandology,项目名称:pyjamas,代码行数:13,代码来源:timerdemo.py
示例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])
开发者ID:Afey,项目名称:pyjs,代码行数:50,代码来源:test.py
示例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(' '))
开发者ID:anandology,项目名称:pyjamas,代码行数:48,代码来源:timerdemo.py
示例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 = {}
开发者ID:davidmi,项目名称:cryptogram,代码行数:7,代码来源:SeeMeNot.py
示例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)
开发者ID:sean-m-brennan,项目名称:pysysdevel,代码行数:25,代码来源:spinner.py
示例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])
开发者ID:anandology,项目名称:pyjamas,代码行数:47,代码来源:spinner.py
示例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()
开发者ID:anandology,项目名称:pyjamas,代码行数:46,代码来源:Tooltip.py
示例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)
开发者ID:Afey,项目名称:pyjs,代码行数:8,代码来源:game_controller.py
示例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
开发者ID:ThreeLetterNames,项目名称:continuation-calculus-paper,代码行数:17,代码来源:cc_eval.py
示例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)
开发者ID:brodybits,项目名称:pyjs,代码行数:19,代码来源:TinyMCEditor.py
示例16: __init__
class Controller:
def __init__(self, model):
self.model = model
self.key_up = False
self.key_down = False
self.key_left = False
self.key_right = False
self.key_fire = False
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)
def update(self):
self.keyboard_updates()
self.model.update()
def keyboard_updates(self):
ship = self.model.ship
drot = 0
if self.key_left:
drot -= ROTATE_SPEED
if self.key_right:
drot += ROTATE_SPEED
if drot:
ship.rotate_ship(drot)
if self.key_up:
ship.thrust()
else:
ship.friction()
if self.key_fire:
self.model.trigger_fire()
开发者ID:Afey,项目名称:pyjs,代码行数:40,代码来源:game_controller.py
示例17: __init__
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)
开发者ID:anandology,项目名称:pyjamas,代码行数:22,代码来源:Tooltip.py
示例18: __init__
def __init__(self):
self.dropTargets = []
self.dragging = NOT_DRAGGING
self.dragBusy = False
self._currentTargetElement = None
self.previousDropTarget = None
self.draggingImage = None
self.origMouseX = 0
self.origMouseY = 0
self.currentDragOperation = 'none'
self.data = None
self.returnTimer = Timer(notify=self.onReturningWidget)
self.mouseEvent = None
self.dragDataStore = None
开发者ID:Afey,项目名称:pyjs,代码行数:14,代码来源:DNDHelper.py
示例19: __init__
def __init__(self) :
# Since this is a singleton, throw an exception if the constructor is called
# explicitly.
if DataRunManager._onlyInstance!=None :
raise Exception( "DataRunManager is a singleton class. Call 'DataRunManager.instance()' to get the only running instance" )
self.rpcService=GlibRPCService.instance()
self.pollingTimer=Timer( notify=self.pollRPCService )
self.eventHandlers = []
self.fractionComplete = 1
self.statusString = "Not taking data"
self.firstRun = True
# I'll poll once immediately on startup just in case the user is connecting to an
# already running service. The code that handles the response to this starts the
# timer running.
self.pollRPCService()
开发者ID:BristolHEP-CBC-Testing,项目名称:cbcanalysis,代码行数:15,代码来源:DataRunManager.py
示例20: __init__
def __init__(self):
Composite.__init__(self)
self.albums = []
self.photos = []
self.grid = Grid(4, 4, CellPadding=4, CellSpacing=4)
self.grid.addTableListener(self)
self.drill = 0
self.pos = 0
self.up = Button("Up", self)
self.next = Button("Next", self)
self.prev = Button("Prev", self)
self.timer = Timer(notify=self)
self.userid = "jameskhedley"
self.album_url = "http://picasaweb.google.com/data/feed/base/user/" + self.userid + "?alt=json-in-script&kind=album&hl=en_US&callback=restCb"
self.doRESTQuery(self.album_url, self.timer)
self.vp = VerticalPanel()
self.disclosure = DisclosurePanel("Click for boring technical details.")
self.disclosure.add(HTML('''<p>OK so you want to write client JS to do a RESTful HTTP query from picasa right?
Well you can't because of the Same Origin Policy. Basically this means that
because the domain of the query and the domain of the hosted site are different,
then that could well be a cross-site scripting (XSS) attack. So, the workaround is to
do the call from a script tag so the JSON we get back is part of the document.
But since we don't know what URL to hit yet, once we find out then we have to inject
a new script tag dynamically which the browser will run as soon as we append it.
To be honest I'm not 100% why Google use RESTful services and not JSON-RPC or somesuch,
which would be easier. Well, easier for me.'''))
self.IDPanel = HorizontalPanel()
self.IDPanel.add(Label("Enter google account:"))
self.IDButton = Button("Go", self)
self.IDBox = TextBox()
self.IDBox.setText(self.userid)
self.IDPanel.add(self.IDBox)
self.IDPanel.add(self.IDButton)
self.vp.add(self.IDPanel)
self.vp.add(self.disclosure)
self.vp.add(self.grid)
self.initWidget(self.vp)
开发者ID:anandology,项目名称:pyjamas,代码行数:42,代码来源:Photos.py
注:本文中的pyjamas.Timer.Timer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论