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


Python Qt.QUrl类代码示例

本文整理汇总了Python中PyQt4.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 PyQt4.QtWebKit import QWebPage
    from PyQt4.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()
        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:yeyanchao,项目名称:calibre,代码行数:31,代码来源:__init__.py

示例2: 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 PyQt4.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:
        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:iwannafly,项目名称:calibre,代码行数:31,代码来源:webview.py

示例3: 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:kbw1,项目名称:calibre-marvin-manager,代码行数:7,代码来源:appearance.py

示例4: load_html

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

    html = EntityDeclarationProcessor(html).processed_html
    has_svg = re.search(r'<[:a-zA-Z]*svg', html) is not None
    if 'xhtml' in mime_type:
        self_closing_pat = re.compile(r'<([a-z1-6]+)\s+([^>]+)/>',
                re.IGNORECASE)
        html = self_closing_pat.sub(self_closing_sub, html)

    html = re.sub(ur'<\s*title\s*/\s*>', u'', html, flags=re.IGNORECASE)
    loading_url = QUrl.fromLocalFile(path)
    pre_load_callback(loading_url)

    if has_svg:
        view.setContent(QByteArray(html.encode(codec)), mime_type,
                loading_url)
    else:
        view.setHtml(html, loading_url)
开发者ID:Eksmo,项目名称:calibre,代码行数:27,代码来源:webview.py

示例5: setDocument

 def setDocument(self, filename, empty=""):
     """Sets the HTML text to be displayed. """
     self._source = QUrl.fromLocalFile(filename)
     if os.path.exists(filename):
         self.viewer.setSource(self._source)
     else:
         self.viewer.setText(empty)
开发者ID:kernsuite-debian,项目名称:purr,代码行数:7,代码来源:MainWindow.py

示例6: 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:Kielek,项目名称:calibre,代码行数:7,代码来源:preview.py

示例7: mimeData

 def mimeData(self, itemlist):
     mimedata = QMimeData()
     urls = []
     for item in itemlist:
         dp = getattr(item, "_dp", None)
         dp and urls.append(QUrl.fromLocalFile(dp.fullpath or dp.sourcepath))
     mimedata.setUrls(urls)
     return mimedata
开发者ID:kernsuite-debian,项目名称:purr,代码行数:8,代码来源:MainWindow.py

示例8: parse_link

    def parse_link(self, link):
        link = link.strip()
        has_schema = re.match(r'^[a-zA-Z]+:', link)
        if has_schema is not None:
            url = QUrl(link, QUrl.TolerantMode)
            if url.isValid():
                return url
        if os.path.exists(link):
            return QUrl.fromLocalFile(link)

        if has_schema is None:
            first, _, rest = link.partition('.')
            prefix = 'http'
            if first == 'ftp':
                prefix = 'ftp'
            url = QUrl(prefix +'://'+link, QUrl.TolerantMode)
            if url.isValid():
                return url

        return QUrl(link, QUrl.TolerantMode)
开发者ID:Eksmo,项目名称:calibre,代码行数:20,代码来源:comments_editor.py

示例9: refresh

 def refresh(self):
     if self.current_name:
         self.refresh_timer.stop()
         # This will check if the current html has changed in its editor,
         # and re-parse it if so
         parse_worker.add_request(self.current_name)
         # Tell webkit to reload all html and associated resources
         current_url = QUrl.fromLocalFile(current_container().name_to_abspath(self.current_name))
         if current_url != self.view.url():
             # The container was changed
             self.view.setUrl(current_url)
         else:
             self.view.refresh()
开发者ID:Kielek,项目名称:calibre,代码行数:13,代码来源:preview.py

示例10: 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:089git,项目名称:calibre,代码行数:13,代码来源:main.py

示例11: drag_data

 def drag_data(self):
     m = self.model()
     rows = self.selectionModel().selectedRows()
     paths = [force_unicode(p, enc=filesystem_encoding) for p in m.paths(rows) if p]
     md = QMimeData()
     md.setData("application/calibre+from_device", "dummy")
     md.setUrls([QUrl.fromLocalFile(p) for p in paths])
     drag = QDrag(self)
     drag.setMimeData(md)
     cover = self.drag_icon(m.cover(self.currentIndex().row()), len(paths) > 1)
     drag.setHotSpot(QPoint(-15, -15))
     drag.setPixmap(cover)
     return drag
开发者ID:john-peterson,项目名称:calibre,代码行数:13,代码来源:views.py

示例12: url_for_id

 def url_for_id(i):
     try:
         ans = db.format_path(i, fmt, index_is_id=True)
     except:
         ans = None
     if ans is None:
         fmts = db.formats(i, index_is_id=True)
         if fmts:
             fmts = fmts.split(',')
         else:
             fmts = []
         for f in fmts:
             try:
                 ans = db.format_path(i, f, index_is_id=True)
             except:
                 ans = None
     if ans is None:
         ans = db.abspath(i, index_is_id=True)
     return QUrl.fromLocalFile(ans)
开发者ID:shamray,项目名称:calibre,代码行数:19,代码来源:alternate_views.py

示例13: share

 def share(self):
     index = self.available_profiles.currentIndex()
     title, src = self._model.title(index), self._model.script(index)
     if not title or not src:
         error_dialog(self, _("No recipe selected"), _("No recipe selected")).exec_()
         return
     pt = PersistentTemporaryFile(suffix=".recipe")
     pt.write(src.encode("utf-8"))
     pt.close()
     body = _("The attached file: %(fname)s is a " "recipe to download %(title)s.") % dict(
         fname=os.path.basename(pt.name), title=title
     )
     subject = _("Recipe for ") + title
     url = QUrl("mailto:")
     url.addQueryItem("subject", subject)
     url.addQueryItem("body", body)
     url.addQueryItem("attachment", pt.name)
     open_url(url)
开发者ID:Eksmo,项目名称:calibre,代码行数:18,代码来源:user_profiles.py

示例14: share

 def share(self):
     index = self.available_profiles.currentIndex()
     title, src = self._model.title(index), self._model.script(index)
     if not title or not src:
         error_dialog(self, _('No recipe selected'), _('No recipe selected')).exec_()
         return
     pt = PersistentTemporaryFile(suffix='.recipe')
     pt.write(src.encode('utf-8'))
     pt.close()
     body = _('The attached file: %(fname)s is a '
             'recipe to download %(title)s.')%dict(
                 fname=os.path.basename(pt.name), title=title)
     subject = _('Recipe for ')+title
     url = QUrl('mailto:')
     url.addQueryItem('subject', subject)
     url.addQueryItem('body', body)
     url.addQueryItem('attachment', pt.name)
     open_url(url)
开发者ID:Hainish,项目名称:calibre,代码行数:18,代码来源:user_profiles.py

示例15: search_online

 def search_online(self):
     t = unicode(self.selectedText()).strip()
     if t:
         url = 'https://www.google.com/search?q=' + QUrl().toPercentEncoding(t)
         open_url(QUrl.fromEncoded(url))
开发者ID:alfaniel,项目名称:calibre,代码行数:5,代码来源:documentview.py


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