當前位置: 首頁>>代碼示例>>Python>>正文


Python QEventLoop.processEvents方法代碼示例

本文整理匯總了Python中PyQt4.Qt.QEventLoop.processEvents方法的典型用法代碼示例。如果您正苦於以下問題:Python QEventLoop.processEvents方法的具體用法?Python QEventLoop.processEvents怎麽用?Python QEventLoop.processEvents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyQt4.Qt.QEventLoop的用法示例。


在下文中一共展示了QEventLoop.processEvents方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _wait_for_replies

# 需要導入模塊: from PyQt4.Qt import QEventLoop [as 別名]
# 或者: from PyQt4.Qt.QEventLoop import processEvents [as 別名]
 def _wait_for_replies(self, reply_count, timeout):
     final_time = time.time() + (self.default_timeout if timeout is default_timeout else timeout)
     loop = QEventLoop(self)
     while time.time() < final_time and self.nam.reply_count < reply_count:
         loop.processEvents()
         time.sleep(0.1)
     if self.nam.reply_count < reply_count:
         raise Timeout("Waiting for replies took longer than %d seconds" % timeout)
開發者ID:palerdot,項目名稱:calibre,代碼行數:10,代碼來源:browser.py

示例2: _wait_for_replies

# 需要導入模塊: from PyQt4.Qt import QEventLoop [as 別名]
# 或者: from PyQt4.Qt.QEventLoop import processEvents [as 別名]
 def _wait_for_replies(self, reply_count, timeout):
     final_time = time.time() + timeout
     loop = QEventLoop(self)
     while (time.time() < final_time and self.nam.reply_count <
             reply_count):
         loop.processEvents()
         time.sleep(0.1)
     if self.nam.reply_count < reply_count:
         raise Timeout('Waiting for replies took longer than %d seconds' %
                 timeout)
開發者ID:bjhemens,項目名稱:calibre,代碼行數:12,代碼來源:browser.py

示例3: do_print

# 需要導入模塊: from PyQt4.Qt import QEventLoop [as 別名]
# 或者: from PyQt4.Qt.QEventLoop import processEvents [as 別名]
    def do_print(self, printer):
        painter = QPainter(printer)
        zoomx = printer.logicalDpiX()/self.view.logicalDpiX()
        zoomy = printer.logicalDpiY()/self.view.logicalDpiY()
        painter.scale(zoomx, zoomy)
        pr = printer.pageRect()
        self.view.page().setViewportSize(QSize(pr.width()/zoomx,
            pr.height()/zoomy))
        evaljs = self.mf.evaluateJavaScript
        loop = QEventLoop(self)
        pagenum = 0
        from_, to = printer.fromPage(), printer.toPage()
        first = True

        for path in self.iterator.spine:
            self.loaded_ok = None
            load_html(path, self.view, codec=getattr(path, 'encoding', 'utf-8'),
                    mime_type=getattr(path, 'mime_type', None))
            while self.loaded_ok is None:
                loop.processEvents(loop.ExcludeUserInputEvents)
            if not self.loaded_ok:
                return error_dialog(self.parent(), _('Failed to render'),
                        _('Failed to render document %s')%path, show=True)
            evaljs(self.paged_js)
            evaljs('''
                document.body.style.backgroundColor = "white";
                paged_display.set_geometry(1, 0, 0, 0);
                paged_display.layout();
                paged_display.fit_images();
            ''')

            while True:
                pagenum += 1
                if (pagenum >= from_ and (to == 0 or pagenum <= to)):
                    if not first:
                        printer.newPage()
                    first = False
                    self.mf.render(painter)
                nsl = evaljs('paged_display.next_screen_location()').toInt()
                if not nsl[1] or nsl[0] <= 0: break
                evaljs('window.scrollTo(%d, 0)'%nsl[0])

        painter.end()
開發者ID:089git,項目名稱:calibre,代碼行數:45,代碼來源:printing.py

示例4: download_file

# 需要導入模塊: from PyQt4.Qt import QEventLoop [as 別名]
# 或者: from PyQt4.Qt.QEventLoop import processEvents [as 別名]
    def download_file(self, url_or_selector_or_qwe, timeout=60):
        """
        Download unsupported content: i.e. files the browser cannot handle
        itself or files marked for saving as files by the website. Useful if
        you want to download something like an epub file after authentication.

        You can pass in either the url to the file to be downloaded, or a
        selector that points to an element to be clicked on the current page
        which will cause the file to be downloaded.
        """
        ans = [False, None, []]
        loop = QEventLoop(self)
        start_time = time.time()
        end_time = start_time + timeout
        self.page.unsupportedContent.disconnect(self.page.on_unsupported_content)
        try:

            def download(reply):
                if ans[0]:
                    reply.abort()  # We only handle the first unsupported download
                    return
                ans[0] = True
                while not reply.isFinished() and end_time > time.time():
                    if not loop.processEvents():
                        time.sleep(0.01)
                    raw = bytes(bytearray(reply.readAll()))
                    if raw:
                        ans[-1].append(raw)
                if not reply.isFinished():
                    ans[1] = Timeout("Loading of %r took longer than %d seconds" % (url_or_selector_or_qwe, timeout))
                ans[-1].append(bytes(bytearray(reply.readAll())))

            self.page.unsupportedContent.connect(download)
            if hasattr(url_or_selector_or_qwe, "rstrip") and re.match("[a-z]+://", url_or_selector_or_qwe) is not None:
                # We have a URL
                self.page.mainFrame().load(QUrl(url_or_selector_or_qwe))
            else:
                self.click(url_or_selector_or_qwe, wait_for_load=False)
            lw = LoadWatcher(self.page)
            while not ans[0] and lw.is_loading and end_time > time.time():
                if not loop.processEvents():
                    time.sleep(0.01)
            if not ans[0]:
                raise NotAFile(
                    "%r does not point to a downloadable file. You can only"
                    " use this method to download files that the browser cannot handle"
                    " natively. Or files that are marked with the "
                    " content-disposition: attachment header" % url_or_selector_or_qwe
                )
            if ans[1] is not None:
                raise ans[1]
            return b"".join(ans[-1])
        finally:
            self.page.unsupportedContent.disconnect()
            self.page.unsupportedContent.connect(self.page.on_unsupported_content)
