当前位置: 首页>>代码示例>>Python>>正文


Python Timer.cancel方法代码示例

本文整理汇总了Python中pyjamas.Timer.Timer.cancel方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.cancel方法的具体用法?Python Timer.cancel怎么用?Python Timer.cancel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyjamas.Timer.Timer的用法示例。


在下文中一共展示了Timer.cancel方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import cancel [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()
开发者ID:Afey,项目名称:pyjs,代码行数:31,代码来源:Feed.py

示例2: Timer

# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import cancel [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(' '))
开发者ID:anandology,项目名称:pyjamas,代码行数:50,代码来源:timerdemo.py

示例3: Tooltip

# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import cancel [as 别名]
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,代码行数:48,代码来源:Tooltip.py

示例4: itself

# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import cancel [as 别名]
class RandomColor:

    __doc__ = '''This last example demonstrates what most pyjamas
    programmers currently do with timers: create a Timer instance
    specifying <code>notify</code> with an object that has an
    <code>onTimer</code> attribute that is callable.  The slider on
    the left will adjust how often the middle panel changes color; it
    is either OFF or a value of seconds from 1 to 5.  Changing the
    slider immediately cancels the current timer and starts a new
    timer to change the color in the newly specified time.  Like the
    previous example, this timer reschedules itself (if it wasn't
    turned off) at the end of the call to <code>onTimer()</code>.
    '''

    def __init__(self):

        # create the label and slider
        self.__label = Label('OFF')
        self.slider = slider = HorizontalSlider(0, 5, step=1,
                                                StyleName="slider")
        slider.setDragable(True)
        slider.addControlValueListener(self)

        # put them in a hpanel
        self.hpanel = hpanel = HorizontalPanel(Spacing=10)
        hpanel.add(slider)
        hpanel.add(self.__label)

        # create the color panel and give it color
        self.colorpanel = CaptionPanel('Color:',
                                       SimplePanel(StyleName='colorpanel'))
        self.randomcolor()

        # we're initially off
        self.value = 0
        # create our timer
        self.timer = Timer(notify=self)

    def initialize(self):

        # this method solves an apparent bug with the slider: the
        # slider doesn't draw its handle if the position is set before
        # showing, so instead of doing this in __init__ (where I
        # originally had it), this method gets called after it is
        # shown on the root panel.  See below when it gets called.
        self.slider.setValue(self.value)
        self.slider.setControlPos(self.value)

    def onTimer(self, timer):

        # when the timer fires we randomize the color and (maybe)
        # reschedule ourselves.
        self.randomcolor()
        v = self.value * 1000
        if v:
            self.timer.schedule(v)

    def onControlValueChanged(self, sender, old, new):

        # event handler for when the slider is moved.
        if new == self.value:
            return
        self.value = new

        # is it being turned off?
        if new == 0:
            self.__label.setText('OFF')
            self.timer.cancel()
        else:
            # no it's being reset
            self.__label.setText(str(new) + ' sec')
            self.onTimer(self.timer)
            
    def randomcolor(self):

        # randomize the color and set the panel accordingly
        r = random()*256
        g = random()*256
        b = random()*256
        e = self.colorpanel.getWidget().getElement()
        color = '#%02x%02x%02x' % (r, g, b)
        self.colorpanel.setCaption('Color: %s' % color)
        DOM.setStyleAttribute(e, "background", color)
开发者ID:anandology,项目名称:pyjamas,代码行数:85,代码来源:timerdemo.py

示例5: Tooltip

# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import cancel [as 别名]
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 onShowImpl(self, popup):
        width = self.getOffsetWidth()
        heigth = self.getOffsetHeight()
        w_width = Window.getClientWidth()
        w_heigth = Window.getClientHeight()
        if w_width > width and w_heigth > heigth:
            offset_x = self.getAbsoluteLeft()
            offset_y = self.getAbsoluteTop()
            element = self.getElement()
            if (offset_x + width) > w_width:
                offset_x = w_width - width
                DOM.setStyleAttribute(element, "left", "%dpx" % offset_x)
            if (offset_y + heigth) > w_heigth:
                offset_y = w_heigth - heigth
                DOM.setStyleAttribute(element, "top", "%dpx" % offset_y)

    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:Afey,项目名称:pyjs,代码行数:64,代码来源:Tooltip.py

示例6: RichTextToolbar

# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import cancel [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()
开发者ID:Afey,项目名称:pyjs,代码行数:104,代码来源:RichTextToolbar.py

示例7: RichTextEditor

# 需要导入模块: from pyjamas.Timer import Timer [as 别名]
# 或者: from pyjamas.Timer.Timer import cancel [as 别名]

#.........这里部分代码省略.........
    """*
    * 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)

        return iFrameWin

开发者ID:Afey,项目名称:pyjs,代码行数:68,代码来源:RichTextEditor.py


注:本文中的pyjamas.Timer.Timer.cancel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。