本文整理汇总了Python中qtpy.QtCore.QTimer.setSingleShot方法的典型用法代码示例。如果您正苦于以下问题:Python QTimer.setSingleShot方法的具体用法?Python QTimer.setSingleShot怎么用?Python QTimer.setSingleShot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtCore.QTimer
的用法示例。
在下文中一共展示了QTimer.setSingleShot方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: embed
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import setSingleShot [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)
示例2: open_in_window
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import setSingleShot [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_())
示例3: create_app
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import setSingleShot [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
示例4: ShellBaseWidget
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import setSingleShot [as 别名]
class ShellBaseWidget(ConsoleBaseWidget, SaveHistoryMixin):
"""
Shell base widget
"""
redirect_stdio = Signal(bool)
sig_keyboard_interrupt = Signal()
execute = Signal(str)
append_to_history = Signal(str, str)
def __init__(self, parent, history_filename, profile=False):
"""
parent : specifies the parent widget
"""
ConsoleBaseWidget.__init__(self, parent)
SaveHistoryMixin.__init__(self)
# Prompt position: tuple (line, index)
self.current_prompt_pos = None
self.new_input_line = True
# History
self.histidx = None
self.hist_wholeline = False
assert is_text_string(history_filename)
self.history_filename = history_filename
self.history = self.load_history()
# Session
self.historylog_filename = CONF.get('main', 'historylog_filename',
get_conf_path('history.log'))
# Context menu
self.menu = None
self.setup_context_menu()
# Simple profiling test
self.profile = profile
# Buffer to increase performance of write/flush operations
self.__buffer = []
self.__timestamp = 0.0
self.__flushtimer = QTimer(self)
self.__flushtimer.setSingleShot(True)
self.__flushtimer.timeout.connect(self.flush)
# Give focus to widget
self.setFocus()
# Cursor width
self.setCursorWidth( CONF.get('main', 'cursor/width') )
def toggle_wrap_mode(self, enable):
"""Enable/disable wrap mode"""
self.set_wrap_mode('character' if enable else None)
def set_font(self, font):
"""Set shell styles font"""
self.setFont(font)
self.set_pythonshell_font(font)
cursor = self.textCursor()
cursor.select(QTextCursor.Document)
charformat = QTextCharFormat()
charformat.setFontFamily(font.family())
charformat.setFontPointSize(font.pointSize())
cursor.mergeCharFormat(charformat)
#------ Context menu
def setup_context_menu(self):
"""Setup shell context menu"""
self.menu = QMenu(self)
self.cut_action = create_action(self, _("Cut"),
shortcut=keybinding('Cut'),
icon=ima.icon('editcut'),
triggered=self.cut)
self.copy_action = create_action(self, _("Copy"),
shortcut=keybinding('Copy'),
icon=ima.icon('editcopy'),
triggered=self.copy)
paste_action = create_action(self, _("Paste"),
shortcut=keybinding('Paste'),
icon=ima.icon('editpaste'),
triggered=self.paste)
save_action = create_action(self, _("Save history log..."),
icon=ima.icon('filesave'),
tip=_("Save current history log (i.e. all "
"inputs and outputs) in a text file"),
triggered=self.save_historylog)
self.delete_action = create_action(self, _("Delete"),
shortcut=keybinding('Delete'),
icon=ima.icon('editdelete'),
triggered=self.delete)
selectall_action = create_action(self, _("Select All"),
shortcut=keybinding('SelectAll'),
icon=ima.icon('selectall'),
triggered=self.selectAll)
add_actions(self.menu, (self.cut_action, self.copy_action,
paste_action, self.delete_action, None,
selectall_action, None, save_action) )
#.........这里部分代码省略.........
示例5: AutosaveForPlugin
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import setSingleShot [as 别名]
class AutosaveForPlugin(object):
"""Component of editor plugin implementing autosave functionality."""
# Interval (in ms) between two autosaves
DEFAULT_AUTOSAVE_INTERVAL = 60 * 1000
def __init__(self, editor):
"""
Constructor.
Autosave is disabled after construction and needs to be enabled
explicitly if required.
Args:
editor (Editor): editor plugin.
"""
self.editor = editor
self.timer = QTimer(self.editor)
self.timer.setSingleShot(True)
self.timer.timeout.connect(self.do_autosave)
self._enabled = False # Can't use setter here
self._interval = self.DEFAULT_AUTOSAVE_INTERVAL
@property
def enabled(self):
"""
Get or set whether autosave component is enabled.
The setter will start or stop the autosave component if appropriate.
"""
return self._enabled
@enabled.setter
def enabled(self, new_enabled):
if new_enabled == self.enabled:
return
self.stop_autosave_timer()
self._enabled = new_enabled
self.start_autosave_timer()
@property
def interval(self):
"""
Interval between two autosaves, in milliseconds.
The setter will perform an autosave if the interval is changed and
autosave is enabled.
"""
return self._interval
@interval.setter
def interval(self, new_interval):
if new_interval == self.interval:
return
self.stop_autosave_timer()
self._interval = new_interval
if self.enabled:
self.do_autosave()
def start_autosave_timer(self):
"""
Start a timer which calls do_autosave() after `self.interval`.
The autosave timer is only started if autosave is enabled.
"""
if self.enabled:
self.timer.start(self.interval)
def stop_autosave_timer(self):
"""Stop the autosave timer."""
self.timer.stop()
def do_autosave(self):
"""Instruct current editorstack to autosave files where necessary."""
logger.debug('Autosave triggered')
stack = self.editor.get_current_editorstack()
stack.autosave.autosave_all()
self.start_autosave_timer()
def try_recover_from_autosave(self):
"""Offer to recover files from autosave."""
autosave_dir = get_conf_path('autosave')
autosave_mapping = CONF.get('editor', 'autosave_mapping', {})
dialog = RecoveryDialog(autosave_dir, autosave_mapping,
parent=self.editor)
dialog.exec_if_nonempty()
self.recover_files_to_open = dialog.files_to_open[:]
示例6: create_app
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import setSingleShot [as 别名]
def create_app(datafiles=[], data_configs=[], data_configs_show=False,
interactive=True):
"""
Create and initialize a cubeviz application instance
Parameters
----------
datafiles : `list`
A list of filenames representing data files to be loaded
data_configs : `list`
A list of filenames representing data configuration files to be used
data_configs_show : `bool`
Display matching info about data configuration files
interactive : `bool`
Flag to indicate whether session is interactive or not (i.e. for testing)
"""
app = get_qapp()
# Splash screen
if interactive:
splash = get_splash()
splash.image = QtGui.QPixmap(CUBEVIZ_LOGO_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)
dfc_kwargs = dict(remove_defaults=True, check_ifu_valid=interactive)
DataFactoryConfiguration(data_configs, data_configs_show, **dfc_kwargs)
# Check to make sure each file exists and raise an Exception
# that will show in the popup if it does not exist.
_check_datafiles_exist(datafiles)
# Show the splash screen for 1 second
if interactive:
timer = QTimer()
timer.setInterval(1000)
timer.setSingleShot(True)
timer.timeout.connect(splash.close)
timer.start()
data_collection = glue.core.DataCollection()
hub = data_collection.hub
ga = _create_glue_app(data_collection, hub)
ga.run_startup_action('cubeviz')
# Load the data files.
if datafiles:
datasets = load_data_files(datafiles)
ga.add_datasets(data_collection, datasets, auto_merge=False)
if interactive:
splash.set_progress(100)
return ga
示例7: start_glue
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import setSingleShot [as 别名]
def start_glue(gluefile=None, config=None, datafiles=None, maximized=True):
"""Run a glue session and exit
Parameters
----------
gluefile : str
An optional ``.glu`` file to restore.
config : str
An optional configuration file to use.
datafiles : str
An optional list of data files to load.
maximized : bool
Maximize screen on startup. Otherwise, use default size.
"""
import glue
from glue.utils.qt import get_qapp
app = get_qapp()
splash = get_splash()
splash.show()
# 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)
from glue.app.qt import GlueApplication
datafiles = datafiles or []
hub = None
if gluefile is not None:
app = restore_session(gluefile)
return app.start()
if config is not None:
glue.env = glue.config.load_configuration(search_path=[config])
data_collection = glue.core.DataCollection()
hub = data_collection.hub
splash.set_progress(100)
session = glue.core.Session(data_collection=data_collection, hub=hub)
ga = GlueApplication(session=session)
from qtpy.QtCore import QTimer
timer = QTimer()
timer.setInterval(1000)
timer.setSingleShot(True)
timer.timeout.connect(splash.close)
timer.start()
if datafiles:
datasets = load_data_files(datafiles)
ga.add_datasets(data_collection, datasets)
return ga.start(maximized=maximized)
示例8: ScriptRunner
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import setSingleShot [as 别名]
class ScriptRunner(object):
"""
Runs a script that interacts with a widget (tests it).
If the script is a python generator then after each iteration controls returns
to the QApplication's event loop.
Generator scripts can yield a positive number. It is treated as the number of seconds
before the next iteration is called. During the wait time the event loop is running.
"""
def __init__(self, script, widget=None, close_on_finish=True, pause=0, is_cli=False):
"""
Initialise a runner.
:param script: The script to run.
:param widget: The widget to test.
:param close_on_finish: If true close the widget after the script has finished.
:param is_cli: If true the script is to be run from a command line tool. Exceptions are
treated slightly differently in this case.
"""
app = get_application()
self.script = script
self.widget = widget
self.close_on_finish = close_on_finish
self.pause = pause
self.is_cli = is_cli
self.error = None
self.script_iter = [None]
self.pause_timer = QTimer(app)
self.pause_timer.setSingleShot(True)
self.script_timer = QTimer(app)
def run(self):
ret = run_script(self.script, self.widget)
if isinstance(ret, Exception):
raise ret
self.script_iter = [iter(ret) if inspect.isgenerator(ret) else None]
if self.pause != 0:
self.script_timer.setInterval(self.pause * 1000)
# Zero-timeout timer runs script_runner() between Qt events
self.script_timer.timeout.connect(self, Qt.QueuedConnection)
QMetaObject.invokeMethod(self.script_timer, 'start', Qt.QueuedConnection)
def __call__(self):
app = get_application()
if not self.pause_timer.isActive():
try:
script_iter = self.script_iter[-1]
if script_iter is None:
if self.close_on_finish:
app.closeAllWindows()
app.exit()
return
# Run test script until the next 'yield'
try:
ret = next(script_iter)
except ValueError:
return
while ret is not None:
if inspect.isgenerator(ret):
self.script_iter.append(ret)
ret = None
elif isinstance(ret, six.integer_types) or isinstance(ret, float):
# Start non-blocking pause in seconds
self.pause_timer.start(int(ret * 1000))
ret = None
else:
ret = ret()
except StopIteration:
if len(self.script_iter) > 1:
self.script_iter.pop()
else:
self.script_iter = [None]
self.script_timer.stop()
if self.close_on_finish:
app.closeAllWindows()
app.exit(0)
except Exception as e:
self.script_iter = [None]
traceback.print_exc()
if self.close_on_finish:
app.exit(1)
self.error = e
示例9: FindReplace
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import setSingleShot [as 别名]
#.........这里部分代码省略.........
# Replace layout
replace_with = QLabel(_("Replace with:"))
self.replace_text = PatternComboBox(self, adjust_to_minimum=False,
tip=_('Replace string'))
self.replace_button = create_toolbutton(self,
text=_('Replace/find'),
icon=ima.icon('DialogApplyButton'),
triggered=self.replace_find,
text_beside_icon=True)
self.replace_button.clicked.connect(self.update_replace_combo)
self.replace_button.clicked.connect(self.update_search_combo)
self.all_check = QCheckBox(_("Replace all"))
self.replace_layout = QHBoxLayout()
widgets = [replace_with, self.replace_text, self.replace_button,
self.all_check]
for widget in widgets:
self.replace_layout.addWidget(widget)
glayout.addLayout(self.replace_layout, 1, 1)
self.widgets.extend(widgets)
self.replace_widgets = widgets
self.hide_replace()
self.search_text.setTabOrder(self.search_text, self.replace_text)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.shortcuts = self.create_shortcuts(parent)
self.highlight_timer = QTimer(self)
self.highlight_timer.setSingleShot(True)
self.highlight_timer.setInterval(1000)
self.highlight_timer.timeout.connect(self.highlight_matches)
def create_shortcuts(self, parent):
"""Create shortcuts for this widget"""
# Configurable
findnext = config_shortcut(self.find_next, context='_',
name='Find next', parent=parent)
findprev = config_shortcut(self.find_previous, context='_',
name='Find previous', parent=parent)
togglefind = config_shortcut(self.show, context='_',
name='Find text', parent=parent)
togglereplace = config_shortcut(self.toggle_replace_widgets,
context='_', name='Replace text',
parent=parent)
# Fixed
fixed_shortcut("Escape", self, self.hide)
return [findnext, findprev, togglefind, togglereplace]
def get_shortcut_data(self):
"""
Returns shortcut data, a list of tuples (shortcut, text, default)
shortcut (QShortcut or QAction instance)
text (string): action/shortcut description
default (string): default key sequence
"""
return [sc.data for sc in self.shortcuts]
def update_search_combo(self):
self.search_text.lineEdit().returnPressed.emit()
示例10: start_glue
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import setSingleShot [as 别名]
def start_glue(gluefile=None, config=None, datafiles=None, maximized=True,
startup_actions=None, auto_merge=False):
"""Run a glue session and exit
Parameters
----------
gluefile : str
An optional ``.glu`` file to restore.
config : str
An optional configuration file to use.
datafiles : str
An optional list of data files to load.
maximized : bool
Maximize screen on startup. Otherwise, use default size.
auto_merge : bool, optional
Whether to automatically merge data passed in `datafiles` (default is `False`)
"""
import glue
# Some Qt modules are picky in terms of being imported before the
# application is set up, so we import them here. We do it here rather
# than in get_qapp since in the past, including this code in get_qapp
# caused severe issues (e.g. segmentation faults) in plugin packages
# during testing.
try:
from qtpy import QtWebEngineWidgets # noqa
except ImportError: # Not all PyQt installations have this module
pass
from glue.utils.qt import get_qapp
app = get_qapp()
splash = get_splash()
splash.show()
# 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)
from glue.app.qt import GlueApplication
datafiles = datafiles or []
hub = None
from qtpy.QtCore import QTimer
timer = QTimer()
timer.setInterval(1000)
timer.setSingleShot(True)
timer.timeout.connect(splash.close)
timer.start()
if gluefile is not None:
app = restore_session(gluefile)
return app.start()
if config is not None:
glue.env = glue.config.load_configuration(search_path=[config])
data_collection = glue.core.DataCollection()
hub = data_collection.hub
splash.set_progress(100)
session = glue.core.Session(data_collection=data_collection, hub=hub)
ga = GlueApplication(session=session)
if datafiles:
datasets = load_data_files(datafiles)
ga.add_datasets(data_collection, datasets, auto_merge=auto_merge)
if startup_actions is not None:
for name in startup_actions:
ga.run_startup_action(name)
return ga.start(maximized=maximized)
示例11: FindReplace
# 需要导入模块: from qtpy.QtCore import QTimer [as 别名]
# 或者: from qtpy.QtCore.QTimer import setSingleShot [as 别名]
#.........这里部分代码省略.........
self.replace_sel_button = create_toolbutton(self,
text=_('Replace selection'),
icon=ima.icon('DialogApplyButton'),
triggered=self.replace_find_selection,
text_beside_icon=True)
self.replace_sel_button.clicked.connect(self.update_replace_combo)
self.replace_sel_button.clicked.connect(self.update_search_combo)
self.replace_all_button = create_toolbutton(self,
text=_('Replace all'),
icon=ima.icon('DialogApplyButton'),
triggered=self.replace_find_all,
text_beside_icon=True)
self.replace_all_button.clicked.connect(self.update_replace_combo)
self.replace_all_button.clicked.connect(self.update_search_combo)
self.replace_layout = QHBoxLayout()
widgets = [replace_with, self.replace_text, self.replace_button,
self.replace_sel_button, self.replace_all_button]
for widget in widgets:
self.replace_layout.addWidget(widget)
glayout.addLayout(self.replace_layout, 1, 1)
self.widgets.extend(widgets)
self.replace_widgets = widgets
self.hide_replace()
self.search_text.setTabOrder(self.search_text, self.replace_text)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.shortcuts = self.create_shortcuts(parent)
self.highlight_timer = QTimer(self)
self.highlight_timer.setSingleShot(True)
self.highlight_timer.setInterval(1000)
self.highlight_timer.timeout.connect(self.highlight_matches)
self.search_text.installEventFilter(self)
def eventFilter(self, widget, event):
"""Event filter for search_text widget.
Emits signals when presing Enter and Shift+Enter.
This signals are used for search forward and backward.
Also, a crude hack to get tab working in the Find/Replace boxes.
"""
if event.type() == QEvent.KeyPress:
key = event.key()
shift = event.modifiers() & Qt.ShiftModifier
if key == Qt.Key_Return:
if shift:
self.return_shift_pressed.emit()
else:
self.return_pressed.emit()
if key == Qt.Key_Tab:
if self.search_text.hasFocus():
self.replace_text.set_current_text(
self.search_text.currentText())
self.focusNextChild()
return super(FindReplace, self).eventFilter(widget, event)
def create_shortcuts(self, parent):
"""Create shortcuts for this widget"""
# Configurable