開發者ID:palerdot,項目名稱:calibre,代碼行數:57,代碼來源:browser.py

示例5: _wait_for_load

# 需要導入模塊: from PyQt4.Qt import QEventLoop [as 別名]
# 或者: from PyQt4.Qt.QEventLoop import processEvents [as 別名]
    def _wait_for_load(self, timeout, url=None):
        timeout = self.default_timeout if timeout is default_timeout else timeout
        loop = QEventLoop(self)
        start_time = time.time()
        end_time = start_time + timeout
        lw = LoadWatcher(self.page, parent=self)
        while lw.is_loading and end_time > time.time():
            if not loop.processEvents():
                time.sleep(0.01)
        if lw.is_loading:
            raise Timeout("Loading of %r took longer than %d seconds" % (url, timeout))

        return lw.loaded_ok
開發者ID:palerdot,項目名稱:calibre,代碼行數:15,代碼來源:browser.py

示例6: PDFWriter

# 需要導入模塊: from PyQt4.Qt import QEventLoop [as 別名]
# 或者: from PyQt4.Qt.QEventLoop import processEvents [as 別名]

#.........這裏部分代碼省略.........
    def render_html(self, ok):
        if ok:
            try:
                self.do_paged_render()
            except:
                self.log.exception('Rendering failed')
                self.loop.exit(1)
                return
        else:
            # The document is so corrupt that we can't render the page.
            self.logger.error('Document cannot be rendered.')
            self.loop.exit(1)
            return
        done = self.total_items - len(self.render_queue)
        self.report_progress(done/self.total_items,
                        _('Rendered %s'%os.path.basename(self.current_item)))
        self.render_book()

    @property
    def current_page_num(self):
        return self.doc.current_page_num

    def load_mathjax(self):
        evaljs = self.view.page().mainFrame().evaluateJavaScript
        mjpath = P(u'viewer/mathjax').replace(os.sep, '/')
        if iswindows:
            mjpath = u'/' + mjpath
        if evaljs('''
                    window.mathjax.base = %s;
                    mathjax.check_for_math(); mathjax.math_present
                    '''%(json.dumps(mjpath, ensure_ascii=False))).toBool():
            self.log.debug('Math present, loading MathJax')
            while not evaljs('mathjax.math_loaded').toBool():
                self.loop.processEvents(self.loop.ExcludeUserInputEvents)
            evaljs('document.getElementById("MathJax_Message").style.display="none";')

    def get_sections(self, anchor_map):
        sections = {}
        ci = os.path.abspath(os.path.normcase(self.current_item))
        if self.toc is not None:
            for toc in self.toc.flat():
                path = toc.abspath or None
                frag = toc.fragment or None
                if path is None:
                    continue
                path = os.path.abspath(os.path.normcase(path))
                if path == ci:
                    col = 0
                    if frag and frag in anchor_map:
                        col = anchor_map[frag]['column']
                    if col not in sections:
                        sections[col] = toc.text or _('Untitled')

        return sections

    def do_paged_render(self):
        if self.paged_js is None:
            import uuid
            from calibre.utils.resources import compiled_coffeescript as cc
            self.paged_js =  cc('ebooks.oeb.display.utils')
            self.paged_js += cc('ebooks.oeb.display.indexing')
            self.paged_js += cc('ebooks.oeb.display.paged')
            self.paged_js += cc('ebooks.oeb.display.mathjax')
            self.hf_uuid = str(uuid.uuid4()).replace('-', '')

        self.view.page().mainFrame().addToJavaScriptWindowObject("py_bridge", self)
開發者ID:iwannafly,項目名稱:calibre,代碼行數:70,代碼來源:from_html.py

示例7: run_for_a_time

# 需要導入模塊: from PyQt4.Qt import QEventLoop [as 別名]
# 或者: from PyQt4.Qt.QEventLoop import processEvents [as 別名]
 def run_for_a_time(self, timeout):
     final_time = time.time() + timeout
     loop = QEventLoop(self)
     while time.time() < final_time:
         if not loop.processEvents():
             time.sleep(0.1)
開發者ID:palerdot,項目名稱:calibre,代碼行數:8,代碼來源:browser.py


注:本文中的PyQt4.Qt.QEventLoop.processEvents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。