本文整理汇总了Python中PySide.QtCore.QTimer.stop方法的典型用法代码示例。如果您正苦于以下问题:Python QTimer.stop方法的具体用法?Python QTimer.stop怎么用?Python QTimer.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtCore.QTimer
的用法示例。
在下文中一共展示了QTimer.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SessionService
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class SessionService(QObject):
session_started = Signal(SessionModel)
session_paused = Signal(SessionModel)
session_resumed = Signal(SessionModel)
session_stopped = Signal()
timer_updated = Signal(float)
def __init__(self):
super(SessionService, self).__init__()
self.session_dao = SessionDao()
self.time = 0
self.state = SessionState.STOPPED
self.timer = QTimer(self)
self.timer.timeout.connect(self._timer_timeout)
self.current_session = None
def start_session(self, project):
self.time = 0
self.current_session = SessionModel(start = time.time(), project_id = project.id)
self.current_session = self.session_dao.save(self.current_session)
self.timer.start(1000)
self.state = SessionState.ACTIVE
self.session_started.emit(self.current_session)
def pause_session(self):
self.timer.stop()
self.state = SessionState.PAUSED
self.session_paused.emit(self.current_session)
def resume_session(self):
self.timer.start(1000)
self.state = SessionState.ACTIVE
self.current_pause = None
self.session_resumed.emit(self.current_session)
def stop_session(self):
self.state = SessionState.STOPPED
self.timer.stop()
if self.current_session:
self.current_session.end = time.time()
self.current_session.duration = self.time
self.session_dao.save(self.current_session)
self.session_stopped.emit()
self.current_session = None
self.time = 0
def get_state(self):
return self.state
def get_table_model(self, project):
'Returns a table model with sessions for the specified project'
return SessionTableModel(self, project, self.session_dao)
def _timer_timeout(self):
self.time += 1
self.timer_updated.emit(self.time)
示例2: Panel
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class Panel(QWidget):
def __init__(self, parent=None, instr=None, lock=None, title="Instrument Panel"):
# This class derivates from a Qt Widget so we have to call
# the class builder ".__init__()"
QWidget.__init__(self)
# "self" is now a Qt Widget, then we load the user interface
# generated with QtDesigner and call it self.ui
self.ui = Keithley6221_Ui.Ui_Panel()
# Now we have to feed the GUI building method of this object (self.ui)
# with the current Qt Widget 'self', but the widgets from the design will actually be built as children
# of the object self.ui
self.ui.setupUi(self)
self.setWindowTitle(title)
self.reserved_access_to_instr = lock
self.instr = instr
self.monitor_timer = QTimer()
# The timer would not wait for the completion of the task otherwise
self.monitor_timer.setSingleShot(True)
self.monitor_timer.timeout.connect(self.monitor)
self.firsttime = 0
# bug: if the box is checked in the .ui file, the system freezes
# if self.ui.monitor.isChecked():self.monitor()
def monitor(self, state=1):
if state != 1:
self.monitor_timer.stop()
elif state and not (self.monitor_timer.isActive()):
with self.reserved_access_to_instr:
I = self.instr.query_current_source_amplitude()
Vcomp = self.instr.query_voltage_compliance()
outstate = self.instr.query_output_ON()
self.ui.I_disp.setText(str(I * 1e6) + u" μA")
self.ui.V_disp.setText(str(Vcomp) + " V")
self.ui.outputON.setChecked(outstate)
self.monitor_timer.start(self.ui.refresh_rate.value() * 1000)
def update_timer_timeout(self, secs):
# The value must be converted to milliseconds
self.monitor_timer.setInterval(secs * 1000)
def change_I(self, value=0):
with self.reserved_access_to_instr:
self.instr.set_current_source_amplitude(value * 1e6)
def change_V_comp(self, value=0):
with self.reserved_access_to_instr:
self.instr.set_voltage_compliance(value)
def switch_output(self, value=False):
if value:
with self.reserved_access_to_instr:
self.instr.output_ON()
else:
with self.reserved_access_to_instr:
self.instr.output_OFF()
def reset_inst(self):
with self.reserved_access_to_instr:
self.instr.reset()
示例3: PhotoListModel
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class PhotoListModel(QAbstractListModel):
URL_ROLE = Qt.UserRole + 1
IMAGE_URL_ROLE = Qt.UserRole + 2
HEIGHT_ROLE = Qt.UserRole + 3
WIDTH_ROLE = Qt.UserRole + 4
def __init__(self, album, parent=None):
super(PhotoListModel, self).__init__(parent)
self._album = album
self._photos = []
self._cache = []
self._done = False
keys = {}
keys[PhotoListModel.URL_ROLE] = "url"
keys[PhotoListModel.IMAGE_URL_ROLE] = "imageUrl"
keys[PhotoListModel.HEIGHT_ROLE] = "height"
keys[PhotoListModel.WIDTH_ROLE] = "width"
self.setRoleNames(keys)
self._load = PhotoLoad(self)
self._load.start()
self._timer = QTimer()
self._timer.setInterval(1000)
self._timer.timeout.connect(self.loadCache)
self._timer.start()
def rowCount(self, index):
return len(self._photos)
def appendCache(self, itens):
self._cache += itens
def loadCache(self):
self.beginInsertRows(QModelIndex(), len(self._photos), len(self._photos) + len(self._cache))
self._photos += self._cache
self.endInsertRows()
self._cache = []
if self._done:
self._timer.stop()
def data(self, index, role):
if not index.isValid():
return None
if index.row() > len(self._photos):
return None
img = self._photos[index.row()]
if role == PhotoListModel.URL_ROLE:
return img.url
elif role == PhotoListModel.IMAGE_URL_ROLE:
return img.imageUrl
elif role == PhotoListModel.HEIGHT_ROLE:
return img.height
elif role == PhotoListModel.WIDTH_ROLE:
return img.width
else:
return None
示例4: LogFilePositionSource
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class LogFilePositionSource(QGeoPositionInfoSource):
def __init__(self, parent):
QGeoPositionInfoSource.__init__(self, parent)
self.logFile = QFile(self)
self.timer = QTimer(self)
self.timer.timeout.connect(self.readNextPosition)
self.logFile.setFileName(translate_filename('simplelog.txt'))
assert self.logFile.open(QIODevice.ReadOnly)
self.lastPosition = QGeoPositionInfo()
def lastKnownPosition(self, fromSatellitePositioningMethodsOnly):
return self.lastPosition
def minimumUpdateInterval(self):
return 100
def startUpdates(self):
interval = self.updateInterval()
if interval < self.minimumUpdateInterval():
interval = self.minimumUpdateInterval()
self.timer.start(interval)
def stopUpdates(self):
self.timer.stop()
def requestUpdate(self, timeout):
# For simplicity, ignore timeout - assume that if data is not available
# now, no data will be added to the file later
if (self.logFile.canReadLine()):
self.readNextPosition()
else:
self.updateTimeout.emit()
def readNextPosition(self):
line = self.logFile.readLine().trimmed()
if not line.isEmpty():
data = line.split(' ')
hasLatitude = True
hasLongitude = True
timestamp = QDateTime.fromString(str(data[0]), Qt.ISODate)
latitude = float(data[1])
longitude = float(data[2])
if timestamp.isValid():
coordinate = QGeoCoordinate(latitude, longitude)
info = QGeoPositionInfo(coordinate, timestamp)
if info.isValid():
self.lastPosition = info
# Currently segfaulting. See Bug 657
# http://bugs.openbossa.org/show_bug.cgi?id=657
self.positionUpdated.emit(info)
示例5: FunnySpiral
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class FunnySpiral(QGLWidget):
"""
Renders a spiral on a Qt widget.
"""
def __init__(self, parent=None):
QGLWidget.__init__(self, parent)
self.timer = QTimer(self)
# the timer, which drives the animation
self.timer.timeout.connect(self.update)
# the angle, by which the spiral is rotated
self.angle = 0
self.spiral = self.update_spiral()
def start_rotation(self):
self.timer.start(100)
def stop_rotation(self):
self.timer.stop()
def update_spiral(self):
# create a polygon providing the corner points of the spiral
polygon = QPolygon()
for i in xrange(self.window().width()):
x = int(math.cos(i * 0.16) * i)
y = int(math.sin(i * 0.16) * i)
polygon.append(QPoint(x, y))
return polygon
def resizeEvent(self, evt):
# re-create the spiral, if the widget is resized
self.spiral = self.update_spiral()
def paintEvent(self, evt):
# create a painter
with paint(self) as painter:
# adjust the width of the pen
pen = QPen()
pen.setWidth(5)
painter.setPen(pen)
# enable high quality antialiasing
painter.setRenderHint(QPainter.Antialiasing)
painter.setRenderHint(QPainter.HighQualityAntialiasing)
# move the center of the coordinate system to the widgets center
painter.translate(self.width() / 2, self.height() / 2)
# rotate the coordinate system by the given angle
painter.rotate(self.angle)
# draw the spiral
painter.drawPolyline(self.spiral)
# end painting and free resources
# update the angle
self.angle += 30
self.angle %= 360
示例6: SyncThread
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class SyncThread(QThread):
"""Sync notes with evernote thread"""
force_sync_signal = Signal()
sync_state_changed = Signal(int)
def __init__(self, app, *args, **kwargs):
QThread.__init__(self, *args, **kwargs)
self.app = app
self.status = STATUS_NONE
self.last_sync = datetime.now()
self.timer = QTimer()
self.timer.timeout.connect(self.sync)
self.update_timer()
self.wait_condition = QWaitCondition()
self.mutex = QMutex()
def update_timer(self):
self.timer.stop()
delay = int(self.app.settings.value('sync_delay') or 0) or DEFAULT_SYNC_DELAY
if delay != SYNC_MANUAL:
self.timer.start(delay)
def run(self):
self.session = get_db_session()
self.sq = self.session.query
self.auth_token = get_auth_token()
self.note_store = get_note_store(self.auth_token)
self.perform()
while True:
self.mutex.lock()
self.wait_condition.wait(self.mutex)
self.perform()
self.mutex.unlock()
def force_sync(self):
self.timer.stop()
self.sync()
self.update_timer()
@Slot()
def sync(self):
self.wait_condition.wakeAll()
def perform(self):
"""Perform all sync"""
self.status = STATUS_SYNC
self.last_sync = datetime.now()
self.sync_state_changed.emit(SYNC_STATE_START)
try:
self.local_changes()
self.remote_changes()
except Exception, e: # maybe log this
self.session.rollback()
finally:
示例7: Network
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class Network(QObject):
messageReceived = Signal(str)
serverClosed = Signal()
def __init__(self, parent):
super(Network, self).__init__(parent)
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._isConnected = False
self.log = logger.Logger('client')
self.threadRecv = None
self.timerConnect = QTimer(self)
self.timerConnect.timeout.connect(self.connect_)
parent.updated.connect(self.slotUpdated)
def state(self):
return self._state
def connect_(self):
try:
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect((socket.gethostname(), cst.PORT))
self._isConnected = True
self.timerConnect.stop()
self.threadRecv = ThreadRecv(self.socket, self.log)
self.threadRecv.receivedMessage.connect(self.slotMessage)
self.threadRecv.start()
self.log.info('client connected')
self.send('send-state')
except:
self._isConnected = False
self.timerConnect.start(100)
def slotMessage(self, msg):
self.log.recv(msg)
if msg == 'socket-closed':
self._isConnected = False
self.timerConnect.start(100)
self.serverClosed.emit()
else:
self.messageReceived.emit(msg)
def send(self, msg):
if self._isConnected:
try:
self.socket.send(msg)
self.log.send(msg)
except socket.error, msg:
self.log.warning('sending failed: %s', msg)
示例8: Animation
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class Animation():
_SetterGetter = 0; _SetAttr = 1;
def __init__(self,obj,property_name_or_setter,getter=None):
# decide how the property will be set
if getter != None:
self._setmethod = Animation._SetterGetter
self._setter = property_name_or_setter; self._getter = getter
else:
self._propname = property_name_or_setter
self._setmethod = Animation._SetAttr
self._anim_obj = obj
# initialize some variables
self.startvalue = True
self.endvalue = True
self.duration = 1000
self.interval = 5
self.interpolator = True # the interpolator gives values for the animation
self._previousvalue = QColor(0,0,0) # this is given to the interpolator in Animation.update()
self.isvisual = True # this is used to tell whether to call QWidget.update() on self._anim_obj
self._timer = QTimer() # this is used for timing the animation...duh
self._timer.timeout.connect(self._update)
def setBySetter(self,value): self._setter(value)
def setBySetAttr(self,value): setattr(self._anim_obj,self._propname,value)
def start(self):
if type(self.startvalue) == QColor: # if we're working with colors, use a ColorInterpolator
self.interpolator = ColorInterpolator(self.startvalue, self.endvalue, self.duration, self.interval, self.stop)
else:
raise NotImplementedError("There is no interpolator for ", str(type(self.start())))
self._previousvalue = self.startvalue
self._timer.start(self.interval)
def _update(self):
self._previousvalue = self.interpolator.getnextvalue(self._previousvalue)
if self.isvisual: self._anim_obj.update()
def stop(self):
print "Stopped\n"
self._timer.timeout.connect(self._blankmethod)
self._timer.stop()
def _blankmethod(self): print "blankmethod"
示例9: InputHandler
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class InputHandler(observable.Object):
def __init__(self, port, target):
observable.Object.__init__(self)
# store the source port and the target to send data to
self._port = port
self._target = target
# add an idle timer to check for input
self._timer = QTimer()
self._timer.setInterval(0)
self._timer.timeout.connect(self.receive)
self._timer.start()
def destroy(self):
self._timer.timeout.disconnect(self.receive)
self._timer.stop()
@property
def port(self):
return(self._port)
@property
def target(self):
return(self._target)
# check for input
def receive(self, limit_time=True):
# limit processing time to maintain responsiveness
time_limit = time.time() + 0.100
# wrap the target in a change block so each midi event doesn't waste a lot
# of time causing cascading changes
target_and_refs = (self._target,)
try:
target_and_refs += self._target.model_refs
except AttributeError: pass
for model in target_and_refs:
try:
model.begin_change_block()
except AttributeError: pass
while (True):
result = self._port.receive()
if (result is None): break
(data, msg_time) = result
self.handle_message(data, msg_time)
# handle at least one message per run, but limit overall processing time
# to keep the UI responsive, allowing the jackpatch buffer to handle
# the backlog
if ((limit_time) and (time.time() > time_limit)): break
for model in target_and_refs:
try:
model.end_change_block()
except AttributeError: pass
# handle input, reimplement to pass data to the target
def handle_message(data, time):
pass
示例10: HeartBeatTimer
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class HeartBeatTimer(QObject):
""" Class for HeartBeat event timer
"""
__status_changed = Signal(str)
def __init__(self, period, callback):
""" Constructor for HeartBeatTimer class
:param int period: timeout period in msec
:param callback: callback function to be called when timer changes its status
callback signature: callback(status)
"""
super(HeartBeatTimer, self).__init__()
self.__period = period
self.is_alive = False
self.__timer = QTimer(self)
self.__timer.timeout.connect(self.__heartbeat_timer_expired)
self.__timer.start(self.__period)
self.__status_changed.connect(callback)
self.__status_changed.emit("OFFLINE")
def refresh_timer(self):
""" Restart the heartbeat timer
"""
self.__timer.start(self.__period)
if not self.is_alive:
self.is_alive = True
self.__status_changed.emit("ONLINE")
def change_timeout_period(self, period):
""" Change the existing timeout period if not same
:param int period: new timeout period in msec
"""
if period != self.__period:
self.__period = period
self.__timer.start(self.__period)
@Slot()
def __heartbeat_timer_expired(self):
""" Slot function for heartbeat timeout event
"""
self.__timer.stop()
if self.is_alive:
self.is_alive = False
self.__status_changed.emit("OFFLINE")
示例11: Browser
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class Browser(QWidget):
def __init__(self):
super(Browser, self).__init__()
self.layout = QStackedLayout(self)
self.layout.setStackingMode(QStackedLayout.StackAll)
self.hostname = os.uname()[1]
self.timer = QTimer()
self.timer.setSingleShot(False)
self.timer.start(2000)
self._init_sites()
self.remote_shell = RemoteShell(self)
self.connect(self.timer, SIGNAL("timeout()"), self, SLOT("show_next()"))
self.show_next()
def _init_sites(self):
self.sites = list()
self.site_id = -1
url = QUrl("https://www.qt.io/developers/")
self.sites.append(Site(self, url, 5, 1))
url = QUrl("https://wiki.qt.io/PySide")
self.sites.append(Site(self, url, 5, 1))
url = QUrl("https://www.python.org/")
self.sites.append(Site(self, url, 5, 1))
@property
def current_site(self):
return self.sites[self.site_id]
def show_next(self):
self.timer.stop()
previous_id = self.site_id
self.site_id = (self.site_id + 1) % len(self.sites)
current_site = self.current_site
self.timer.start(current_site.time * 1000)
current_site.show()
print("show " + current_site.url.toString().encode())
if previous_id >= 0:
self.sites[previous_id].hide()
示例12: _VideoComponentEditor
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class _VideoComponentEditor(_LaserComponentEditor):
"""
"""
playTimer = Any
fps = Int
stop_timer = Event
def init(self, parent):
"""
Finishes initializing the editor by creating the underlying toolkit
widget.
"""
super(_VideoComponentEditor, self).init(parent)
self.playTimer = QTimer(self.control)
# self.playTimer.timeout.connect(self.update)
self.control.connect(self.playTimer, SIGNAL('timeout()'), self.update)
if self.value.fps:
self.playTimer.setInterval(1000 / float(self.value.fps))
self.playTimer.start()
self.value.on_trait_change(self.stop, 'closed_event')
self.value.on_trait_change(self._update_fps, 'fps')
self.sync_value('stop_timer', 'stop_timer', mode='from')
def _update_fps(self):
if self.value.fps:
self.playTimer.setInterval(1000 / float(self.value.fps))
def stop(self):
print 'VideoComponentEditor stop'
try:
self.playTimer.stop()
except RuntimeError:
pass
def update(self):
if self.control:
# invoke_in_main_thread(self.value.request_redraw)
self.value.request_redraw()
def _stop_timer_fired(self):
print 'VideoComponentEditor stopping playTimer'
self.playTimer.stop()
示例13: open
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
def open(self, url, timeout=60):
"""Wait for download to complete and return result"""
loop = QEventLoop()
timer = QTimer()
timer.setSingleShot(True)
timer.timeout.connect(loop.quit)
self.loadFinished.connect(loop.quit)
self.load(QUrl(url))
timer.start(timeout * 1000)
loop.exec_() # delay here until download finished
if timer.isActive():
# downloaded successfully
timer.stop()
return self.html()
else:
# timed out
print 'Request timed out:', url
示例14: _VideoComponentEditor
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class _VideoComponentEditor(_LaserComponentEditor):
"""
"""
playTimer = Any
fps = Int
stop_timer = Event
def init(self, parent):
"""
Finishes initializing the editor by creating the underlying toolkit
widget.
"""
super(_VideoComponentEditor, self).init(parent)
self.playTimer = QTimer(self.control)
self.playTimer.timeout.connect(self.update)
if self.value.fps:
self.playTimer.setInterval(1000 / self.value.fps)
self.playTimer.start()
self.value.on_trait_change(self.stop, "closed_event")
self.value.on_trait_change(self._update_fps, "fps")
self.sync_value("stop_timer", "stop_timer", mode="both")
def _update_fps(self):
if self.value.fps:
self.playTimer.setInterval(1000 / self.value.fps)
def stop(self):
try:
self.playTimer.stop()
except RuntimeError:
del self.playTimer
def update(self):
if self.control:
self.value.draw_valid = False
self.control.repaint()
def _stop_timer_fired(self):
print "VideoComponentEditor stopping playTimer"
self.playTimer.stop()
示例15: AntReverseCalculation
# 需要导入模块: from PySide.QtCore import QTimer [as 别名]
# 或者: from PySide.QtCore.QTimer import stop [as 别名]
class AntReverseCalculation():
"""
Callable function calls every second and at once, and it must has "seconds_before_start" as argument.
"""
def __init__(self):
self._seconds_before_start = 0
self._timer = QTimer()
QObject.connect(self._timer, SIGNAL('timeout()'), self._action)
def _action(self):
self._seconds_before_start -= 1
if self._seconds_before_start == 0:
self._timer.stop()
self._callable(seconds_before_start=self._seconds_before_start)
def startReverseCalculation(self, number_of_seconds, callable_function):
self._callable = callable_function
self._seconds_before_start = copy(number_of_seconds) + 1
self._timer.start(1000)
self._action()