本文整理汇总了Python中pyjamas.Timer.Timer.scheduleRepeating方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.scheduleRepeating方法的具体用法?Python Timer.scheduleRepeating怎么用?Python Timer.scheduleRepeating使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.Timer.Timer
的用法示例。
在下文中一共展示了Timer.scheduleRepeating方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import scheduleRepeating [as 别名]
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: Spinner
# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import scheduleRepeating [as 别名]
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])
示例3: TestPanel
# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import scheduleRepeating [as 别名]
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])
示例4: Timer
# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import scheduleRepeating [as 别名]
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(' '))
示例5: Spinner
# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import scheduleRepeating [as 别名]
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])
示例6: transfer_tinymce
# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import scheduleRepeating [as 别名]
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)
示例7: __init__
# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import scheduleRepeating [as 别名]
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()
示例8: RichTextToolbar
# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import scheduleRepeating [as 别名]
#.........这里部分代码省略.........
rng.collapse(start)
self.getSelection()
Selection.setRange(rng)
self.refresh()
def run(self):
try:
self.getSelection()
rng = Selection.getRange()
if (self.timerRange is None) or (not self.timerRange.equals(rng)):
self.onSelectionChange(rng)
self.timerRange = rng
except:
GWT.log("Error in timer selection", ex)
def getSelection(self):
res = None
try:
window = self.getWindow()
Selection.getSelection(window)
except:
print "Error getting the selection"
traceback.print_exc()
def getWindow(self, iFrame=None):
if iFrame is None:
iFrame = self.richText.getElement()
iFrameWin = iFrame.contentWindow or iFrame.contentDocument
if not iFrameWin.document:
iFrameWin = iFrameWin.parentNode # FBJS version of parentNode
#print "getWindow", iFrameWin, dir(iFrameWin)
return iFrameWin
def captureSelection(self):
""" This captures the selection when the mouse leaves the RTE,
because in IE the selection indicating the cursor position
is lost once another widget gains focus.
Could be implemented for IE only.
"""
try:
self.getSelection()
self.lastRange = Selection.getRange()
except:
GWT.log("Error capturing selection for IE", ex)
# Gets run every time the selection is changed
def onSelectionChange(self, sel):
pass
def isOnTextBorder(self, sender):
twX = self.richText.getAbsoluteLeft()
twY = self.richText.getAbsoluteTop()
x = event.getClientX() - twX
y = event.getClientY() - twY
width = self.richText.getOffsetWidth()
height = self.richText.getOffsetHeight()
return ((sender == self.richText) and
((x <= 0) or (x >= width) or
(y <= 0) or (y >= height)))
def startSelTimer(self):
self.selTimer.scheduleRepeating(250)
def endSelTimer(self):
self.selTimer.cancel()
def getRange(self):
if self.lastRange is None:
self.getSelection()
return Selection.getRange()
else:
return self.lastRange
def checkForChange(self):
text = self.richText.getHTML()
if text == self.lastText:
return
nEvt = doc().createEvent("HTMLEvents")
nEvt.initEvent("change", False, True)
self.getElement().dispatchEvent(nEvt)
self.lastText = text
def setHtml(self, text):
self.richText.setHTML(text)
self.lastText = text
def getHtml(self):
return self.richText.getHTML()
def getDocument(self):
return Selection.getDocument(self.getWindow())
def getFormatter(self):
return self.richText.getExtendedFormatter()
示例9: RichTextEditor
# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import scheduleRepeating [as 别名]
#.........这里部分代码省略.........
self.m_lastRange = None
self.startSelTimer()
"""*
* This captures the selection when the mouse leaves the RTE, because in IE
* the selection indicating the cursor position is lost once another widget
* gains focus. Could be implemented for IE only.
"""
def captureSelection(self):
try:
self.getSelection()
self.m_lastRange = Selection.getRange()
except:
GWT.log("Error capturing selection for IE", ex)
# Gets run every time the selection is changed
def onSelectionChange(self, sel):
pass
def isOnTextBorder(self, event):
sender = event.getSource()
twX = self.m_textW.getAbsoluteLeft()
twY = self.m_textW.getAbsoluteTop()
x = event.getClientX() - twX
y = event.getClientY() - twY
width = self.m_textW.getOffsetWidth()
height = self.m_textW.getOffsetHeight()
return ((sender == self.m_textW) and
((x <= 0) or (x >= width) or
(y <= 0) or (y >= height)))
def startSelTimer(self):
self.m_selTimer.scheduleRepeating(250)
def endSelTimer(self):
self.m_selTimer.cancel()
def getRange(self):
if self.m_lastRange is None:
self.getSelection()
return Selection.getRange()
else:
return self.m_lastRange
def getSelection(self):
res = None
try:
window = self.getWindow()
Selection.getSelection(window)
except:
print "Error getting the selection"
traceback.print_exc()
def getWindow(self, iFrame=None):
if iFrame is None:
iFrame = self.m_textW.getElement()
iFrameWin = iFrame.contentWindow or iFrame.contentDocument
if not iFrameWin.document:
iFrameWin = iFrameWin.parentNode # FBJS version of parentNode
#print "getWindow", iFrameWin, dir(iFrameWin)