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


Python Qt.QUrl类代码示例

本文整理汇总了Python中PyQt5.Qt.QUrl的典型用法代码示例。如果您正苦于以下问题:Python QUrl类的具体用法?Python QUrl怎么用?Python QUrl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: render_html

def render_html(path_to_html, width=590, height=750, as_xhtml=True):
    from PyQt5.QtWebKitWidgets import QWebPage
    from PyQt5.Qt import QEventLoop, QPalette, Qt, QUrl, QSize
    from calibre.gui2 import is_ok_to_use_qt
    if not is_ok_to_use_qt():
        return None
    path_to_html = os.path.abspath(path_to_html)
    with CurrentDir(os.path.dirname(path_to_html)):
        page = QWebPage()
        settings = page.settings()
        settings.setAttribute(settings.PluginsEnabled, False)
        pal = page.palette()
        pal.setBrush(QPalette.Background, Qt.white)
        page.setPalette(pal)
        page.setViewportSize(QSize(width, height))
        page.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
        page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
        loop = QEventLoop()
        renderer = HTMLRenderer(page, loop)
        page.loadFinished.connect(renderer, type=Qt.QueuedConnection)
        if as_xhtml:
            page.mainFrame().setContent(open(path_to_html, 'rb').read(),
                    'application/xhtml+xml', QUrl.fromLocalFile(path_to_html))
        else:
            page.mainFrame().load(QUrl.fromLocalFile(path_to_html))
        loop.exec_()
    renderer.loop = renderer.page = None
    page.loadFinished.disconnect()
    del page
    del loop
    if isinstance(renderer.exception, ParserError) and as_xhtml:
        return render_html(path_to_html, width=width, height=height,
                as_xhtml=False)
    return renderer
开发者ID:harrywright,项目名称:calibre,代码行数:34,代码来源:__init__.py

示例2: process_rule

    def process_rule(self, rule, is_ancestor, maximum_specificities):
        selector = rule['selector']
        sheet_index = rule['sheet_index']
        rule_address = rule['rule_address'] or ()
        if selector is not None:
            try:
                specificity = [0] + list(parse(selector)[0].specificity())
            except (AttributeError, TypeError, SelectorError):
                specificity = [0, 0, 0, 0]
        else:  # style attribute
            specificity = [1, 0, 0, 0]
        specificity.extend((sheet_index, tuple(rule_address)))
        ancestor_specificity = 0 if is_ancestor else 1
        properties = []
        for prop in rule['properties']:
            important = 1 if prop[-1] == 'important' else 0
            p = Property(prop, [ancestor_specificity] + [important] + specificity)
            properties.append(p)
            if p.specificity > maximum_specificities.get(p.name, (0,0,0,0,0,0)):
                maximum_specificities[p.name] = p.specificity
        rule['properties'] = properties

        href = rule['href']
        if hasattr(href, 'startswith') and href.startswith('%s://%s' % (FAKE_PROTOCOL, FAKE_HOST)):
            qurl = QUrl(href)
            name = qurl.path()[1:]
            if name:
                rule['href'] = name
开发者ID:JimmXinu,项目名称:calibre,代码行数:28,代码来源:live_css.py

示例3: get_proxy_auth_credentials

def get_proxy_auth_credentials(qurl, authenticator, proxy_host, parent=None):
    qurl = QUrl(qurl)
    qurl.setFragment(None)
    d = Credentials(_('Please specify a password for {0} at the proxy: {1}').format(qurl.toString(), proxy_host), parent)
    if d.exec_() == d.Accepted:
        username, password = d.credentials
        authenticator.setUser(username)
        authenticator.setPassword(password)
开发者ID:kovidgoyal,项目名称:vise,代码行数:8,代码来源:auth.py

示例4: urls_from_md

