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


Python QWebView.resize方法代码示例

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


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

示例1: testPlugin

# 需要导入模块: from PySide.QtWebKit import QWebView [as 别名]
# 或者: from PySide.QtWebKit.QWebView import resize [as 别名]
    def testPlugin(self):
        view = QWebView()
        fac = PluginFactory()
        view.page().setPluginFactory(fac)
        QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True)

        view.load(QUrl(os.path.join(os.path.abspath(os.path.dirname(__file__)), "qmlplugin", "index.html")))

        view.resize(840, 600)
        view.show()

        QTimer.singleShot(500, self.app.quit)

        self.app.exec_()
开发者ID:holmeschiu,项目名称:PySide,代码行数:16,代码来源:qml_plugin_test.py

示例2: main

# 需要导入模块: from PySide.QtWebKit import QWebView [as 别名]
# 或者: from PySide.QtWebKit.QWebView import resize [as 别名]
def main():

    app = QApplication([])

    view = QWebView()
    fac = PluginFactory()
    view.page().setPluginFactory(fac)
    QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True)

    view.load(QUrl(sys.argv[1]))

    view.resize(840, 600)
    view.show()

    return app.exec_()
开发者ID:AmerGit,项目名称:Examples,代码行数:17,代码来源:main.py

示例3: Browser

# 需要导入模块: from PySide.QtWebKit import QWebView [as 别名]
# 或者: from PySide.QtWebKit.QWebView import resize [as 别名]
class Browser(object):
    DEFAULT_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 " +\
                         "(KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2"

    DEFAULT_MAX_WAIT_TIME = 8

    _app = None

    @staticmethod
    def _initialize():
        if not Browser._app:
            Browser._app = QApplication.instance() or QApplication(['recap'])

    def __init__(self, dimension=(1024, 768), headless=True, user_agent = None, max_wait_time = None):
        Browser._initialize()

        self._headless = headless

        self._view = QWebView()
        self._view.setPage(RecapWebPage(user_agent if user_agent else Browser.DEFAULT_USER_AGENT))
        self._view.resize(*dimension)
        self._view.page().loadStarted.connect(self._page_loading_started)
        self._view.page().loadFinished.connect(self._page_loading_finished)

        self._manager = self._view.page().networkAccessManager()

        #        cache = QNetworkDiskCache()
        #        cache.setCacheDirectory(cache_dir)
        #        self._manager.setCache(cache)

        cookie_jar = QNetworkCookieJar()
        self._manager.setCookieJar(cookie_jar)

        self._max_wait_time = max_wait_time if max_wait_time else Browser.DEFAULT_MAX_WAIT_TIME
        self._show()

    @property
    def page(self):
        return self._view.page()

    def close(self):
        self._view.close()

    def goto(self, url):
        self.open(url)
        return WebPage(self, self.page)

    def open(self, address, method='get', headers={}):
        body = QByteArray()

        try:
            method = getattr(QNetworkAccessManager,
                "%sOperation" % method.capitalize())
        except AttributeError:
            raise Exception("Invalid http method %s" % method)

        request = QNetworkRequest(QUrl(address))
        request.CacheLoadControl(0)

        for header in headers:
            request.setRawHeader(header, headers[header])

        self._view.page().currentFrame().load(request, method, body)
        self._wait_for_page()

    def capture(self, filename):
        image = QImage(self._view.page().currentFrame().contentsSize(), QImage.Format_ARGB32)

        painter = QPainter(image)

        self._view.page().currentFrame().render(painter)
        painter.end()

        image.save(filename)

    def execute_and_wait(self, callback):
        result = callback()
        self._page_loaded = False
        self._wait_for_page()
        return result

    def _page_loading_started(self):
        self._page_loaded = False

    def _page_loading_finished(self):
        self._page_loaded = True

    def _show(self):
        if not self._headless:
            self._view.show()

    def _wait_for_page(self):
        end_time = time.time() + self._max_wait_time
        while True:
            Browser._app.processEvents()
            if self._page_loaded:
                break
            time.sleep(.01)
            if time.time() > end_time:
                raise RecapError("Waited at least %f seconds for page to load", self._max_wait_time)
#.........这里部分代码省略.........
开发者ID:halimath,项目名称:recap,代码行数:103,代码来源:browser.py


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