本文整理汇总了Python中timer.Timer.unpause方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.unpause方法的具体用法?Python Timer.unpause怎么用?Python Timer.unpause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer.Timer
的用法示例。
在下文中一共展示了Timer.unpause方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EventRecorder
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import unpause [as 别名]
#.........这里部分代码省略.........
self._current_observed_mouse_presses.remove( event.button() )
except KeyError:
synthetic_press_event = QMouseEvent( QEvent.MouseButtonPress, event.pos(), event.globalPos(), event.button(), event.buttons(), event.modifiers() )
synthetic_eventstr = event_to_string(synthetic_press_event)
self._captured_events.append( (synthetic_eventstr, objname, timestamp_in_seconds) )
self._captured_events.append( (eventstr, objname, timestamp_in_seconds) )
return
def insertComment(self, comment):
self._captured_events.append( (comment, "comment", None) )
def _shouldSaveEvent(self, event):
if isinstance(event, QMouseEvent):
# Ignore most mouse movement events if the user isn't pressing anything.
if event.type() == QEvent.MouseMove \
and int(event.button()) == 0 \
and int(event.buttons()) == 0 \
and int(event.modifiers()) == 0:
# If mouse tracking is enabled for this widget,
# then we'll assume mouse movements are important to it.
widgetUnderCursor = QApplication.instance().widgetAt( QCursor.pos() )
if widgetUnderCursor is not None and widgetUnderCursor.hasMouseTracking():
return True
# Somewhat hackish (and slow), but we have to record mouse movements during combo box usage.
# Same for QMenu usage (on Mac, it doesn't seem to matter, but on Fedora it does matter.)
if widgetUnderCursor is not None and widgetUnderCursor.objectName() == "qt_scrollarea_viewport":
return has_ancestor(widgetUnderCursor, QComboBox)
if isinstance(widgetUnderCursor, QMenu):
return True
return False
else:
return True
# Ignore non-spontaneous events
if not event.spontaneous():
return False
if event.type() in self.IgnoredEventTypes:
return False
if isinstance(event, self.IgnoredEventClasses):
return False
return True
def unpause(self):
# Here, we use a special override of QApplication.notify() instead of using QApplication.instance().installEventFilter().
# That's because (contrary to the documentation), the QApplication eventFilter does NOT get to see every event in the application.
# Testing shows that events that were "filtered out" by a different event filter may not be seen by the QApplication event filter.
self._timer.unpause()
def pause(self):
self._timer.pause()
def writeScript(self, fileobj, author_name):
# Write header comments
fileobj.write(
"""
# Event Recording
# Created by {}
# Started at: {}
""".format( author_name, str(self._timer.start_time) ) )
# Write playback function definition
fileobj.write(
"""
def playback_events(player):
import PyQt4.QtCore
from PyQt4.QtCore import Qt, QEvent, QPoint
import PyQt4.QtGui
# The getMainWindow() function is provided by EventRecorderApp
mainwin = PyQt4.QtGui.QApplication.instance().getMainWindow()
player.display_comment("SCRIPT STARTING")
""")
# Write all events and comments
for eventstr, objname, timestamp_in_seconds in self._captured_events:
if objname == "comment":
eventstr = eventstr.replace('\\', '\\\\')
eventstr = eventstr.replace('"', '\\"')
eventstr = eventstr.replace("'", "\\'")
fileobj.write(
"""
########################
player.display_comment(\"""{eventstr}\""")
########################
""".format( **locals() ) )
else:
fileobj.write(
"""
event = {eventstr}
player.post_event( '{objname}', event , {timestamp_in_seconds} )
""".format( **locals() )
)
fileobj.write(
"""
player.display_comment("SCRIPT COMPLETE")
""")
示例2: EventPlayer
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import unpause [as 别名]
class EventPlayer(object):
def __init__(self, playback_speed=None, comment_display=None):
self._playback_speed = playback_speed
self._timer = Timer()
self._timer.unpause()
if comment_display is None:
self._comment_display = self._default_comment_display
else:
self._comment_display = comment_display
def getNamedObject(self, widget_name):
return get_named_object(widget_name)
def play_script(self, path, finish_callback=None):
"""
Start execution of the given script in a separate thread and return immediately.
Note: You should handle any exceptions from the playback script via sys.execpthook.
"""
_globals = {}
_locals = {}
# Before we start, move the mouse cursor to (0,0) to avoid interference with the recorded events.
QCursor.setPos(0, 0)
"""
Calls to events in the playback script like: player.post_event(obj,PyQt4.QtGui.QMouseEvent(...),t)
are/were responsible for the xcb-error on Ubuntu, because you may not use
a Gui-object from a thread other than the MainThread running the Gui
"""
execfile(path, _globals, _locals)
def run():
_locals['playback_events'](player=self)
if finish_callback is not None:
finish_callback()
th = threading.Thread( target=run )
th.daemon = True
th.start()
def post_event(self, obj_name, event, timestamp_in_seconds):
# Remove any lingering widgets (which might have conflicting names with our receiver)
gc.collect()
try:
# Locate the receiver object.
obj = get_named_object(obj_name)
except NamedObjectNotFoundError:
# If the object couldn't be found, check to see if this smells
# like a silly mouse-move event that was sent after a window closed.
if event.type() == QEvent.MouseMove \
and int(event.button()) == 0 \
and int(event.buttons()) == 0 \
and int(event.modifiers()) == 0:
# Just proceed. We shouldn't raise an exception just because we failed to
# deliver a pointless mouse-movement to a widget that doesn't exist anymore.
return
elif event.type() == QEvent.KeyRelease:
# Sometimes we try to send a KeyRelease to a just-closed dialog.
# Ignore errors from such cases.
return
elif event.type() == QEvent.Wheel:
# Also don't freak out if we can't find an object that is supposed to be receiving wheel events.
# If there's a real problem, it will be noticed that object is sent a mousepress or key event.
return
else:
# This isn't a plain mouse-move.
# It was probably important, and something went wrong.
raise
if self._playback_speed is not None:
self._timer.sleep_until(timestamp_in_seconds / self._playback_speed)
assert threading.current_thread().name != "MainThread"
event.spont = True
QApplication.postEvent(obj, event)
assert QApplication.instance().thread() == obj.thread()
flusher = EventFlusher()
flusher.moveToThread( obj.thread() )
flusher.setParent( QApplication.instance() )
# Note: We are allowed to use QTimer outside of the main thread like this
# because the target function belongs to a QObject
QTimer.singleShot( 0, flusher.set )
flusher.wait()
flusher.clear()
def display_comment(self, comment):
self._comment_display(comment)
def _default_comment_display(self, comment):
print "--------------------------------------------------"
print comment
print "--------------------------------------------------"