def urls_from_md(md):
    ans = list(md.urls())
    if md.hasText():
        # Chromium returns the url as text/plain on drag and drop of image
        text = md.text()
        if text and text.lstrip().partition(':')[0] in {'http', 'https', 'ftp'}:
            u = QUrl(text.strip())
            if u.isValid():
                ans.append(u)
    return ans
开发者ID:j-howell,项目名称:calibre,代码行数:10,代码来源:dnd.py

示例5: show

 def show(self, name):
     if name != self.current_name:
         self.refresh_timer.stop()
         self.current_name = name
         parse_worker.add_request(name)
         self.view.setUrl(QUrl.fromLocalFile(current_container().name_to_abspath(name)))
         return True
开发者ID:AtulKumar2,项目名称:calibre,代码行数:7,代码来源:preview.py

示例6: load

	def load(self, url = ''):
		p = re.compile('(^file:\/\/)|(^http:\/\/)|(^https:\/\/)|(^data:)')
		if url and p.match(url) == None:
			url = QUrl.fromLocalFile(os.path.abspath(url))
		else:
			url = QUrl(url)
		super(WebView, self).load(url)
开发者ID:andriodartisan,项目名称:hae,代码行数:7,代码来源:webview.py

示例7: show_help

 def show_help(self):
     '''
     Display strftime help file
     '''
     from calibre.gui2 import open_url
     path = os.path.join(self.parent.resources_path, 'help/timestamp_formats.html')
     open_url(QUrl.fromLocalFile(path))
开发者ID:Philantrop,项目名称:calibre-marvin-manager,代码行数:7,代码来源:appearance.py

示例8: open_local_file

def open_local_file(path):
    if iswindows:
        with sanitize_env_vars():
            os.startfile(os.path.normpath(path))
    else:
        url = QUrl.fromLocalFile(path)
        open_url(url)
开发者ID:AEliu,项目名称:calibre,代码行数:7,代码来源:__init__.py

示例9: load_html

def load_html(path, view, codec='utf-8', mime_type=None,
              pre_load_callback=lambda x:None, path_is_html=False,
              force_as_html=False, loading_url=None):
    from PyQt5.Qt import QUrl, QByteArray
    if mime_type is None:
        mime_type = guess_type(path)[0]
        if not mime_type:
            mime_type = 'text/html'
    if path_is_html:
        html = path
    else:
        with open(path, 'rb') as f:
            html = f.read().decode(codec, 'replace')

    html = cleanup_html(html)
    loading_url = loading_url or QUrl.fromLocalFile(path)
    pre_load_callback(loading_url)

    if force_as_html or load_as_html(html):
        view.setHtml(html, loading_url)
    else:
        view.setContent(QByteArray(html.encode(codec)), mime_type,
                loading_url)
        mf = view.page().mainFrame()
        elem = mf.findFirstElement('parsererror')
        if not elem.isNull():
            return False
    return True
开发者ID:j-howell,项目名称:calibre,代码行数:28,代码来源:webview.py

示例10: load_html

def load_html(path, view, codec='utf-8', mime_type=None,
              pre_load_callback=lambda x:None, path_is_html=False,
              force_as_html=False):
    from PyQt5.Qt import QUrl, QByteArray
    if mime_type is None:
        mime_type = guess_type(path)[0]
        if not mime_type:
            mime_type = 'text/html'
    if path_is_html:
        html = path
    else:
        with open(path, 'rb') as f:
            html = f.read().decode(codec, 'replace')

    html = EntityDeclarationProcessor(html).processed_html
    self_closing_pat = re.compile(r'<\s*([:A-Za-z0-9-]+)([^>]*)/\s*>')
    html = self_closing_pat.sub(self_closing_sub, html)

    loading_url = QUrl.fromLocalFile(path)
    pre_load_callback(loading_url)

    if force_as_html or re.search(r'<[a-zA-Z0-9-]+:svg', html) is None and '<![CDATA[' not in html:
        view.setHtml(html, loading_url)
    else:
        view.setContent(QByteArray(html.encode(codec)), mime_type,
                loading_url)
        mf = view.page().mainFrame()
        elem = mf.findFirstElement('parsererror')
        if not elem.isNull():
            return False
    return True
