本文整理汇总了Python中spyderlib.qt.QtCore.QTimer.start方法的典型用法代码示例。如果您正苦于以下问题:Python QTimer.start方法的具体用法?Python QTimer.start怎么用?Python QTimer.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyderlib.qt.QtCore.QTimer
的用法示例。
在下文中一共展示了QTimer.start方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: qapplication
# 需要导入模块: from spyderlib.qt.QtCore import QTimer [as 别名]
# 或者: from spyderlib.qt.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: setup
# 需要导入模块: from spyderlib.qt.QtCore import QTimer [as 别名]
# 或者: from spyderlib.qt.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)
示例3: BaseTimerStatus
# 需要导入模块: from spyderlib.qt.QtCore import QTimer [as 别名]
# 或者: from spyderlib.qt.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())
示例4: FindReplace
# 需要导入模块: from spyderlib.qt.QtCore import QTimer [as 别名]
# 或者: from spyderlib.qt.QtCore.QTimer import start [as 别名]
#.........这里部分代码省略.........
codeeditor.base.TextEditBaseWidget
browser.WebView
"""
self.editor = editor
from spyderlib.qt.QtWebKit import QWebView
self.words_button.setVisible(not isinstance(editor, QWebView))
self.re_button.setVisible(not isinstance(editor, QWebView))
from spyderlib.widgets.sourcecode.codeeditor import CodeEditor
self.is_code_editor = isinstance(editor, CodeEditor)
self.highlight_button.setVisible(self.is_code_editor)
if refresh:
self.refresh()
if self.isHidden() and editor is not None:
self.clear_matches()
@Slot()
def find_next(self):
"""Find next occurrence"""
state = self.find(changed=False, forward=True, rehighlight=False)
self.editor.setFocus()
self.search_text.add_current_text()
return state
@Slot()
def find_previous(self):
"""Find previous occurrence"""
state = self.find(changed=False, forward=False, rehighlight=False)
self.editor.setFocus()
return state
def text_has_been_edited(self, text):
"""Find text has been edited (this slot won't be triggered when
setting the search pattern combo box text programmatically"""
self.find(changed=True, forward=True, start_highlight_timer=True)
def highlight_matches(self):
"""Highlight found results"""
if self.is_code_editor and self.highlight_button.isChecked():
text = self.search_text.currentText()
words = self.words_button.isChecked()
regexp = self.re_button.isChecked()
self.editor.highlight_found_results(text, words=words,
regexp=regexp)
def clear_matches(self):
"""Clear all highlighted matches"""
if self.is_code_editor:
self.editor.clear_found_results()
def find(self, changed=True, forward=True,
rehighlight=True, start_highlight_timer=False):
"""Call the find function"""
text = self.search_text.currentText()
if len(text) == 0:
self.search_text.lineEdit().setStyleSheet("")
return None
else:
case = self.case_button.isChecked()
words = self.words_button.isChecked()
regexp = self.re_button.isChecked()
found = self.editor.find_text(text, changed, forward, case=case,
words=words, regexp=regexp)
self.search_text.lineEdit().setStyleSheet(self.STYLE[found])
if self.is_code_editor and found:
if rehighlight or not self.editor.found_results:
self.highlight_timer.stop()
示例5: ExternalShellBase
# 需要导入模块: from spyderlib.qt.QtCore import QTimer [as 别名]
# 或者: from spyderlib.qt.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
#.........这里部分代码省略.........
示例6: ShellBaseWidget
# 需要导入模块: from spyderlib.qt.QtCore import QTimer [as 别名]
# 或者: from spyderlib.qt.QtCore.QTimer import start [as 别名]
#.........这里部分代码省略.........
def _key_ctrl_space(self):
raise NotImplementedError
def _key_home(self, shift, ctrl):
if self.is_cursor_on_last_line():
self.stdkey_home(shift, ctrl, self.current_prompt_pos)
def _key_end(self, shift, ctrl):
if self.is_cursor_on_last_line():
self.stdkey_end(shift, ctrl)
def _key_pageup(self):
raise NotImplementedError
def _key_pagedown(self):
raise NotImplementedError
def _key_escape(self):
raise NotImplementedError
def _key_question(self, text):
raise NotImplementedError
def _key_parenleft(self, text):
raise NotImplementedError
def _key_period(self, text):
raise NotImplementedError
#------ History Management
def load_history(self):
"""Load history from a .py file in user home directory"""
if osp.isfile(self.history_filename):
rawhistory, _ = encoding.readlines(self.history_filename)
rawhistory = [line.replace('\n', '') for line in rawhistory]
if rawhistory[1] != self.INITHISTORY[1]:
rawhistory[1] = self.INITHISTORY[1]
else:
rawhistory = self.INITHISTORY
history = [line for line in rawhistory \
if line and not line.startswith('#')]
# Truncating history to X entries:
while len(history) >= CONF.get('historylog', 'max_entries'):
del history[0]
while rawhistory[0].startswith('#'):
del rawhistory[0]
del rawhistory[0]
# Saving truncated history:
encoding.writelines(rawhistory, self.history_filename)
return history
def browse_history(self, backward):
"""Browse history"""
if self.is_cursor_before('eol') and self.hist_wholeline:
self.hist_wholeline = False
tocursor = self.get_current_line_to_cursor()
text, self.histidx = self.__find_in_history(tocursor,
self.histidx, backward)
if text is not None:
if self.hist_wholeline:
self.clear_line()
self.insert_text(text)
else:
cursor_position = self.get_position('cursor')
# Removing text from cursor to the end of the line
self.remove_text('cursor', 'eol')
# Inserting history text
self.insert_text(text)
self.set_cursor_position(cursor_position)
def __find_in_history(self, tocursor, start_idx, backward):
"""Find text 'tocursor' in history, from index 'start_idx'"""
示例7: Restarter
# 需要导入模块: from spyderlib.qt.QtCore import QTimer [as 别名]
# 或者: from spyderlib.qt.QtCore.QTimer import start [as 别名]
class Restarter(QWidget):
"""Widget in charge of displaying the splash information screen and the
error messages.
"""
def __init__(self):
super(Restarter, self).__init__()
self.ellipsis = ['', '.', '..', '...', '..', '.']
# Widgets
self.timer_ellipsis = QTimer(self)
self.splash = QSplashScreen(QPixmap(get_image_path('splash.svg'),
'svg'))
# Widget setup
self.setVisible(False)
font = self.splash.font()
font.setPixelSize(10)
self.splash.setFont(font)
self.splash.show()
self.timer_ellipsis.timeout.connect(self.animate_ellipsis)
def _show_message(self, text):
"""Show message on splash screen."""
self.splash.showMessage(text, Qt.AlignBottom | Qt.AlignCenter |
Qt.AlignAbsolute, QColor(Qt.white))
def animate_ellipsis(self):
"""Animate dots at the end of the splash screen message."""
ellipsis = self.ellipsis.pop(0)
text = ' '*len(ellipsis) + self.splash_text + ellipsis
self.ellipsis.append(ellipsis)
self._show_message(text)
def set_splash_message(self, text):
"""Sets the text in the bottom of the Splash screen."""
self.splash_text = text
self._show_message(text)
self.timer_ellipsis.start(500)
def launch_error_message(self, error_type, error=None):
"""Launch a message box with a predefined error message.
Parameters
----------
error_type : int [CLOSE_ERROR, RESET_ERROR, RESTART_ERROR]
Possible error codes when restarting/reseting spyder.
error : Exception
Actual Python exception error caught.
"""
messages = {CLOSE_ERROR: _("It was not possible to close the previous "
"Spyder instance.\nRestart aborted."),
RESET_ERROR: _("Spyder could not reset to factory "
"defaults.\nRestart aborted."),
RESTART_ERROR: _("It was not possible to restart Spyder.\n"
"Operation aborted.")}
titles = {CLOSE_ERROR: _("Spyder exit error"),
RESET_ERROR: _("Spyder reset error"),
RESTART_ERROR: _("Spyder restart error")}
if error:
e = error.__repr__()
message = messages[error_type] + _("\n\n{0}").format(e)
else:
message = messages[error_type]
title = titles[error_type]
self.splash.hide()
QMessageBox.warning(self, title, message, QMessageBox.Ok)
raise RuntimeError(message)
示例8: FindReplace
# 需要导入模块: from spyderlib.qt.QtCore import QTimer [as 别名]
# 或者: from spyderlib.qt.QtCore.QTimer import start [as 别名]
#.........这里部分代码省略.........
codeeditor.base.TextEditBaseWidget
browser.WebView
"""
self.editor = editor
from spyderlib.qt.QtWebKit import QWebView
self.words_button.setVisible(not isinstance(editor, QWebView))
self.re_button.setVisible(not isinstance(editor, QWebView))
from spyderlib.widgets.sourcecode.codeeditor import CodeEditor
self.is_code_editor = isinstance(editor, CodeEditor)
self.highlight_button.setVisible(self.is_code_editor)
if refresh:
self.refresh()
if self.isHidden() and editor is not None:
self.clear_matches()
def find_next(self):
"""Find next occurence"""
state = self.find(changed=False, forward=True, rehighlight=False)
self.editor.setFocus()
self.search_text.add_current_text()
return state
def find_previous(self):
"""Find previous occurence"""
state = self.find(changed=False, forward=False, rehighlight=False)
self.editor.setFocus()
return state
def text_has_been_edited(self, text):
"""Find text has been edited (this slot won't be triggered when
setting the search pattern combo box text programmatically"""
self.find(changed=True, forward=True, start_highlight_timer=True)
def highlight_matches(self):
"""Highlight found results"""
if self.is_code_editor and self.highlight_button.isChecked():
text = self.search_text.currentText()
words = self.words_button.isChecked()
regexp = self.re_button.isChecked()
self.editor.highlight_found_results(text, words=words, regexp=regexp)
def clear_matches(self):
"""Clear all highlighted matches"""
if self.is_code_editor:
self.editor.clear_found_results()
def find(self, changed=True, forward=True, rehighlight=True, start_highlight_timer=False):
"""Call the find function"""
text = self.search_text.currentText()
if len(text) == 0:
self.search_text.lineEdit().setStyleSheet("")
return None
else:
case = self.case_button.isChecked()
words = self.words_button.isChecked()
regexp = self.re_button.isChecked()
found = self.editor.find_text(text, changed, forward, case=case, words=words, regexp=regexp)
self.search_text.lineEdit().setStyleSheet(self.STYLE[found])
if found:
if rehighlight or not self.editor.found_results:
self.highlight_timer.stop()
if start_highlight_timer:
self.highlight_timer.start()
else:
示例9: AsyncClient
# 需要导入模块: from spyderlib.qt.QtCore import QTimer [as 别名]
# 或者: from spyderlib.qt.QtCore.QTimer import start [as 别名]
class AsyncClient(QObject):
"""
A class which handles a connection to a client through a QProcess.
"""
# Emitted when the client has initialized.
initialized = Signal()
# Emitted when the client errors.
errored = Signal()
# Emitted when a request response is received.
received = Signal(object)
def __init__(self, target, executable=None, name=None,
extra_args=None, libs=None, cwd=None, env=None):
super(AsyncClient, self).__init__()
self.executable = executable or sys.executable
self.extra_args = extra_args
self.target = target
self.name = name or self
self.libs = libs
self.cwd = cwd
self.env = env
self.is_initialized = False
self.closing = False
self.context = zmq.Context()
QApplication.instance().aboutToQuit.connect(self.close)
# Set up the heartbeat timer.
self.timer = QTimer(self)
self.timer.timeout.connect(self._heartbeat)
self.timer.start(HEARTBEAT)
def run(self):
"""Handle the connection with the server.
"""
# Set up the zmq port.
self.socket = self.context.socket(zmq.PAIR)
self.port = self.socket.bind_to_random_port('tcp://*')
# Set up the process.
self.process = QProcess(self)
if self.cwd:
self.process.setWorkingDirectory(self.cwd)
p_args = ['-u', self.target, str(self.port)]
if self.extra_args is not None:
p_args += self.extra_args
# Set up environment variables.
processEnvironment = QProcessEnvironment()
env = self.process.systemEnvironment()
if (self.env and 'PYTHONPATH' not in self.env) or DEV:
python_path = osp.dirname(get_module_path('spyderlib'))
# Add the libs to the python path.
for lib in self.libs:
try:
path = osp.dirname(imp.find_module(lib)[1])
python_path = osp.pathsep.join([python_path, path])
except ImportError:
pass
env.append("PYTHONPATH=%s" % python_path)
if self.env:
env.update(self.env)
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
self.process.setProcessEnvironment(processEnvironment)
# Start the process and wait for started.
self.process.start(self.executable, p_args)
self.process.finished.connect(self._on_finished)
running = self.process.waitForStarted()
if not running:
raise IOError('Could not start %s' % self)
# Set up the socket notifer.
fid = self.socket.getsockopt(zmq.FD)
self.notifier = QSocketNotifier(fid, QSocketNotifier.Read, self)
self.notifier.activated.connect(self._on_msg_received)
def request(self, func_name, *args, **kwargs):
"""Send a request to the server.
The response will be a dictionary the 'request_id' and the
'func_name' as well as a 'result' field with the object returned by
the function call or or an 'error' field with a traceback.
"""
if not self.is_initialized:
return
request_id = uuid.uuid4().hex
request = dict(func_name=func_name,
args=args,
kwargs=kwargs,
request_id=request_id)
try:
self.socket.send_pyobj(request)
except zmq.ZMQError:
pass
#.........这里部分代码省略.........