本文整理汇总了Python中PyQt5.QtCore.QEventLoop.quit方法的典型用法代码示例。如果您正苦于以下问题:Python QEventLoop.quit方法的具体用法?Python QEventLoop.quit怎么用?Python QEventLoop.quit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QEventLoop
的用法示例。
在下文中一共展示了QEventLoop.quit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: waitForSignal
# 需要导入模块: from PyQt5.QtCore import QEventLoop [as 别名]
# 或者: from PyQt5.QtCore.QEventLoop import quit [as 别名]
def waitForSignal(signal, message="", timeout=0):
"""Waits (max timeout msecs if given) for a signal to be emitted.
It the waiting lasts more than 2 seconds, a progress dialog is displayed
with the message.
Returns True if the signal was emitted.
Return False if the wait timed out or the dialog was canceled by the user.
"""
loop = QEventLoop()
dlg = QProgressDialog(minimum=0, maximum=0, labelText=message)
dlg.setWindowTitle(appinfo.appname)
dlg.setWindowModality(Qt.ApplicationModal)
QTimer.singleShot(2000, dlg.show)
dlg.canceled.connect(loop.quit)
if timeout:
QTimer.singleShot(timeout, dlg.cancel)
stop = lambda: loop.quit()
signal.connect(stop)
loop.exec_()
signal.disconnect(stop)
dlg.hide()
dlg.deleteLater()
return not dlg.wasCanceled()
示例2: Ace
# 需要导入模块: from PyQt5.QtCore import QEventLoop [as 别名]
# 或者: from PyQt5.QtCore.QEventLoop import quit [as 别名]
class Ace(QWebView):
""" Embbeded Ace javascript web editor """
isReady = pyqtSignal(name='isReady')
modificationChanged = pyqtSignal(bool)
cursorPositionChanged = pyqtSignal(int, int, name='cursorPositionChanged')
def __init__(self, file_info, parent=None):
super(Ace, self).__init__(parent)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.parent = parent
self.file_info = file_info
self.language = EditorHelper.lang_from_file_info(file_info)
self.waitForReady = False
self.loop = QEventLoop()
settings = self.settings()
settings.setAttribute(QWebSettings.JavascriptCanAccessClipboard, True)
settings.setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
self.inspector = QWebInspector(self)
showInspectorAction = QAction('showInspector', self)
showInspectorAction.triggered.connect(self.showInspector)
self.addAction(showInspectorAction)
self.modificationChanged.connect(self.modification_changed)
self.main_frame().javaScriptWindowObjectCleared.connect(self.__self_js)
pckg, file_name = 'ace_editor', 'ace_editor.html'
resource = pkg_resources.resource_string(pckg, file_name)
html_template = str(resource, 'utf-8')
#insert file content
with open(self.file_info.absoluteFilePath(), 'r') as f:
text = f.read()
text = html.escape(text)
html_template = html_template.replace('{{ content }}', text)
base_url = QUrl.fromLocalFile(os.path.dirname(__file__))
self.setHtml(html_template, base_url)
self.modified = False
if not self.waitForReady:
self.loop.exec()
@pyqtSlot(str, name='test', result=str)
@EditorHelper.json_dumps
def test(self, prefix):
print(prefix)
return ['plop', 'cool', 42, {'plop':23}]
def modification_changed(self, b):
self.modified = b
def save(self, parent, action=None):
Alter.invoke_all('editor_presave', self)
if self.modified:
with open(self.file_info.absoluteFilePath(), 'w') as f:
f.write(self.get_value())
self.original_to_current_doc()
self.modificationChanged.emit(False)
parent.status_bar.showMessage(self.tr("Saved file."))
Alter.invoke_all('editor_save', self)
else :
parent.status_bar.showMessage(self.tr("Nothing to save."))
def toggle_hidden(self, parent, action=None):
self.set_show_invisibles(action.isChecked())
def toggle_soft_tabs(self, parent, action=None):
self.set_use_soft_tabs(action.isChecked())
def main_frame(self):
""" Convinient function to get main QWebFrame """
return self.page().mainFrame()
def send_js(self, script):
""" Convinient function to send javascript to ace editor """
return self.main_frame().evaluateJavaScript(script)
def __self_js(self):
self.main_frame().addToJavaScriptWindowObject('AceEditor', self)
@pyqtSlot(name='isReady')
def editor_ready(self):
if self.language != None:
self.set_mode(self.language.lower())
self.set_focus()
if self.loop.isRunning():
self.loop.quit()
self.waitForReady = True
def showInspector(self):
self.dialogInspector = QDialog(self)
self.dialogInspector.setLayout(QVBoxLayout())
self.dialogInspector.layout().addWidget(self.inspector)
self.dialogInspector.setModal(False)
self.dialogInspector.show()
def original_to_current_doc(self):
self.send_js('editor.orignalToCurrentDoc()')
def get_value(self):
#.........这里部分代码省略.........