本文整理匯總了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):
#.........這裏部分代碼省略.........