当前位置: 首页>>代码示例>>Python>>正文


Python QEventLoop.exec方法代码示例

本文整理汇总了Python中PyQt5.QtCore.QEventLoop.exec方法的典型用法代码示例。如果您正苦于以下问题:Python QEventLoop.exec方法的具体用法?Python QEventLoop.exec怎么用?Python QEventLoop.exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtCore.QEventLoop的用法示例。


在下文中一共展示了QEventLoop.exec方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_request

# 需要导入模块: from PyQt5.QtCore import QEventLoop [as 别名]
# 或者: from PyQt5.QtCore.QEventLoop import exec [as 别名]
    def send_request(self, post=None, data={}):
        loop = QEventLoop()
        self.r.setUrl(self.url)
        if post:
            encoded_data = self._urlencode_post_data(data)
            pprint(encoded_data)
            self.reply_post = self.conn.post(self.r, encoded_data)
            self.reply_post.downloadProgress.connect(self.prepare_responce)

        else:
            self.reply = self.conn.get(self.r)
            self.reply.finished.connect(self.prepare_responce)
        # return \
        loop.exec()
开发者ID:blropb,项目名称:qt-test,代码行数:16,代码来源:browser.py

示例2: Ace

# 需要导入模块: from PyQt5.QtCore import QEventLoop [as 别名]
# 或者: from PyQt5.QtCore.QEventLoop import exec [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):
#.........这里部分代码省略.........
开发者ID:FlorianPerrot,项目名称:Mojuru,代码行数:103,代码来源:Ace.py


注:本文中的PyQt5.QtCore.QEventLoop.exec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。