def handle_args(args: List[str]) -> str: """ Handles the given arguments, determining the starting dir. :param args: List of arguments given to the application. :type args: List[str] :return: The directory to start the application with. :rtype: str """ if len(args) > 1: if os.path.isdir(args[1]): return os.path.abspath(args[1]) if QUrl(args[1]).isValid() and os.path.isdir(QUrl(args[1]).path()): return os.path.abspath(QUrl(args[1]).path()) return QDir.homePath()
async def installFromURL( self, path: Union[str, QUrl], local: bool = True, web: bool = True, installtime: Optional[datetime] = None) -> Tuple[int, int]: installed = 0 errors = 0 if not installtime: installtime = datetime.now(tz=timezone.utc) if isinstance(path, QUrl): path = path.toString() if web and isValidModDownloadUrl(path): self.setDisabled(True) logger.bind(dots=True, path=path).info(f'Installing mods from') i, e = await self.installFromFileDownload(path, installtime) installed += i errors += e elif local and isValidFileUrl(path): self.setDisabled(True) path = QUrl(path) logger.bind(dots=True, path=Path( path.toLocalFile())).info(f'Installing mods from') i, e = await self.installFromFile(Path(path.toLocalFile()), installtime) installed += i errors += e else: logger.bind(path=path).error('Could not install mods from') return installed, errors
def eventFilter(self, source: QLineEdit, event: Union[QDropEvent, QMouseEvent, QDragEnterEvent]): if event.type() == QEvent.DragEnter: event.accept() elif event.type() == QEvent.Drop: # 任何拖放事件 都先清空原来的内容 source.clear() md = event.mimeData() # type: QMimeData if md.hasUrls() and len(md.urls()) == 1: path = md.urls()[0].toLocalFile() if os.path.exists(path): source.setText(path) self.update_name.emit(path) return True elif event.type() == QEvent.MouseButtonDblClick: # 选择本地headers.json文件 fileName, selectedFilter = QFileDialog.getOpenFileUrl( None, caption="select headers.json", dir=QUrl("file://.")) if isinstance(fileName, QUrl): path = fileName.toLocalFile() if os.path.exists(path): source.clear() source.setText(path) self.update_name.emit(path) return True return super(HeaderFileQLineEdit, self).eventFilter(source, event)
def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle('PySide6 WebEngineWidgets Example') self.toolBar = QToolBar() self.addToolBar(self.toolBar) self.backButton = QPushButton() self.backButton.setIcon(QIcon(':/qt-project.org/styles/commonstyle/images/left-32.png')) self.backButton.clicked.connect(self.back) self.toolBar.addWidget(self.backButton) self.forwardButton = QPushButton() self.forwardButton.setIcon(QIcon(':/qt-project.org/styles/commonstyle/images/right-32.png')) self.forwardButton.clicked.connect(self.forward) self.toolBar.addWidget(self.forwardButton) self.addressLineEdit = QLineEdit() self.addressLineEdit.returnPressed.connect(self.load) self.toolBar.addWidget(self.addressLineEdit) self.webEngineView = QWebEngineView() self.setCentralWidget(self.webEngineView) initialUrl = 'http://qt.io' self.addressLineEdit.setText(initialUrl) self.webEngineView.load(QUrl(initialUrl)) self.webEngineView.page().titleChanged.connect(self.setWindowTitle) self.webEngineView.page().urlChanged.connect(self.urlChanged)
def __init__(self, *args, **kwargs): super(Help, self).__init__(*args, **kwargs) self.browser = QWebEngineView() self.browser.setUrl(QUrl("https://piscat.readthedocs.io/")) self.setCentralWidget(self.browser) self.show()
def main(): app = QApplication([]) QtWebEngine.initialize() engine = QQmlApplicationEngine() qml_file_path = os.path.join(os.path.dirname(__file__), 'browser.qml') qml_url = QUrl.fromLocalFile(os.path.abspath(qml_file_path)) engine.load(qml_url) app.exec_()
def set_texture(self, img_path: Path) -> None: # This is from https://stackoverflow.com/q/49887994/2826337 # and from https://forum.qt.io/topic/106370/qdiffusespecularmaterial-diffuse-texture/4 # noqa: E501 loader = Qt3DRender.QTextureLoader(self.entity) local_pathname = os.fspath(img_path.resolve()) img_url = QUrl.fromLocalFile(local_pathname) loader.setSource(img_url) self.material.setDiffuse(loader)
def login_esia(self): response = self.web_session.get( 'https://irkkt-mobile.nalog.ru:8888/v2/mobile/users/esia/auth/url') if response.status_code != 200: logging.error( self.tr("Get ESIA URL failed: ") + f"{response}/{response.text}") return json_content = json.loads(response.text) auth_url = json_content['url'] self.ESIAWebView.load(QUrl(auth_url))
def _create_model(parent, serialized_bookmarks): result = QStandardItemModel(0, 1, parent) last_folder_item = None for entry in serialized_bookmarks: if len(entry) == 1: last_folder_item = _create_folder_item(entry[0]) result.appendRow(last_folder_item) else: url = QUrl.fromUserInput(entry[0]) title = entry[1] icon = QIcon(entry[2]) if len(entry) > 2 and entry[2] else None last_folder_item.appendRow(_create_item(url, title, icon)) return result
def create_ngl_widget(engine): # Dynamically create an instance of the rendering widget widget_url = QUrl.fromLocalFile(op.join(op.dirname(__file__), "NodeGLWidget.qml")) component = QQmlComponent(engine) component.loadUrl(widget_url) widget = component.create() # Inject it live into its placeholder app_window = engine.rootObjects()[0] placeholder = app_window.findChild(QObject, "ngl_widget_placeholder") widget.setParentItem(placeholder) return widget
def eventFilter(self, source: QLineEdit, event: Union[QDropEvent, QMouseEvent, QDragEnterEvent]): if event.type() == QEvent.DragEnter: event.accept() elif event.type() == QEvent.Drop: # 任何拖放事件 都先清空原来的内容 source.clear() md = event.mimeData() # type: QMimeData if md.hasUrls() and len(md.urls()) == 1: path = md.urls()[0].toLocalFile() if os.path.exists(path): source.setText(path) self.update_name.emit(path) return True elif event.type() == QEvent.MouseButtonDblClick: # 获取剪切板内容 看看有没有链接或者是文件 clipboard = QApplication.clipboard() md = clipboard.mimeData() if md.hasUrls() and len(md.urls()) == 1: # 比如复制了文件 这里就可以获取到文件的路径 但超链接并不会在这里 path = md.urls()[0].toLocalFile() if os.path.exists(path): source.clear() source.setText(path) self.update_name.emit(path) elif md.hasText(): # 检查是不是http(s)://开头的链接 text = md.text() if re.match(r'^https?://', text): source.clear() source.setText(text) self.update_name.emit(text) else: # 否则尝试选择本地元数据文件 fileName, selectedFilter = QFileDialog.getOpenFileUrl( None, caption="选择元数据文件", dir=QUrl("file://.")) if isinstance(fileName, QUrl): path = fileName.toLocalFile() if os.path.exists(path): source.clear() source.setText(path) self.update_name.emit(path) return True return super(URIQLineEdit, self).eventFilter(source, event)
def get_MIME(files_as_indexes: List[QModelIndex]) -> Tuple[List[str], List[QUrl]]: """ Converts the given files to their MIME data. :param files_as_indexes: List of indexes of files. :type files_as_indexes: List[QModelIndex] :return: files as str list of path and the MIME data of the given files. :rtype: Tuple[List[str], List[QUrl]] """ files_as_path = indexes_to_paths(files_as_indexes) file_urls = [] for file in files_as_path: file_urls.append(QUrl.fromLocalFile(file)) mime_data = QMimeData() mime_data.setUrls(file_urls) return files_as_path, mime_data
def start_request(self, ): token = 'c2FuY2hvcjpNVFF6TkRFME5UZ3lOVUJ4Y1M1amIyMD06MTYzNjk4MjAyNTowNjljMz' \ 'FlZjM4MDhlZjQ2YWFiYzA1NzUwMTYzMDY1ZTQyMWZkYTli' url = QUrl( 'https://ladsweb.modaps.eosdis.nasa.gov/archive/orders/501675589.json' ) self.http_request_aborted = False req = QNetworkRequest(url) req.setRawHeader(QByteArray('Authorization'), QByteArray('Bearer ' + token)) self.reply = self.qnam.get(req) self.reply.finished.connect(self.http_finished) progress = progress_dialog(url) progress.setAttribute(Qt.WA_DeleteOnClose) progress.canceled.connect(self.cancel_download) self.reply.downloadProgress.connect(progress.network_reply_progress) self.reply.finished.connect(progress.hide) progress.exec()
def showContextMenu(self, pos: QPoint) -> None: mods = self.getSelectedMods() if not mods: return menu = QMenu(self) actionOpen = menu.addAction('&Open Directory') actionOpen.setIcon( QIcon(str(getRuntimePath('resources/icons/open-folder.ico')))) actionOpen.triggered.connect(lambda: [ util.openDirectory(self.modmodel.getModPath(mod)) # type: ignore for mod in mods ]) menu.addSeparator() actionEnable = menu.addAction('&Enable') actionEnable.triggered.connect( lambda: [asyncio.create_task(self.enableSelectedMods(True))]) actionEnable.setEnabled(not all(mod.enabled for mod in mods)) actionDisable = menu.addAction('&Disable') actionDisable.triggered.connect( lambda: [asyncio.create_task(self.enableSelectedMods(False))]) actionDisable.setEnabled(not all(not mod.enabled for mod in mods)) menu.addSeparator() actionUninstall = menu.addAction('&Uninstall') actionUninstall.triggered.connect( lambda: [asyncio.create_task(self.deleteSelectedMods())]) menu.addSeparator() actionOpenNexus = menu.addAction('Open &Nexus Mods page') actionOpenNexus.setIcon( QIcon(str(getRuntimePath('resources/icons/browse.ico')))) actionOpenNexus.triggered.connect(lambda: [ QDesktopServices.openUrl( QUrl(f'https://www.nexusmods.com/witcher3/mods/{modid}')) for modid in {mod.modid for mod in mods if mod.modid > 0} ]) actionOpenNexus.setEnabled(not all(mod.modid <= 0 for mod in mods)) menu.popup(self.viewport().mapToGlobal(pos))
server = QWebSocketServer("QWebChannel Standalone Example Server", QWebSocketServer.NonSecureMode) if not server.listen(QHostAddress.LocalHost, 12345): print("Failed to open web socket server.") sys.exit(-1) # wrap WebSocket clients in QWebChannelAbstractTransport objects clientWrapper = WebSocketClientWrapper(server) # setup the channel channel = QWebChannel() clientWrapper.clientConnected.connect(channel.connectTo) # setup the UI dialog = Dialog() # setup the core and publish it to the QWebChannel core = Core(dialog) channel.registerObject("core", core) # open a browser window with the client HTML page url = QUrl.fromLocalFile(cur_dir + "/index.html") QDesktopServices.openUrl(url) message = "Initialization complete, opening browser at {}.".format( url.toDisplayString()) dialog.displayMessage(message) dialog.show() sys.exit(app.exec_())
def setupUi(self, LoginFNSDialog): if not LoginFNSDialog.objectName(): LoginFNSDialog.setObjectName(u"LoginFNSDialog") LoginFNSDialog.resize(400, 500) self.verticalLayout_3 = QVBoxLayout(LoginFNSDialog) self.verticalLayout_3.setSpacing(6) self.verticalLayout_3.setObjectName(u"verticalLayout_3") self.verticalLayout_3.setContentsMargins(2, 2, 2, 2) self.LoginMethodTabs = QTabWidget(LoginFNSDialog) self.LoginMethodTabs.setObjectName(u"LoginMethodTabs") self.LoginSMSTab = QWidget() self.LoginSMSTab.setObjectName(u"LoginSMSTab") self.verticalLayout_7 = QVBoxLayout(self.LoginSMSTab) self.verticalLayout_7.setSpacing(2) self.verticalLayout_7.setObjectName(u"verticalLayout_7") self.verticalLayout_7.setContentsMargins(0, 0, 0, 0) self.PhoneNumberFrame = QFrame(self.LoginSMSTab) self.PhoneNumberFrame.setObjectName(u"PhoneNumberFrame") self.PhoneNumberFrame.setFrameShape(QFrame.NoFrame) self.PhoneNumberFrame.setFrameShadow(QFrame.Plain) self.formLayout_2 = QFormLayout(self.PhoneNumberFrame) self.formLayout_2.setObjectName(u"formLayout_2") self.formLayout_2.setContentsMargins(6, -1, 6, 0) self.PhoneLbl = QLabel(self.PhoneNumberFrame) self.PhoneLbl.setObjectName(u"PhoneLbl") self.formLayout_2.setWidget(0, QFormLayout.LabelRole, self.PhoneLbl) self.PhoneNumberEdit = QLineEdit(self.PhoneNumberFrame) self.PhoneNumberEdit.setObjectName(u"PhoneNumberEdit") self.PhoneNumberEdit.setInputMask(u"+7-999-999-99-99;_") self.formLayout_2.setWidget(0, QFormLayout.FieldRole, self.PhoneNumberEdit) self.verticalLayout_7.addWidget(self.PhoneNumberFrame) self.CodeButtonFrame = QFrame(self.LoginSMSTab) self.CodeButtonFrame.setObjectName(u"CodeButtonFrame") self.CodeButtonFrame.setFrameShape(QFrame.NoFrame) self.CodeButtonFrame.setFrameShadow(QFrame.Plain) self.verticalLayout_8 = QVBoxLayout(self.CodeButtonFrame) self.verticalLayout_8.setObjectName(u"verticalLayout_8") self.verticalLayout_8.setContentsMargins(0, 6, 0, 0) self.GetCodeBtn = QPushButton(self.CodeButtonFrame) self.GetCodeBtn.setObjectName(u"GetCodeBtn") sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.GetCodeBtn.sizePolicy().hasHeightForWidth()) self.GetCodeBtn.setSizePolicy(sizePolicy) self.verticalLayout_8.addWidget(self.GetCodeBtn, 0, Qt.AlignHCenter) self.verticalLayout_7.addWidget(self.CodeButtonFrame) self.CodeFrame = QFrame(self.LoginSMSTab) self.CodeFrame.setObjectName(u"CodeFrame") self.CodeFrame.setFrameShape(QFrame.NoFrame) self.CodeFrame.setFrameShadow(QFrame.Plain) self.formLayout_3 = QFormLayout(self.CodeFrame) self.formLayout_3.setObjectName(u"formLayout_3") self.formLayout_3.setContentsMargins(6, -1, 6, 0) self.CodeLbl = QLabel(self.CodeFrame) self.CodeLbl.setObjectName(u"CodeLbl") self.formLayout_3.setWidget(0, QFormLayout.LabelRole, self.CodeLbl) self.CodeEdit = QLineEdit(self.CodeFrame) self.CodeEdit.setObjectName(u"CodeEdit") self.formLayout_3.setWidget(0, QFormLayout.FieldRole, self.CodeEdit) self.verticalLayout_7.addWidget(self.CodeFrame) self.SMSButtonFrame = QFrame(self.LoginSMSTab) self.SMSButtonFrame.setObjectName(u"SMSButtonFrame") sizePolicy1 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) sizePolicy1.setHorizontalStretch(0) sizePolicy1.setVerticalStretch(0) sizePolicy1.setHeightForWidth( self.SMSButtonFrame.sizePolicy().hasHeightForWidth()) self.SMSButtonFrame.setSizePolicy(sizePolicy1) self.SMSButtonFrame.setFrameShape(QFrame.NoFrame) self.SMSButtonFrame.setFrameShadow(QFrame.Plain) self.verticalLayout_10 = QVBoxLayout(self.SMSButtonFrame) self.verticalLayout_10.setObjectName(u"verticalLayout_10") self.verticalLayout_10.setContentsMargins(0, 0, 0, 6) self.frame = QFrame(self.SMSButtonFrame) self.frame.setObjectName(u"frame") sizePolicy1.setHeightForWidth( self.frame.sizePolicy().hasHeightForWidth()) self.frame.setSizePolicy(sizePolicy1) self.frame.setFrameShape(QFrame.NoFrame) self.frame.setFrameShadow(QFrame.Plain) self.verticalLayout_9 = QVBoxLayout(self.frame) self.verticalLayout_9.setObjectName(u"verticalLayout_9") self.SMSLoginBtn = QPushButton(self.frame) self.SMSLoginBtn.setObjectName(u"SMSLoginBtn") sizePolicy.setHeightForWidth( self.SMSLoginBtn.sizePolicy().hasHeightForWidth()) self.SMSLoginBtn.setSizePolicy(sizePolicy) self.verticalLayout_9.addWidget(self.SMSLoginBtn, 0, Qt.AlignHCenter | Qt.AlignTop) self.verticalLayout_10.addWidget(self.frame) self.line = QFrame(self.SMSButtonFrame) self.line.setObjectName(u"line") self.line.setFrameShape(QFrame.HLine) self.line.setFrameShadow(QFrame.Sunken) self.verticalLayout_10.addWidget(self.line) self.SMSCloseBtn = QPushButton(self.SMSButtonFrame) self.SMSCloseBtn.setObjectName(u"SMSCloseBtn") sizePolicy.setHeightForWidth( self.SMSCloseBtn.sizePolicy().hasHeightForWidth()) self.SMSCloseBtn.setSizePolicy(sizePolicy) self.verticalLayout_10.addWidget(self.SMSCloseBtn, 0, Qt.AlignHCenter) self.verticalLayout_7.addWidget(self.SMSButtonFrame) self.LoginMethodTabs.addTab(self.LoginSMSTab, "") self.LoginPasswordTab = QWidget() self.LoginPasswordTab.setObjectName(u"LoginPasswordTab") self.verticalLayout = QVBoxLayout(self.LoginPasswordTab) self.verticalLayout.setSpacing(2) self.verticalLayout.setObjectName(u"verticalLayout") self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.LoginDataFrame = QFrame(self.LoginPasswordTab) self.LoginDataFrame.setObjectName(u"LoginDataFrame") sizePolicy2 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) sizePolicy2.setHorizontalStretch(0) sizePolicy2.setVerticalStretch(0) sizePolicy2.setHeightForWidth( self.LoginDataFrame.sizePolicy().hasHeightForWidth()) self.LoginDataFrame.setSizePolicy(sizePolicy2) self.LoginDataFrame.setFrameShape(QFrame.NoFrame) self.LoginDataFrame.setFrameShadow(QFrame.Plain) self.formLayout = QFormLayout(self.LoginDataFrame) self.formLayout.setObjectName(u"formLayout") self.formLayout.setHorizontalSpacing(6) self.formLayout.setContentsMargins(6, -1, 6, 0) self.InnLbl = QLabel(self.LoginDataFrame) self.InnLbl.setObjectName(u"InnLbl") self.formLayout.setWidget(0, QFormLayout.LabelRole, self.InnLbl) self.InnEdit = QLineEdit(self.LoginDataFrame) self.InnEdit.setObjectName(u"InnEdit") self.formLayout.setWidget(0, QFormLayout.FieldRole, self.InnEdit) self.PasswordLbl = QLabel(self.LoginDataFrame) self.PasswordLbl.setObjectName(u"PasswordLbl") self.formLayout.setWidget(1, QFormLayout.LabelRole, self.PasswordLbl) self.PasswordEdit = QLineEdit(self.LoginDataFrame) self.PasswordEdit.setObjectName(u"PasswordEdit") self.PasswordEdit.setEchoMode(QLineEdit.Password) self.formLayout.setWidget(1, QFormLayout.FieldRole, self.PasswordEdit) self.verticalLayout.addWidget(self.LoginDataFrame) self.FNSButtonFrame = QFrame(self.LoginPasswordTab) self.FNSButtonFrame.setObjectName(u"FNSButtonFrame") self.FNSButtonFrame.setFrameShape(QFrame.NoFrame) self.FNSButtonFrame.setFrameShadow(QFrame.Plain) self.verticalLayout_4 = QVBoxLayout(self.FNSButtonFrame) self.verticalLayout_4.setSpacing(6) self.verticalLayout_4.setObjectName(u"verticalLayout_4") self.verticalLayout_4.setContentsMargins(0, 0, 0, 6) self.FNSLoginFrame = QFrame(self.FNSButtonFrame) self.FNSLoginFrame.setObjectName(u"FNSLoginFrame") sizePolicy1.setHeightForWidth( self.FNSLoginFrame.sizePolicy().hasHeightForWidth()) self.FNSLoginFrame.setSizePolicy(sizePolicy1) self.FNSLoginFrame.setFrameShape(QFrame.NoFrame) self.FNSLoginFrame.setFrameShadow(QFrame.Plain) self.verticalLayout_5 = QVBoxLayout(self.FNSLoginFrame) self.verticalLayout_5.setObjectName(u"verticalLayout_5") self.FNSLoginBtn = QPushButton(self.FNSLoginFrame) self.FNSLoginBtn.setObjectName(u"FNSLoginBtn") sizePolicy.setHeightForWidth( self.FNSLoginBtn.sizePolicy().hasHeightForWidth()) self.FNSLoginBtn.setSizePolicy(sizePolicy) self.verticalLayout_5.addWidget(self.FNSLoginBtn, 0, Qt.AlignHCenter | Qt.AlignTop) self.verticalLayout_4.addWidget(self.FNSLoginFrame) self.FNSSplitLine = QFrame(self.FNSButtonFrame) self.FNSSplitLine.setObjectName(u"FNSSplitLine") self.FNSSplitLine.setFrameShape(QFrame.HLine) self.FNSSplitLine.setFrameShadow(QFrame.Sunken) self.verticalLayout_4.addWidget(self.FNSSplitLine) self.FNSCloseBtn = QPushButton(self.FNSButtonFrame) self.FNSCloseBtn.setObjectName(u"FNSCloseBtn") sizePolicy.setHeightForWidth( self.FNSCloseBtn.sizePolicy().hasHeightForWidth()) self.FNSCloseBtn.setSizePolicy(sizePolicy) self.verticalLayout_4.addWidget(self.FNSCloseBtn, 0, Qt.AlignHCenter) self.verticalLayout.addWidget(self.FNSButtonFrame) self.LoginMethodTabs.addTab(self.LoginPasswordTab, "") self.ESIATab = QWidget() self.ESIATab.setObjectName(u"ESIATab") self.verticalLayout_2 = QVBoxLayout(self.ESIATab) self.verticalLayout_2.setSpacing(2) self.verticalLayout_2.setObjectName(u"verticalLayout_2") self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) self.ESIAWebView = QWebEngineView(self.ESIATab) self.ESIAWebView.setObjectName(u"ESIAWebView") sizePolicy1.setHeightForWidth( self.ESIAWebView.sizePolicy().hasHeightForWidth()) self.ESIAWebView.setSizePolicy(sizePolicy1) self.ESIAWebView.setUrl(QUrl(u"about:blank")) self.verticalLayout_2.addWidget(self.ESIAWebView) self.ESIAButtonFrame = QFrame(self.ESIATab) self.ESIAButtonFrame.setObjectName(u"ESIAButtonFrame") self.ESIAButtonFrame.setFrameShape(QFrame.NoFrame) self.ESIAButtonFrame.setFrameShadow(QFrame.Plain) self.verticalLayout_6 = QVBoxLayout(self.ESIAButtonFrame) self.verticalLayout_6.setObjectName(u"verticalLayout_6") self.verticalLayout_6.setContentsMargins(0, 0, 0, 6) self.ESIASplitLine = QFrame(self.ESIAButtonFrame) self.ESIASplitLine.setObjectName(u"ESIASplitLine") self.ESIASplitLine.setFrameShape(QFrame.HLine) self.ESIASplitLine.setFrameShadow(QFrame.Sunken) self.verticalLayout_6.addWidget(self.ESIASplitLine) self.ESIACloseBtn = QPushButton(self.ESIAButtonFrame) self.ESIACloseBtn.setObjectName(u"ESIACloseBtn") sizePolicy.setHeightForWidth( self.ESIACloseBtn.sizePolicy().hasHeightForWidth()) self.ESIACloseBtn.setSizePolicy(sizePolicy) self.verticalLayout_6.addWidget(self.ESIACloseBtn, 0, Qt.AlignHCenter) self.verticalLayout_2.addWidget(self.ESIAButtonFrame) self.LoginMethodTabs.addTab(self.ESIATab, "") self.verticalLayout_3.addWidget(self.LoginMethodTabs) self.retranslateUi(LoginFNSDialog) self.FNSCloseBtn.clicked.connect(LoginFNSDialog.close) self.ESIACloseBtn.clicked.connect(LoginFNSDialog.close) self.SMSCloseBtn.clicked.connect(LoginFNSDialog.close) self.LoginMethodTabs.setCurrentIndex(0) QMetaObject.connectSlotsByName(LoginFNSDialog)
def network(self): url = QUrl("http://127.0.0.1:8000/excel_get") res = QNetworkRequest(url) self.nm.get(res)
@Slot(str) def outputStr(self, s): print(s) @Slot('double') def outputFloat(self, x): print(x) if __name__ == '__main__': app = QGuiApplication(sys.argv) view = QQuickView() # Instantiate the Python object. con = Console() # Expose the object to QML. context = view.rootContext() context.setContextProperty("con", con) #qml_file = os.fspath(Path(__file__).resolve().parent / 'qml_test2.qml') view.setSource(QUrl("Source/away_from_keyboard/qml_test2.qml")) if view.status() == QQuickView.Error: sys.exit(-1) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make sure all child QML instances # are destroyed in the correct order. del view sys.exit(res)
url = "http://country.io/names.json" response = urllib.request.urlopen(url) data = json.loads(response.read().decode('utf-8')) # print("data",data) # Format and sort the data data_list = list(data.values()) # print("data_list", data_list) data_list.sort() # Set up the application window app = QGuiApplication(sys.argv) view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) # Expose the list to the Qml code my_model = QStringListModel() my_model.setStringList(data_list) view.rootContext().setContextProperty("myModel", my_model) # Load the QML file qml_file = Path(__file__).parent / "main_view.qml" view.setSource(QUrl.fromLocalFile(os.fspath(qml_file.resolve()))) # Show the window if view.status() == QQuickView.Error: sys.exit(-1) view.show() # execute and cleanup app.exec() del view
painter.drawRoundedRect(0, 0, itemSize.width(), itemSize.height() - 10, 10, 10) if self.rightAligned: points = [ QPointF(itemSize.width() - 10.0, itemSize.height() - 10.0), QPointF(itemSize.width() - 20.0, itemSize.height()), QPointF(itemSize.width() - 30.0, itemSize.height() - 10.0), ] else: points = [ QPointF(10.0, itemSize.height() - 10.0), QPointF(20.0, itemSize.height()), QPointF(30.0, itemSize.height() - 10.0), ] painter.drawConvexPolygon(points) if __name__ == "__main__": app = QApplication(sys.argv) view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) qmlRegisterType(TextBalloon, "TextBalloonPlugin", 1, 0, "TextBalloon") view.setSource(QUrl.fromLocalFile("main.qml")) if view.status() == QQuickView.Error: sys.exit(-1) view.show() sys.exit(app.exec_())
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ## ## $QT_END_LICENSE$ ## ############################################################################# """PySide6 port of the remoteobjects/modelviewclient example from Qt v5.x""" import sys from PySide6.QtCore import QUrl from PySide6.QtWidgets import (QApplication, QTreeView) from PySide6.QtRemoteObjects import QRemoteObjectNode if __name__ == '__main__': app = QApplication(sys.argv) node = QRemoteObjectNode(QUrl("local:registry")) node.setHeartbeatInterval(1000) view = QTreeView() view.setWindowTitle("RemoteView") view.resize(640,480) model = node.acquireModel("RemoteModel") view.setModel(model) view.show() sys.exit(app.exec_())
def browseSnippets(self): url = QUrl.fromLocalFile(snippetPath) QDesktopServices.openUrl(url)
first_item.setBackground(Qt.red) row = [first_item, second_item] source_model.invisibleRootItem().appendRow(row) list.append("FancyTextNumber {}".format(i)) # Needed by QMLModelViewClient role_names = { Qt.DisplayRole: QByteArray(b'_text'), Qt.BackgroundRole: QByteArray(b'_color') } source_model.setItemRoleNames(role_names) roles = [Qt.DisplayRole, Qt.BackgroundRole] print("Creating registry host") node = QRemoteObjectRegistryHost(QUrl("local:registry")) node2 = QRemoteObjectHost(QUrl("local:replica"), QUrl("local:registry")) node2.enableRemoting(source_model, "RemoteModel", roles) view = QTreeView() view.setWindowTitle("SourceView") view.setModel(source_model) view.show() handler = TimerHandler(source_model) QTimer.singleShot(5000, handler.change_data) QTimer.singleShot(10000, handler.insert_data) QTimer.singleShot(11000, handler.change_flags) QTimer.singleShot(12000, handler.remove_data) QTimer.singleShot(13000, handler.move_data)
colorChanged = Signal() color = Property(QColor, getColor, setColor, notify=colorChanged) name = Property(str, getName, setName) chartCleared = Signal() @Slot() # This should be something like @Invokable def clearChart(self): self.setColor(Qt.transparent) self.update() self.chartCleared.emit() if __name__ == '__main__': app = QGuiApplication(sys.argv) qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart') view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) if view.status() == QQuickView.Error: sys.exit(-1) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make sure all child QML instances # are destroyed in the correct order. del view sys.exit(res)
def open_file_url(url): QDesktopServices.openUrl(QUrl("file:///" + url))
def open_file(file): QDesktopServices.openUrl(QUrl.fromLocalFile(file))
def launch(self): QDesktopServices.openUrl(QUrl.fromLocalFile(self.fileName))
all_devices = sd.query_devices() mme_devices = [] mme_id = -1 for idx, device in enumerate(sd.query_hostapis()): if "MME" in device["name"]: mme_id = idx break for device in all_devices: if device["hostapi"] == mme_id and device["max_output_channels"] > 0: mme_devices.append(device["name"]) return mme_devices if __name__ == "__main__": app = QGuiApplication(sys.argv) engine = QQmlApplicationEngine() sounddevices = get_devices() model = SoundBoard.SoundBoard(sounddevices) engine.rootContext().setContextProperty("soundbuttons", model.soundbuttons) engine.rootContext().setContextProperty("sounddevices", sounddevices) engine.rootContext().setContextProperty("logicmodel", model) qml_file = os.path.join(os.path.dirname(__file__), "app.qml") engine.load(QUrl.fromLocalFile(os.path.abspath(qml_file))) app.aboutToQuit.connect(model.handle_close) app.exec_()
self.load_from_json(filename) def load_from_json(self,filename): """Load list of cities from given file""" with open(filename,encoding="utf-8") as f: self.city_list = json.load(f) def rowCount(self, parent:QtCore.QModelIndex=...) -> int: """ Return number of cities in the list""" return len(self.city_list) def data(self, index:QtCore.QModelIndex, role:int=...) -> typing.Any: """ For given index and DisplayRole return name of the selected city""" # Return None if the index is not valid if not index.isValid(): return None # If the role is the DisplayRole, return name of the city if role == QtCore.Qt.DisplayRole: return self.city_list[index.row()]["muniLabel"] app = QGuiApplication(sys.argv) view = QQuickView() url = QUrl(VIEW_URL) citylist_model = CityListModel(CITY_LIST_FILE) ctxt = view.rootContext() ctxt.setContextProperty('cityListModel',citylist_model) view.setSource(url) view.show() app.exec_()
def Sl_on_double_click(self): file_path = QUrl.fromUserInput(self.path) QDesktopServices.openUrl(file_path)