def _loadPage(self): html_path = self._get_page_path() # QEventLoop is used to make the page loading behave syncronously init_loop = QEventLoop() self._page.loadFinished.connect(init_loop.quit) self._page.load(QUrl().fromLocalFile(html_path)) init_loop.exec_()
def go_to(self, url_or_text): """Go to page utl.""" if is_text_string(url_or_text): url = QUrl(url_or_text) else: url = url_or_text self.notebookwidget.load(url)
def escape(self): echart_unsupported_city = [ "菏泽市", "襄阳市", "恩施州", "湘西州","阿坝州", "延边州", "甘孜州", "凉山州", "黔西南州", "黔东南州", "黔南州", "普洱市", "楚雄州", "红河州", "文山州", "西双版纳州", "大理州", "德宏州", "怒江州", "迪庆州", "昌都市", "山南市", "林芝市", "临夏州", "甘南州", "海北州", "黄南州", "海南州", "果洛州", "玉树州", "海西州", "昌吉州", "博州", "克州", "伊犁哈萨克州"] data = [] for index, row in df_aqi.iterrows(): city = row['city'] aqi = row['aqi'] if city=='长沙市': print(city) localAQI=aqi if city in echart_unsupported_city: continue for index, row in df_aqi.iterrows(): city = row['city'] aqi = row['aqi'] if city in echart_unsupported_city: continue if aqi < localAQI and aqi<20 : data.append( ['长沙',city] ) global lastcity lastcity=city style = Style( title_top="#fff", title_pos = "center", title_color="#fff", width=425, height=730, background_color="#404a59" ) style_geo = style.add( is_label_show=True, line_curve=0.2,#线条曲度 line_opacity=0.6, legend_text_color="#fff",#图例文字颜色 legend_pos="right",#图例位置 geo_effect_symbol="plane",#特效形状 geo_effect_symbolsize=15,#特效大小 label_color=['#a6c84c', '#ffa022', '#46bee9'], label_pos="right", label_formatter="{b}",#//标签内容格式器 label_text_color="#fff", ) print(data) print(lastcity) geolines = GeoLines("逃离路线", **style.init_style) geolines.add("出发", data, **style_geo) geolines.render('aqi.html') self.webView.load(QUrl("file:///D:/源代码/aqi.html")) #self.webView.reload() self.webView.repaint() self.webView.update()
def startDrag(self, dropActions): """Reimplement Qt Method - handle drag event""" data = QMimeData() data.setUrls([QUrl(fname) for fname in self.get_selected_filenames()]) drag = QDrag(self) drag.setMimeData(data) drag.exec_()
def setHtml(self, html, baseUrl=QUrl()): """ Reimplement Qt method to prevent WebEngine to steal focus when setting html on the page Solution taken from https://bugreports.qt.io/browse/QTBUG-52999 """ if WEBENGINE: if OLD_PYQT: self.setEnabled(False) super(WebView, self).setHtml(html, baseUrl) if OLD_PYQT: self.setEnabled(True) else: super(WebView, self).setHtml(html, baseUrl) # This is required to catch an error with PyQt 5.9, for which # it seems this functionality is not working. # Fixes spyder-ide/spyder#16703 try: # The event filter needs to be installed every time html is set # because the proxy changes with new content. self.focusProxy().installEventFilter(self) except AttributeError: pass
def draw_city_aqi(self, time = None): #from opendatatools import aqi line = Line("长沙当日AQI", width=425, height=730) data_dict = {} city=local print("getting data for %s" % city) #df_aqi = aqi.get_daily_aqi_onecity(city) aqi_hour=pd.read_csv('daylocal.csv') #print(df_aqi) #print(aqi_hour) aqi_hour.set_index('time', inplace=True) aqi_hour.sort_index(ascending=True, inplace=True) if time is not None: aqi_hour = aqi_hour[aqi_hour.index <= time] data_dict[city] = aqi_hour axis_x = aqi_hour.index axis_y = aqi_hour['aqi'] line.add("%s" % (city), axis_x, axis_y, mark_point=["max","min"]) line.render('aqi.html') #return line self.webView.load(QUrl("file:///D:/源代码/aqi.html")) # self.webView.reload() self.webView.repaint() self.webView.update()
def download(self, url, path): """Download url and save data to path.""" # original_url = url # print(url) qurl = QUrl(url) url = to_text_string(qurl.toEncoded(), encoding='utf-8') logger.debug(str((url, path))) if url in self._workers: while not self._workers[url].finished: return self._workers[url] worker = DownloadWorker(url, path) # Check download folder exists folder = os.path.dirname(os.path.abspath(path)) if not os.path.isdir(folder): os.makedirs(folder) request = QNetworkRequest(qurl) self._head_requests[url] = request self._paths[url] = path self._workers[url] = worker self._manager.head(request) self._timer.start() return worker
def __init__(self, parent, term_url='http://127.0.0.1:8070', handler=None): """Webview main constructor.""" WebView.__init__(self, parent) self.parent = parent self.copy_action = create_action(self, _("Copy text"), icon=ima.icon('editcopy'), triggered=self.copy, shortcut='Ctrl+Shift+C') self.paste_action = create_action(self, _("Paste text"), icon=ima.icon('editpaste'), triggered=self.paste, shortcut='Ctrl+Shift+V') if WEBENGINE: self.channel = QWebChannel(self.page()) self.page().setWebChannel(self.channel) self.channel.registerObject('handler', handler) self.term_url = QUrl(term_url) self.load(self.term_url) if WEBENGINE: self.document = self.page() try: self.document.profile().clearHttpCache() except AttributeError: pass else: self.document = self.page().mainFrame() self.initial_y_pos = 0 self.setFocusPolicy(Qt.ClickFocus)
def open_url(self, url): """ Open link from action in default operating system browser. """ if url is None: return QDesktopServices.openUrl(QUrl(url))
def go_to(self, url_or_text): """Go to page *address*""" if is_text_string(url_or_text): url = QUrl(url_or_text) else: url = url_or_text self.webview.load(url)
def load_url(self, url): if isinstance(url, QUrl): qurl = url else: qurl = QUrl(url) self.load(qurl)
def go_to(self, url_or_text): """Go to page utl.""" if isinstance(url_or_text, str): url = QUrl(url_or_text) else: url = url_or_text self.notebookwidget.load(url)
def report_issue(self): if PY3: from urllib.parse import quote else: from urllib import quote # analysis:ignore issue_template = """\ ## Description - *What steps will reproduce the problem?* 1. 2. 3. - *What is the expected output? What do you see instead?* - *Please provide any additional information below* ## Version and main components - Conda Package Manager Version: {version} - Conda Version: {conda version} - Python Version: {python version} - Qt Version : {Qt version} - QtPy Version : {QtPy version} """ url = QUrl("https://github.com/spyder-ide/conda-manager/issues/new") url.addEncodedQueryItem("body", quote(issue_template)) QDesktopServices.openUrl(url)
def __init__(self, parent, term_url='http://127.0.0.1:8070'): """Webview main constructor.""" WebView.__init__(self, parent) self.parent = parent self.copy_action = create_action(self, _("Copy text"), icon=ima.icon('editcopy'), triggered=self.copy, shortcut='Ctrl+Alt+C') self.paste_action = create_action(self, _("Paste text"), icon=ima.icon('editpaste'), triggered=self.paste, shortcut='Ctrl+Alt+V') self.term_url = QUrl(term_url) self.load(self.term_url) copy_shortcut = QShortcut(QKeySequence("Ctrl+Alt+C"), self, self.copy) copy_shortcut.setContext(Qt.WidgetWithChildrenShortcut) paste_shortcut = QShortcut(QKeySequence("Ctrl+Alt+V"), self, self.paste) paste_shortcut.setContext(Qt.WidgetWithChildrenShortcut) if WEBENGINE: self.document = self.page() else: self.document = self.page().mainFrame() self.initial_y_pos = 0
def request(self, method, endpoint, data=None, headers=None): if not headers: headers = {} url = self.process_info.get('url') token = self.process_info.get('token') host = self.process_info.get('host') if host in ('127.0.0.1', 'localhost'): self.setNetworkAccessible(True) req = QNetworkRequest(QUrl('%s/%s' % (url, endpoint))) method = self.methods[str(method).lower()] # assemble headers if 'content-type' not in [x.lower() for x in headers.keys() if isinstance(x, str)]: headers['content-type'] = 'text/plain' headers['content-length'] = str(len(data if data else '')) if token: (name, value) = token.split(':') headers[name] = value for k, v in headers.items(): kb = k.encode('utf-8') # why? vb = v.encode('utf-8') req.setRawHeader(kb, vb) if data is not None: reply = method(req, data) else: reply = method(req) reply.error.connect(lambda error, reply=reply, self=self: # pylint: disable=undefined-variable self.handle_error(error, reply)) reply.finished.connect(lambda reply=reply, self=self: # pylint: disable=undefined-variable self.print_reply(reply)) return reply
def __init__(self, parent, CONF, term_url='http://127.0.0.1:8070', handler=None): """Webview main constructor.""" super().__init__(parent) web_page = QWebEnginePage(self) self.setPage(web_page) self.source_text = '' self.parent = parent self.CONF = CONF self.shortcuts = self.create_shortcuts() self.channel = QWebChannel(self.page()) self.page().setWebChannel(self.channel) self.channel.registerObject('handler', handler) self.term_url = QUrl(term_url) self.load(self.term_url) self.document = self.page() try: self.document.profile().clearHttpCache() except AttributeError: pass self.initial_y_pos = 0 self.setFocusPolicy(Qt.ClickFocus)
def connect_htp1(self): ''' Connects to the websocket of the specified ip:port. ''' self.ipAddress.setReadOnly(True) logger.info(f"Connecting to {self.ipAddress.text()}") self.__ws_client.open(QUrl(f"ws://{self.ipAddress.text()}/ws/controller"))
def load_url(self, url: str = ''): if url == '': url = self.url_input.text().strip() # print('',url) else: self.url_input.setText(url) self.webview.load(QUrl(url))
def __init__(self, parent=None, toolbar='standard'): """ :param parent: :param toolbar:多种选项:‘no’,‘standard’,'no_url_input' """ super().__init__(parent) self.webview = PMGWebEngineView() self.webview.load(QUrl("https://cn.bing.com")) self.setLayout(QVBoxLayout()) self.toolbar = QToolBar() self.url_input = QLineEdit() # self.url_input.setText('https://cn.bing.com') # self.load_url() self.toolbar.addWidget(self.url_input) self.toolbar.addAction('go').triggered.connect(lambda b: self.load_url()) self.toolbar.addAction('back').triggered.connect(self.webview.back) self.toolbar.addAction('forward').triggered.connect(self.webview.forward) self.layout().addWidget(self.toolbar) if toolbar == 'no': self.toolbar.hide() elif toolbar == 'no_url_input': self.url_input.hide() self.layout().addWidget(self.webview) self.setWindowTitle('My Browser') self.showMaximized()
def open_login_page(self): """ """ conda_url = CONF.get('main', 'conda_url') url = "{0}/{1}".format(conda_url, self.username) qurl = QUrl(url) QDesktopServices.openUrl(qurl) self.tracker.track_event('content', 'clicked', url)
def helpClicked(self): try: from pymantidplot.proxies import showCustomInterfaceHelp showCustomInterfaceHelp("Filter Events") except ImportError: url = ("http://docs.mantidproject.org/nightly/interfaces/{}.html" "".format("Filter Events")) QDesktopServices.openUrl(QUrl(url))
def mouseReleaseEvent(self, event): """Ooen anchors when clicked.""" if self.anchor: QDesktopServices.openUrl(QUrl(self.anchor)) QApplication.setOverrideCursor(Qt.ArrowCursor) self.anchor = None else: super(ControlWidget, self).mouseReleaseEvent(event)
def text_to_url(self, text): """Convert text address into QUrl object""" if text != 'about:blank': text += '.html' if text.startswith('/'): text = text[1:] return QUrl(self.home_url.toString() + text)
def __init__(self, parent=None): super(Downloader, self).__init__(parent) self.manager = QNetworkAccessManager() self.url = 'http://localhost:9998/jpg/image.jpg' self.request = QNetworkRequest() self.request.setUrl(QUrl(self.url)) self.buffer = QByteArray() self.reply = None
def handle_link_clicks(self, url): url = to_text_string(url.toString()) if url == "spy://tutorial": self.show_tutorial() elif url.startswith('http'): programs.start_file(url) else: self.rich_text.webview.load(QUrl(url))
def launch(self, uri, title): """ Emit signal with youtube video identifier string. """ qurl = QUrl(uri) QDesktopServices.openUrl(qurl) self.tracker.track_event('content', 'click', uri) self.sig_view_video.emit(uri, title)
def open_url(url): """ Open link from action in default operating system browser. ADD TRACKING!. """ if url: QDesktopServices.openUrl(QUrl(url))
def set_html_from_file(self, filename): """Set html text from a file.""" html = "" with codecs.open(filename, encoding="utf-8") as file: html = file.read() base_url = QUrl() name = osp.basename(filename) self.set_html(html, name, base_url)
def helpClicked(self): try: import mantidqt mantidqt.interfacemanager.InterfaceManager( ).showCustomInterfaceHelp("Filter Events", "utility") except ImportError: url = ("http://docs.mantidproject.org/nightly/interfaces/{}.html" "".format("Filter Events")) QDesktopServices.openUrl(QUrl(url))
def best(self): global lastcity url='https://m.baidu.com/s?from=1019146b&bd_page_type=1&word='+lastcity print(url) self.webView.load(QUrl(url)) #self.webView.reload() self.webView.repaint() self.webView.update()