def initUI(self): mainLayout = QVBoxLayout() self.setLayout(mainLayout) self.webview = QWebEngineView() self.webpage = QWebEnginePage() self.webview.setPage(self.webpage) url = QUrl.fromLocalFile( resource_filename("yaogua", "html_resource/zhou_yi_yao_gua.html")) self.webview.load(url) mainLayout.addWidget(self.webview)
def __init__(self, parent=None): QDialog.__init__(self, parent=parent) self.setupUi(self) self.web_session = requests.Session() self.web_profile = QWebEngineProfile() self.web_interceptor = RequestInterceptor() self.web_interceptor.response_intercepted.connect(self.response_esia) self.web_profile.setRequestInterceptor(self.web_interceptor) self.ESIAWebView.setPage(QWebEnginePage(self.web_profile, self)) self.LoginMethodTabs.currentChanged.connect(self.on_tab_changed) self.FNSLoginBtn.clicked.connect(self.login_fns)
def main(): import sys QCoreApplication.setOrganizationName("QtExamples") QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) WebUiHandler.registerUrlScheme() app = QApplication(sys.argv) profile = QWebEngineProfile() handler = WebUiHandler() profile.installUrlSchemeHandler(WebUiHandler.schemeName, handler) page = QWebEnginePage(profile) page.load(WebUiHandler.aboutUrl) view = QWebEngineView() view.setPage(page) view.setContextMenuPolicy(Qt.NoContextMenu) view.resize(500, 600) view.show() sys.exit(app.exec_())
def reinit_code(self): reqdata = {'client_id': self.__client_id, 'scope': 'gist'} req = urllib2.Request('https://github.com/login/device/code', data=json.dumps(reqdata), headers=self.__headers) req.get_method = lambda: 'POST' code, ret = urlopen_nt(req) if code != 200: raise RuntimeError('code %d when trying to register device' % code) init_data = json.loads(ret.read()) print(init_data) self.__device_code = init_data['device_code'] self.__interval = init_data.get('interval', 5) url = init_data['verification_uri'] self.__await_login_redirect = True self.__webprofile = QWebEngineProfile(parent=self.__webview) self.__webpage = QWebEnginePage(self.__webprofile, parent=self.__webview) # just to be sure they are deleted in proper order self.__webview.setPage(self.__webpage) self.__webview.load(QUrl(url)) self.__devidlabel.setText('code: %s' % (init_data['user_code'],))
def __init__(self, url, width, height, *args, **kwargs): self.display = Xvfb(int(width * 1.2), int(height * 1.2)) self.display.start() super().__init__(*args, **kwargs) self.engine = QWebEngineView() size = QSize(width, height) self.engine.setFixedSize(size) self.engine.setPage(QWebEnginePage()) settings = self.engine.page().settings() settings.setAttribute(QWebEngineSettings.ShowScrollBars, False) settings.setAttribute(QWebEngineSettings.JavascriptCanOpenWindows, False) settings.setAttribute(QWebEngineSettings.LocalStorageEnabled, False) settings.setAttribute(QWebEngineSettings.HyperlinkAuditingEnabled, False) settings.setAttribute(QWebEngineSettings.PluginsEnabled, False) settings.setAttribute(QWebEngineSettings.FullScreenSupportEnabled, False) settings.setAttribute(QWebEngineSettings.ScreenCaptureEnabled, False) self.engine.loadFinished.connect(self.load_finished) self.engine.load(QUrl(url)) self.engine.show()
def acceptNavigationRequest(self, url, _type, isMainFrame): print("acceptNavigationRequest") print(url) return QWebEnginePage.acceptNavigationRequest(self, url, _type, isMainFrame)
def __init__(self): QWebEnginePage.__init__(self)
def __init__(self, *args, **kwargs): #print('in MyQWebEnginePage') QWebEnginePage.__init__(self, *args, **kwargs) self.webglsupport = None
class GISOSM_Dialog(QtWidgets.QDialog): def __init__(self, parent=None): super(GISOSM_Dialog, self).__init__(parent) self.sitename = "GIS-Sitedata" #Get/set parameters for GIS self.tempFolderName = "GIStemp/" self.lat = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck(self.sitename).WGS84_Latitude) self.lon = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck(self.sitename).WGS84_Longitude) self.bboxWidthStart = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck( self.sitename).BoundingboxWidth) self.bboxHeightStart = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck( self.sitename).BoundingboxHeight) #Set Style self.setStyleSheet( "QWidget {background-color: rgb(68, 68, 68)} QPushButton { background-color: black } QGroupBox {border: 1px solid grey; }" ) #margin: 2px; #Download files self.URLmap = GIS2BIM.GetWebServerData("HTMLwfs", "Other", "URL") #self.filepathBaseMap = GIS2BIM.DownloadURL(GIS2BIM_FreeCAD.CreateTempFolder(self.tempFolderName),self.URLmap,"basemapWFS.html") #Basemap from GIS2BIM Repository for preview #self.filepathNewMap = GIS2BIM.DownloadURL(GIS2BIM_FreeCAD.CreateTempFolder(self.tempFolderName),self.URLmap,"mapWFS.html") #Edited Basemap with location and bbox self.filepathBaseMap = "C:/Users/mikev/OneDrive/Bureaublad/TEMP/GIStemp/basemapWFS.html" self.filepathNewMap = "C:/Users/mikev/OneDrive/Bureaublad/TEMP/GIStemp/mapWFS.html" self.tempFolderPath = GIS2BIM_FreeCAD.CreateTempFolder( self.tempFolderName) os.remove(self.filepathNewMap) BaseMap = open(self.filepathBaseMap, "r") BaseMapstr = BaseMap.read() Newstr = BaseMapstr.replace("51LAT", str(self.lat)) Newstr = Newstr.replace("4LONG", str(self.lon)) Newstr = Newstr.replace("WBBOX", self.bboxWidthStart) Newstr = Newstr.replace("HBBOX", self.bboxHeightStart) open(self.filepathNewMap, "x") f1 = open(self.filepathNewMap, "w") f1.write(Newstr) f1.close() #Overall Grid grid = QtWidgets.QGridLayout() grid.addWidget(self.webViewGroup(), 0, 0, 1, 2) grid.addWidget(self.locationGroup(), 3, 0, QtCore.Qt.AlignTop) grid.addLayout(self.buttonGroup(), 4, 0, 1, 2) grid.setRowStretch(0, 2) self.setLayout(grid) self.setWindowTitle("Load 2D Vector Data with WFS(Web Feature Server)") self.resize(920, 910) def webViewGroup(self): groupBox = QtWidgets.QGroupBox("Map") groupBox.setStyleSheet("QGroupBox {border: 1px solid grey;}") radio1 = QtWidgets.QRadioButton("&Radio button 1") radio1.setChecked(True) webFrame = QFrame() webFrame.setFrameShape(QFrame.StyledPanel) vbox = QtWidgets.QVBoxLayout() groupBox.setLayout(vbox) self.webView = QWebEngineView() self.webPage = QWebEnginePage() self.webPage.load(QUrl(QtCore.QUrl(self.filepathNewMap))) self.webView.setObjectName("webView") self.webView.setPage(self.webPage) self.webView.show() vbox.addWidget(self.webView) return groupBox def locationGroup(self): groupBox = QtWidgets.QGroupBox("Location / Boundingbox") latLonLab = QtWidgets.QLabel("lat/lon (WGS-84)") latLon = QtWidgets.QLabel("lat: " + self.lat + ", lon: " + self.lon) bboxWidthLab = QtWidgets.QLabel("Boundingbox Width [m]") self.bboxWidth = QtWidgets.QLineEdit() self.bboxWidth.setText(self.bboxWidthStart) self.bboxWidth.editingFinished.connect(self.onbboxWidth) bboxHeightLab = QtWidgets.QLabel("Boundingbox Height [m]") self.bboxHeight = QtWidgets.QLineEdit() self.bboxHeight.setText(self.bboxHeightStart) self.bboxHeight.editingFinished.connect(self.onbboxHeight) grid = QtWidgets.QGridLayout() grid.addWidget(latLonLab, 0, 0) grid.addWidget(latLon, 0, 1) grid.addWidget(CRSLab, 1, 0) grid.addWidget(CRSText, 1, 1) grid.addWidget(bboxWidthLab, 2, 0) grid.addWidget(self.bboxWidth, 2, 1) grid.addWidget(bboxHeightLab, 3, 0) grid.addWidget(self.bboxHeight, 3, 1) groupBox.setLayout(grid) groupBox.setStyleSheet("QGroupBox {border: 1px solid grey;}") return groupBox def buttonGroup(self): importbtn = QtWidgets.QPushButton("Import") importbtn.clicked.connect(self.onImport) cancelbtn = QtWidgets.QPushButton("Cancel") cancelbtn.clicked.connect(self.onCancel) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(importbtn) hbox.addWidget(cancelbtn) return hbox def onbboxWidth(self): JS2 = open(self.filepathJSUpdate, "r") JS2 = JS2.read() JS2 = JS2.replace("WBBOX", self.bboxWidth.text()) JS2 = JS2.replace("HBBOX", self.bboxHeight.text()) self.webPage.runJavaScript(JS2) # update bboxWidth in mapview self.testWFS() def onbboxHeight(self): JS3 = open(self.filepathJSUpdate, "r") JS3 = JS3.read() JS3 = JS3.replace("WBBOX", self.bboxWidth.text()) JS3 = JS3.replace("HBBOX", self.bboxHeight.text()) self.webPage.runJavaScript(JS3) # update bboxHeight in mapview self.testWFS() def onImport(self): self.bboxString = GIS2BIM.CreateBoundingBox( float(GIS2BIM_FreeCAD.ArchSiteCreateCheck(self.sitename).CRS_x), float(GIS2BIM_FreeCAD.ArchSiteCreateCheck(self.sitename).CRS_y), float(self.bboxWidth.text()), float(self.bboxHeight.text()), 2) url = self.request.text() xpathstr = self.xPathStr.text() closedValue = self.clsPolygon.isChecked() makeFaceValue = self.clsCreateFace.isChecked() drawStyle = str(self.linePattern.currentText()) Curves = GIS2BIM_FreeCAD.CurvesFromWFS(url, self.bboxString, xpathstr, -float(self.X), -float(self.Y), 1000, 3, closedValue, makeFaceValue, drawStyle, (0.7, 0.0, 0.0)) GIS2BIM_FreeCAD.CreateLayer(self.groupName.text()) FreeCAD.activeDocument().getObject( self.groupName.text()).addObjects(Curves) FreeCAD.ActiveDocument.recompute() self.close() def onCancel(self): self.close()
class GraphWidget(QWidget): def __init__(self, log_console): logger.debug(locals()) QWidget.__init__(self) log_console.add_loggers(logger) self.graph = None self.webview = QWebEngineView(parent=self) self.index = QWebEnginePage(self) worklayout = QHBoxLayout(parent=self) worklayout.addWidget(self.webview) self.setLayout(worklayout) def draw_index(self): if not self.graph: logger.warning("No graph to draw found!") width = self.contentsRect().width() height = self.contentsRect().height() pagewidth = int(width) - 10 pageheight = int(height) - 10 logger.info(f"{width}x{height}") html = importlib.resources.read_text(__package__, "index.thtml", encoding="utf-8-sig") html = (html.replace( "$graph", "'" + json.dumps(networkx.node_link_data(self.graph)) + "'" if self.graph else """'{"directed":true,"multigraph":true,"graph":[],"nodes":[],"links":[]}'""", ).replace("$width", str(pagewidth)).replace("$height", str(pageheight))) path = pathlib.Path( QStandardPaths.writableLocation( QStandardPaths.AppLocalDataLocation)) / "index.html" logger.info(f"""Saving html to {path.absolute()}""") path.write_text(html) self.index.setHtml(html) self.index.settings().setAttribute(QWebEngineSettings.ShowScrollBars, False) self.webview.setPage(self.index) self.webview.resize(width, height) self.webview.show() self.update() @Slot() def draw_graph(self): logger.debug(locals()) self.draw_index() @Slot() def get_open_file_extensions(self): logger.debug(locals()) return ";;".join([ "Node Link Graph (*.json)", "Adjacency Graph (*.json)", "GraphML (.graphml)", "LEDA (*.gw, *.lgr, *.leda)", "Pajek (*.net)", ]) @Slot() def get_save_file_extensions(self): logger.debug(locals()) return ";;".join( ["Node Link Graph (*.json)", "Adjacency Graph (*.json)"]) @Slot(str, str) def open_file(self, path: str, file_type: str): logger.debug(locals()) if "json" in file_type.lower(): if "node link graph" in file_type.lower(): self.graph = networkx.node_link_graph( json.loads(pathlib.Path(path).read_text())) elif "adjacency graph" in file_type.lower(): self.graph = networkx.adjacency_graph( json.loads(pathlib.Path(path).read_text())) else: raise NotImplementedError() elif "graphml" in file_type.lower(): self.graph = networkx.read_graphml(path) elif "leda" in file_type.lower(): self.graph = networkx.read_leda(path) elif "pajek" in file_type.lower(): self.graph = networkx.read_pajek(path) else: raise NotImplementedError() @Slot(str, str) def save_file(self, path: str, file_type: str): logger.debug(locals()) if not self.graph: raise ValueError("No graph to save!") if "json" in file_type.lower(): if "node link graph" in file_type.lower(): with pathlib.Path(path).open("w") as file_p: data = networkx.node_link_data(self.graph) json.dump(data, file_p) del data elif "adjacency graph" in file_type.lower(): with pathlib.Path(path).open("w") as file_p: data = networkx.adjacency_data(self.graph) json.dump(data, file_p) del data else: raise NotImplementedError() else: raise NotImplementedError()
def __init__(self, parent=None): QWebEnginePage.__init__(self, parent)