本文整理汇总了Python中qtpy.QtCore.QTimer.start方法的典型用法代码示例。如果您正苦于以下问题:Python QTimer.start方法的具体用法?Python QTimer.start怎么用?Python QTimer.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtCore.QTimer
的用法示例。
在下文中一共展示了QTimer.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: qapplication
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
def qapplication(translate=True, test_time=3):
"""
Return QApplication instance
Creates it if it doesn't already exist
test_time: Time to maintain open the application when testing. It's given
in seconds
"""
if running_in_mac_app():
SpyderApplication = MacApplication
else:
SpyderApplication = QApplication
app = SpyderApplication.instance()
if app is None:
# Set Application name for Gnome 3
# https://groups.google.com/forum/#!topic/pyside/24qxvwfrRDs
app = SpyderApplication(['Spyder'])
# Set application name for KDE (See issue 2207)
app.setApplicationName('Spyder')
if translate:
install_translator(app)
test_travis = os.environ.get('TEST_CI_WIDGETS', None)
if test_travis is not None:
timer_shutdown = QTimer(app)
timer_shutdown.timeout.connect(app.quit)
timer_shutdown.start(test_time*1000)
return app
示例2: MatplotlibDataViewer
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
class MatplotlibDataViewer(MatplotlibViewerMixin, DataViewer):
_state_cls = MatplotlibDataViewerState
tools = ['mpl:home', 'mpl:pan', 'mpl:zoom']
subtools = {'save': ['mpl:save']}
def __init__(self, session, parent=None, wcs=None, state=None):
super(MatplotlibDataViewer, self).__init__(session, parent=parent, state=state)
# Use MplWidget to set up a Matplotlib canvas inside the Qt window
self.mpl_widget = MplWidget()
self.setCentralWidget(self.mpl_widget)
# TODO: shouldn't have to do this
self.central_widget = self.mpl_widget
self.figure, self.axes = init_mpl(self.mpl_widget.canvas.fig, wcs=wcs)
MatplotlibViewerMixin.setup_callbacks(self)
self.central_widget.resize(600, 400)
self.resize(self.central_widget.size())
self._monitor_computation = QTimer()
self._monitor_computation.setInterval(500)
self._monitor_computation.timeout.connect(self._update_computation)
def _update_computation(self, message=None):
# If we get a ComputationStartedMessage and the timer isn't currently
# active, then we start the timer but we then return straight away.
# This is to avoid showing the 'Computing' message straight away in the
# case of reasonably fast operations.
if isinstance(message, ComputationStartedMessage):
if not self._monitor_computation.isActive():
self._monitor_computation.start()
return
for layer_artist in self.layers:
if layer_artist.is_computing:
self.loading_rectangle.set_visible(True)
text = self.loading_text.get_text()
if text.count('.') > 2:
text = 'Computing'
else:
text += '.'
self.loading_text.set_text(text)
self.loading_text.set_visible(True)
self.redraw()
return
self.loading_rectangle.set_visible(False)
self.loading_text.set_visible(False)
self.redraw()
# If we get here, the computation has stopped so we can stop the timer
self._monitor_computation.stop()
示例3: start_video
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
def start_video(self):
timer = QTimer()
self.timer = timer
timer.timeout.connect(self._wait_for_frame)
self.cam.start_live_video(**self.settings)
timer.start(0) # Run full throttle
self.is_live = True
self.needs_resize = True
self.videoStarted.emit()
示例4: BaseTimerStatus
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
class BaseTimerStatus(StatusBarWidget):
"""Status bar widget base for widgets that update based on timers."""
def __init__(self, parent, statusbar):
"""Status bar widget base for widgets that update based on timers."""
self.timer = None # Needs to come before parent call
super(BaseTimerStatus, self).__init__(parent, statusbar)
self._interval = 2000
# Widget setup
fm = self.label_value.fontMetrics()
self.label_value.setMinimumWidth(fm.width('000%'))
# Setup
if self.is_supported():
self.timer = QTimer()
self.timer.timeout.connect(self.update_status)
self.timer.start(self._interval)
else:
self.hide()
def setVisible(self, value):
"""Override Qt method to stops timers if widget is not visible."""
if self.timer is not None:
if value:
self.timer.start(self._interval)
else:
self.timer.stop()
super(BaseTimerStatus, self).setVisible(value)
def set_interval(self, interval):
"""Set timer interval (ms)."""
self._interval = interval
if self.timer is not None:
self.timer.setInterval(interval)
def import_test(self):
"""Raise ImportError if feature is not supported."""
raise NotImplementedError
def is_supported(self):
"""Return True if feature is supported."""
try:
self.import_test()
return True
except ImportError:
return False
def get_value(self):
"""Return formatted text value."""
raise NotImplementedError
def update_status(self):
"""Update status label widget, if widget is visible."""
if self.isVisible():
self.label_value.setText(self.get_value())
示例5: embed
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
def embed(aQObject):
tag = "__eventletEmbededTimer__"
timer = QTimer()
timer.setSingleShot(True)
timer.setInterval(0.1)
timer.timeout.connect(functools.partial(_timerOnTimeout, timer))
timer.start()
aQObject.setProperty(tag, timer)
示例6: DelayJobRunner
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
class DelayJobRunner(object):
"""
Utility class for running job after a certain delay.
If a new request is made during this delay, the previous request is dropped
and the timer is restarted for the new request.
We use this to implement a cooldown effect that prevents jobs from being
executed while the IDE is not idle.
A job is a simple callable.
"""
def __init__(self, delay=500):
"""
:param delay: Delay to wait before running the job. This delay applies
to all requests and cannot be changed afterwards.
"""
self._timer = QTimer()
self.delay = delay
self._timer.timeout.connect(self._exec_requested_job)
self._args = []
self._kwargs = {}
self._job = lambda x: None
def request_job(self, job, *args, **kwargs):
"""
Request a job execution.
The job will be executed after the delay specified in the
DelayJobRunner contructor elapsed if no other job is requested until
then.
:param job: job.
:type job: callable
:param args: job's position arguments
:param kwargs: job's keyworded arguments
"""
self.cancel_requests()
self._job = job
self._args = args
self._kwargs = kwargs
self._timer.start(self.delay)
def cancel_requests(self):
"""Cancels pending requests."""
self._timer.stop()
self._job = None
self._args = None
self._kwargs = None
def _exec_requested_job(self):
"""Execute the requested job after the timer has timeout."""
self._timer.stop()
self._job(*self._args, **self._kwargs)
示例7: open_in_window
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
def open_in_window(widget_name, script):
"""
Displays a widget in a window.
:param widget_name: A qualified name of a widget, ie mantidqt.mywidget.MyWidget
:param script: A qualified name of a test function that can be run after the
widget is created. The test function must have the signature:
def test(widget):
...
where argument widget is an instance of the tested widget.
The test function can yield from time to time after which the widget can update itself.
This will make the test non-blocking and changes can be viewed as the script runs.
If the test yields an integer it is interpreted as the number of seconds to wait
until the next step.
"""
raw_input('Please attach the Debugger now if required. Press any key to continue')
setup_library_paths()
app = QApplication([""])
w = create_widget(widget_name)
w.setWindowTitle(widget_name)
w.show()
if script is not None:
try:
# If script is a generator script_iter allows non-blocking
# test execution
script_iter = iter(run_script(script, w))
pause_timer = QTimer()
pause_timer.setSingleShot(True)
def idle():
if not pause_timer.isActive():
try:
# Run test script until the next 'yield'
pause_sec = script_iter.next()
if pause_sec is not None:
# Start non-blocking pause in seconds
pause_timer.start(int(pause_sec * 1000))
except StopIteration:
pass
except:
traceback.print_exc()
timer = QTimer()
# Zero-timeout timer runs idle() between Qt events
timer.timeout.connect(idle)
timer.start()
except:
pass
sys.exit(app.exec_())
示例8: setup
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
def setup(self, icon_painter, painter, rect):
if self.parent_widget not in self.info:
timer = QTimer()
timer.timeout.connect(lambda: self._update(self.parent_widget))
self.info[self.parent_widget] = [timer, 0, self.step]
timer.start(self.interval)
else:
timer, angle, self.step = self.info[self.parent_widget]
x_center = rect.width() * 0.5
y_center = rect.height() * 0.5
painter.translate(x_center, y_center)
painter.rotate(angle)
painter.translate(-x_center, -y_center)
示例9: ConnectionInspector
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
class ConnectionInspector(QWidget):
def __init__(self, parent=None):
super(ConnectionInspector, self).__init__(parent, Qt.Window)
connections = self.fetch_data()
self.table_view = ConnectionTableView(connections, self)
self.setLayout(QVBoxLayout(self))
self.layout().addWidget(self.table_view)
button_layout = QHBoxLayout()
self.layout().addItem(button_layout)
self.save_status_label = QLabel(self)
button_layout.addWidget(self.save_status_label)
button_layout.addStretch()
self.save_button = QPushButton(self)
self.save_button.setText("Save list to file...")
self.save_button.clicked.connect(self.save_list_to_file)
button_layout.addWidget(self.save_button)
self.update_timer = QTimer(parent=self)
self.update_timer.setInterval(1500)
self.update_timer.timeout.connect(self.update_data)
self.update_timer.start()
def update_data(self):
self.table_view.model().connections = self.fetch_data()
def fetch_data(self):
plugins = data_plugins.plugin_modules
return [connection
for p in plugins.values()
for connection in p.connections.values()
]
@Slot()
def save_list_to_file(self):
filename, filters = QFileDialog.getSaveFileName(self,
"Save connection list",
"",
"Text Files (*.txt)")
try:
with open(filename, "w") as f:
for conn in self.table_view.model().connections:
f.write(
"{p}://{a}\n".format(p=conn.protocol, a=conn.address))
self.save_status_label.setText("File saved to {}".format(filename))
except Exception as e:
msgBox = QMessageBox()
msgBox.setText("Couldn't save connection list to file.")
msgBox.setInformativeText("Error: {}".format(str(e)))
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec_()
示例10: setup
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
def setup():
qapp = QApplication(sys.argv)
# qapp.setGraphicsSystem('native')
qapp.setWindowIcon(QIcon(os.path.join(ICON_PATH, 'application',
'icon.png')))
#http://stackoverflow.com/questions/4938723/what-is-the-correct-way-to-make-my-pyqt-application-quit-when-killed-from-the-co
timer = QTimer()
timer.start(500) # You may change this if you wish.
timer.timeout.connect(lambda: None) # Let the interpreter run each 500 ms.
app = App(sys.argv)
app.viewer.main_window.show()
return qapp, app
示例11: qapplication
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
def qapplication(translate=True, test_time=3):
"""Return QApplication instance
Creates it if it doesn't already exist"""
app = QApplication.instance()
if app is None:
app = QApplication(['Conda-Manager'])
app.setApplicationName('Conda-Manager')
if translate:
install_translator(app)
test_travis = os.environ.get('TEST_CI', None)
if test_travis is not None:
timer_shutdown = QTimer(app)
timer_shutdown.timeout.connect(app.quit)
timer_shutdown.start(test_time*1000)
return app
示例12: BaseTimerStatus
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
class BaseTimerStatus(StatusBarWidget):
TITLE = None
TIP = None
def __init__(self, parent, statusbar):
StatusBarWidget.__init__(self, parent, statusbar)
self.setToolTip(self.TIP)
layout = self.layout()
layout.addWidget(QLabel(self.TITLE))
self.label = QLabel()
self.label.setFont(self.label_font)
layout.addWidget(self.label)
layout.addSpacing(20)
if self.is_supported():
self.timer = QTimer()
self.timer.timeout.connect(self.update_label)
self.timer.start(2000)
else:
self.timer = None
self.hide()
def set_interval(self, interval):
"""Set timer interval (ms)"""
if self.timer is not None:
self.timer.setInterval(interval)
def import_test(self):
"""Raise ImportError if feature is not supported"""
raise NotImplementedError
def is_supported(self):
"""Return True if feature is supported"""
try:
self.import_test()
return True
except ImportError:
return False
def get_value(self):
"""Return value (e.g. CPU or memory usage)"""
raise NotImplementedError
def update_label(self):
"""Update status label widget, if widget is visible"""
if self.isVisible():
self.label.setText('%d %%' % self.get_value())
示例13: create_app
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
def create_app(datafiles=[], interactive=True):
app = get_qapp()
if interactive:
# Splash screen
splash = get_splash()
splash.image = QtGui.QPixmap(MOSVIZ_SPLASH_PATH)
splash.show()
else:
splash = None
# Start off by loading plugins. We need to do this before restoring
# the session or loading the configuration since these may use existing
# plugins.
load_plugins(splash=splash)
# # Show the splash screen for 2 seconds
if interactive:
timer = QTimer()
timer.setInterval(2000)
timer.setSingleShot(True)
timer.timeout.connect(splash.close)
timer.start()
data_collection = glue.core.DataCollection()
hub = data_collection.hub
if interactive:
splash.set_progress(100)
ga = _create_glue_app(data_collection, hub)
ga.run_startup_action('mosviz')
# Load the data files.
if datafiles:
datasets = load_data_files(datafiles)
ga.add_datasets(data_collection, datasets, auto_merge=False)
return ga
示例14: Connection
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
class Connection(PyDMConnection):
def __init__(self, widget, address, protocol=None, parent=None):
super(Connection, self).__init__(widget, address, protocol, parent)
self.add_listener(widget)
self.value = address
self.rand = 0
self.timer = QTimer(self)
self.timer.timeout.connect(self.send_new_value)
self.timer.start(1000)
self.connected = True
def send_new_value(self):
val_to_send = "{0}-{1}".format(self.value, random.randint(0, 9))
self.new_value_signal[str].emit(str(val_to_send))
def send_connection_state(self, conn):
self.connection_state_signal.emit(conn)
def add_listener(self, widget):
super(Connection, self).add_listener(widget)
self.send_connection_state(True)
示例15: ExternalShellBase
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import start [as 别名]
class ExternalShellBase(QWidget):
"""External Shell widget: execute Python script in a separate process"""
SHELL_CLASS = None
redirect_stdio = Signal(bool)
sig_finished = Signal()
def __init__(self, parent=None, fname=None, wdir=None,
history_filename=None, show_icontext=True,
light_background=True, menu_actions=None,
show_buttons_inside=True, show_elapsed_time=True):
QWidget.__init__(self, parent)
self.menu_actions = menu_actions
self.run_button = None
self.kill_button = None
self.options_button = None
self.icontext_action = None
self.show_elapsed_time = show_elapsed_time
self.fname = fname
if wdir is None:
wdir = osp.dirname(osp.abspath(fname))
self.wdir = wdir if osp.isdir(wdir) else None
self.arguments = ""
self.shell = self.SHELL_CLASS(parent, get_conf_path(history_filename))
self.shell.set_light_background(light_background)
self.shell.execute.connect(self.send_to_process)
self.shell.sig_keyboard_interrupt.connect(self.keyboard_interrupt)
# Redirecting some SIGNALs:
self.shell.redirect_stdio.connect(
lambda state: self.redirect_stdio.emit(state))
self.state_label = None
self.time_label = None
vlayout = QVBoxLayout()
toolbar_buttons = self.get_toolbar_buttons()
if show_buttons_inside:
self.state_label = QLabel()
hlayout = QHBoxLayout()
hlayout.addWidget(self.state_label)
hlayout.addStretch(0)
hlayout.addWidget(self.create_time_label())
hlayout.addStretch(0)
for button in toolbar_buttons:
hlayout.addWidget(button)
vlayout.addLayout(hlayout)
else:
vlayout.setContentsMargins(0, 0, 0, 0)
vlayout.addWidget(self.get_shell_widget())
self.setLayout(vlayout)
self.resize(640, 480)
if parent is None:
self.setWindowIcon(self.get_icon())
self.setWindowTitle(_("Console"))
self.t0 = None
self.timer = QTimer(self)
self.process = None
self.is_closing = False
if show_buttons_inside:
self.update_time_label_visibility()
@Slot(bool)
def set_elapsed_time_visible(self, state):
self.show_elapsed_time = state
if self.time_label is not None:
self.time_label.setVisible(state)
def create_time_label(self):
"""Create elapsed time label widget (if necessary) and return it"""
if self.time_label is None:
self.time_label = QLabel()
return self.time_label
def update_time_label_visibility(self):
self.time_label.setVisible(self.show_elapsed_time)
def is_running(self):
if self.process is not None:
return self.process.state() == QProcess.Running
def get_toolbar_buttons(self):
if self.run_button is None:
self.run_button = create_toolbutton(self, text=_("Run"),
icon=ima.icon('run'),
tip=_("Run again this program"),
triggered=self.start_shell)
if self.kill_button is None:
self.kill_button = create_toolbutton(self, text=_("Kill"),
icon=ima.icon('kill'),
tip=_("Kills the current process, "
"causing it to exit immediately"))
buttons = [self.run_button]
#.........这里部分代码省略.........