我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用PySide.QtCore.QUrl()。
def loadPage(self, web_page): try: if os.environ.get('DEBUG'): self.settings().setAttribute( QWebSettings.DeveloperExtrasEnabled, True) except Exception: pass if os.environ.get('DEBUG'): self.inspector = QWebInspector(self) self.inspector.setPage(self.page()) self.inspector.show() if os.path.isabs(web_page): web_page = os.path.relpath(web_page) url = QtCore.QUrl(web_page) # TODO -- port this to QWebEngine self.frame = self.page().mainFrame() self.frame.addToJavaScriptWindowObject( "bitmaskBrowser", self.bitmask_browser) self.load(url)
def open(self, url, timeout=60): """Wait for download to complete and return result""" loop = QEventLoop() timer = QTimer() timer.setSingleShot(True) timer.timeout.connect(loop.quit) self.loadFinished.connect(loop.quit) self.load(QUrl(url)) timer.start(timeout * 1000) loop.exec_() # delay here until download finished if timer.isActive(): # downloaded successfully timer.stop() return self.html() else: # timed out print 'Request timed out:', url
def main(): app = QApplication([]) webview = QWebView() loop = QEventLoop() webview.loadFinished.connect(loop.quit) webview.load(QUrl('http://example.webscraping.com/search')) loop.exec_() webview.show() frame = webview.page().mainFrame() frame.findFirstElement('#search_term').setAttribute('value', '.') frame.findFirstElement('#page_size option:checked').setPlainText('1000') frame.findFirstElement('#search').evaluateJavaScript('this.click()') elements = None while not elements: app.processEvents() elements = frame.findAllElements('#results a') countries = [e.toPlainText().strip() for e in elements] print countries
def __init__(self, url): QtWebKit.QWebView.__init__(self) self.setMaximumSize(1930,210) self.setMinimumSize(1930,210) self.SmallMultipleLayout = None self.js = None self.setContentsMargins(0, 0, 0, 0) self.load(QtCore.QUrl(url)) self.setContentsMargins(0, 0, 0, 0) self.signalConnection() self.url = url frame = self.page().mainFrame() frame.setScrollBarPolicy(QtCore.Qt.Vertical , QtCore.Qt.ScrollBarAlwaysOn) frame.setScrollBarPolicy(QtCore.Qt.Horizontal , QtCore.Qt.ScrollBarAlwaysOff)
def version_check_done(self, version): self.version_thread.quit() if version and __version__ != version: version_box = QtGui.QMessageBox(self) version_box.setWindowTitle("New version available!") version_box.setText( "You have version '{}', but there's a new version available: '{}'.".format(__version__, version) ) version_box.addButton("Download now", QtGui.QMessageBox.AcceptRole) version_box.addButton("Remind me later", QtGui.QMessageBox.RejectRole) ret = version_box.exec_() if ret == QtGui.QMessageBox.AcceptRole: QtGui.QDesktopServices.openUrl( QtCore.QUrl("https://github.com/farshield/shortcircuit/releases/tag/{}".format(version)) ) # event: QCloseEvent
def open_log_file(self): assert self.last_log_file is not None QDesktopServices.openUrl(QUrl(self.last_log_file))
def show_about(self): msg = QMessageBox() msg.setIcon(QMessageBox.Question) msg.setText("SpyKING CIRCUS v%s" %circus.__version__) msg.setWindowTitle("About") msg.setInformativeText("Documentation can be found at\n" "http://spyking-circus.rtfd.org\n" "\n" "Open a browser to see the online help?" ) msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No) msg.setDefaultButton(QMessageBox.No) answer = msg.exec_() if answer == QMessageBox.Yes: QDesktopServices.openUrl(QUrl("http://spyking-circus.rtfd.org"))
def open_plot_folder(self): f_next, _ = os.path.splitext(str(self.ui.edit_file.text())) plot_folder = os.path.join(f_next, 'plots') QDesktopServices.openUrl(QUrl(plot_folder))
def help_phy(self): QDesktopServices.openUrl(QUrl("https://github.com/kwikteam/phy-contrib"))
def help_matlab(self): QDesktopServices.openUrl(QUrl("http://ch.mathworks.com/products/matlab/"))
def _jump_to_sg(self): """ Jump to shotgun, launch web browser """ from sgtk.platform.qt import QtGui, QtCore url = self.context.shotgun_url QtGui.QDesktopServices.openUrl(QtCore.QUrl(url))
def loadDatasheet(self): ''' load datasheet of selected package ''' url = str(self.datasheetPath.text()).strip() if len(url): if url.startswith("http://") or url.startswith("https://") or url.startswith("www."): QtGui.QDesktopServices().openUrl(QtCore.QUrl(url)) else: QtGui.QDesktopServices().openUrl(QtCore.QUrl("file:///{0}".format(url), QtCore.QUrl.TolerantMode))
def reload(self): self.load(QtCore.QUrl(self.url))
def logo_double_click(event): event.accept() QtGui.QDesktopServices.openUrl(QtCore.QUrl("https://www.eve-scout.com/"))
def icon_double_click(event): event.accept() QtGui.QDesktopServices.openUrl(QtCore.QUrl("https://github.com/farshield/shortcircuit"))
def btn_eve_login_clicked(self): if not self.eve_connected: url = self.crestp.login() QtGui.QDesktopServices.openUrl(QtCore.QUrl.fromEncoded(url)) else: self.crestp.logout()
def load(self, url, method = "get", headers = {}, post_data = ""): request = QtNetwork.QNetworkRequest(QtCore.QUrl(url)) request.CacheLoadControl(0) for header in headers: if header != "Accept-Encoding": request.setRawHeader(QtCore.QByteArray(header), QtCore.QByteArray(headers[header])) method = getattr(QtNetwork.QNetworkAccessManager, "%sOperation"%method.capitalize()) self.frame.load(request, method, QtCore.QByteArray(post_data)) self.isLoaded = False self._wait()
def run(self): self.view.loadFinished.connect(self.load_finished) # self.view.load(qt_core.QUrl(self.url)) self.view.setHtml(self.html, qt_core.QUrl(self.url))
def run(self): self.view.loadFinished.connect(self.load_finished) # self.view.load(qt_core.QUrl(self.url)) self.view.setHtml(self.html, qt_core.QUrl(self.url)) self.start_deamon() self.daemon_rpc_request = DaemonRPCRequest(self.app) self.timer = QTimer(self) self.timer.timeout.connect(self._update_daemon_status) self.timer.start(10000) QTimer.singleShot(1000, self._load_wallet) QTimer.singleShot(2000, self._update_daemon_status)
def readFile(): #Should be swapped with a read of a template class JavaScriptObjectToSend(QtCore.QObject): """Simple class with one slot and one read-only property.""" @QtCore.Slot(str) def showMessage(self, msg): """Open a message box and display the specified message.""" QtGui.QMessageBox.information(None, "Info", msg) def _pyVersion(self): """Return the Python version.""" return sys.version """Python interpreter version property.""" pyVersion = Property(str, fget=_pyVersion) class jsonObject(QObject): def __init__(self,startval=42): QObject.__init__(self) self.ppval="source" self.pp = Property(str,self.readPP,self.setPP) @QtCore.Slot(str) def readPP(self,msg): return msg,self.ppval @QtCore.Slot(str) def setPP(self,val): self.ppval = val obj = jsonObject() basepath = os.path.dirname(os.path.abspath(__file__)) basepath = str(basepath)+'/' win = QtWebKit.QWebView() win.setWindowTitle('D3d visualization') layout = QtGui.QVBoxLayout() win.setLayout(layout) myObj = JavaScriptObjectToSend() view = QtWebKit.QWebView() view.settings().setAttribute(QtWebKit.QWebSettings.LocalContentCanAccessRemoteUrls, True) view.page().mainFrame().addToJavaScriptWindowObject("pyObj", myObj) view.page().mainFrame().addToJavaScriptWindowObject("jsonObj", obj) view.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled, True) view.settings().setAttribute(QtWebKit.QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) view.settings().setAttribute(QtWebKit.QWebSettings.PrivateBrowsingEnabled, True) view.setHtml(html, baseUrl=QtCore.QUrl().fromLocalFile(basepath)) return view
def download_file(self, path, setting): version_file = self.settings['base_url'].format(self.selected_version()) location = self.get_setting('download_dir').value versions = re.findall('v(\d+)\.(\d+)\.(\d+)', path)[0] self.progress_text = u'Downloading {}'.format(path.replace(version_file, '')) path = self.get_redirected_url(path) url = QUrl(path) file_name = setting.save_file_path(self.selected_version(), location) archive_exists = QFile.exists(file_name) forced = self.get_setting('force_download').value if archive_exists and not forced: self.continue_downloading_or_extract() return self.out_file = QFile(file_name) if not self.out_file.open(QIODevice.WriteOnly): error = self.out_file.error().name self.show_error(u'Unable to save the file {}: {}.'.format(file_name, error)) self.out_file = None self.enable_ui() return mode = QHttp.ConnectionModeHttps port = url.port() if port == -1: port = 0 self.http.setHost(url.host(), mode, port) self.http_request_aborted = False # Download the file. self.http_get_id = self.http.get(path, to=self.out_file)