开发者ID:Riva3000,项目名称:calibre,代码行数:31,代码来源:webview.py

示例11: load_footnote_data

 def load_footnote_data(self, current_url):
     fd = self.footnote_data_cache[current_url] = {}
     try:
         raw = self.view.document.javascript('window.calibre_extract.get_footnote_data()', typ='string')
         for x in json.loads(raw or '{}'):
             if x not in fd:
                 qu = QUrl(x)
                 path = qu.toLocalFile()
                 spath = self.spine_path(path)
                 if spath is not None:
                     target = qu.fragment(QUrl.FullyDecoded)
                     fd[qu.toString()] = (spath, target, qu)
                     self.known_footnote_targets[spath].add(target)
     except Exception:
         prints('Failed to get footnote data, with error:')
         import traceback
         traceback.print_exc()
     return fd
开发者ID:AtulKumar2,项目名称:calibre,代码行数:18,代码来源:footnote.py

示例12: set_html

def set_html(mi, html, web_view):
    from calibre.gui2.ui import get_gui
    gui = get_gui()
    book_id = getattr(mi, 'id', None)
    if gui and book_id is not None:
        path = gui.current_db.abspath(book_id, index_is_id=True)
        if path:
            web_view.setHtml(html, QUrl.fromLocalFile(os.path.join(path, 'metadata.html')))
            return
    web_view.setHtml(html)
开发者ID:MarioJC,项目名称:calibre,代码行数:10,代码来源:book_details.py

示例13: _paste_and_go

def _paste_and_go(window, in_current_tab=True):
    c = QApplication.clipboard()
    for mode in c.Clipboard, c.Selection:
        text = c.text(mode).strip()
        if text:
            if text.partition(':')[0].lower() in {'file', 'http', 'https', 'about'}:
                qurl = QUrl.fromUserInput(text)
                if qurl.isValid() and not qurl.isEmpty():
                    window.open_url(qurl, in_current_tab=in_current_tab)
                    return
    window.show_status_message(_('No URL in clipboard'), 2, 'success')
开发者ID:kovidgoyal,项目名称:vise,代码行数:11,代码来源:actions.py

示例14: current_changed

 def current_changed(self, current, previous):
     link = current.data(Qt.UserRole)
     if link is None:
         return
     url = None
     if link.is_external:
         if link.href:
             frag = ('#' + link.anchor.id) if link.anchor.id else ''
             url = QUrl(link.href + frag)
     elif link.anchor.location:
         path = current_container().name_to_abspath(link.anchor.location.name)
         if path and os.path.exists(path):
             url = QUrl.fromLocalFile(path)
             if link.anchor.id:
                 url.setFragment(link.anchor.id)
     if url is None:
         self.view.setHtml('<p>' + _('No destination found for this link'))
         self.current_url = url
     elif url != self.current_url:
         self.current_url = url
         self.view.setUrl(url)
开发者ID:thuvh,项目名称:calibre,代码行数:21,代码来源:reports.py

示例15: toc_clicked

 def toc_clicked(self, index, force=False):
     if force or QApplication.mouseButtons() & Qt.LeftButton:
         item = self.toc_model.itemFromIndex(index)
         if item.abspath is not None:
             if not os.path.exists(item.abspath):
                 return error_dialog(self, _('No such location'),
                         _('The location pointed to by this item'
                             ' does not exist.'), det_msg=item.abspath, show=True)
             url = QUrl.fromLocalFile(item.abspath)
             if item.fragment:
                 url.setFragment(item.fragment)
             self.link_clicked(url)
     self.view.setFocus(Qt.OtherFocusReason)
开发者ID:Solertis,项目名称:calibre,代码行数:13,代码来源:main.py


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