def qt_open_path(path): system = get_platform() if system == 'Windows': from common.file_path import FilePath path = FilePath(path).shortpath # code below was added to resolve issue on Linux # 'kde-open5: /opt/pvtbox/libQt5Core.so.5: # version `Qt_5.9.7_PRIVATE_API' not found # (required by /usr/lib64/libQt5Xml.so.5)' if system == "Linux" and \ os.environ.get("XDG_CURRENT_DESKTOP", None) == "KDE": os.environ["XDG_CURRENT_DESKTOP"] = "X-Generic" QDesktopServices.openUrl(QUrl.fromLocalFile(path))
def search(self): try: imap = imaplib.IMAP4_SSL(host=self.host) imap.login(self.userName, self.password) imap.select() error, searchResult = imap.search(None, "SUBJECT " + self.subject) num = searchResult[0] if 0 != len(num): self.found = True if b' ' not in num: typ, data = imap.fetch(num, '(RFC822)') mail = mailparser.parse_from_bytes(data[0][1]) htmlParser = ParseLink() htmlParser.feed(mail.body) url = htmlParser.link if 0 != len(url): QDesktopServices.openUrl(url) self.delete(imap, num) self.errorList = "" else: self.errorList = "URL not found in mail" else: self.errorList = "More than one email found, possible attack" else: self.errorList = "Email not found" imap.close() imap.logout() except socket.gaierror as error: code, self.errorList = error.args self.found = True except imaplib.IMAP4.error as error: self.controller.resetPassword(self.address) reason, = error.args self.errorList = reason.decode() self.found = True self.done = True
def ClickOpenFilePath(self): selected = self.tableWidget.selectedIndexes() selectRows = set() for index in selected: selectRows.add(index.row()) if not selectRows: return # 只去第一个 row = selectRows.pop() col = 0 bookId = self.tableWidget.item(row, col).text() task = self.downloadDict.get(bookId) assert isinstance(task, DownloadInfo) QDesktopServices.openUrl( QUrl.fromLocalFile(os.path.dirname(task.savePath))) return
def __menu_opened(self, position): action = self.thumb_menu.exec_( self.tableWidget_shotlist.mapToGlobal(position)) if action == self.action_finder: # self.finderpath set by cell_entered SLOT if self.finderpath: QDesktopServices.openUrl("file:///" + self.finderpath) elif action == self.action_preview: if self.previewitem: self.item_doubleclicked(self.previewitem) elif action == self.action_reindex: self.reindex_clicked() else: pass
def open_directory(self, checked=False): """Open file explorer in View data directory.""" url = "file:///" + self.data_dir # noinspection PyTypeChecker, PyCallByClass, PyArgumentList res = QDesktopServices.openUrl(QUrl(url, QUrl.TolerantMode)) if not res: self._toolbox.msg_error.emit("Failed to open directory: {0}".format(self.data_dir))
def __create_menu(self) -> None: menu_bar = self.menuBar() file_menu = menu_bar.addMenu("File") import_action = file_menu.addAction("Import Audio...") import_action.setShortcut(QKeySequence("Ctrl+I")) import_action.triggered.connect(self.__import_audio) open_file_action = file_menu.addAction("Open...") open_file_action.setShortcut(QKeySequence("Ctrl+O")) open_file_action.triggered.connect(self.__open_file) file_menu.addSeparator() save_action = file_menu.addAction("Save") save_action.setShortcut(QKeySequence("Ctrl+S")) save_action.triggered.connect(self.__save_current_file) save_as_action = file_menu.addAction("Save As...") save_as_action.setShortcut(QKeySequence("Ctrl+Shift+S")) save_as_action.triggered.connect(self.__save_current_file_as) file_menu.addSeparator() exit_action = file_menu.addAction("Exit") exit_action.setShortcut(QKeySequence("Alt+f4")) exit_action.triggered.connect(QCoreApplication.quit) help_menu = menu_bar.addMenu("Help") documentation_action = help_menu.addAction("Open Documentation...") documentation_action.triggered.connect( lambda: QDesktopServices.openUrl(libchapters.DOCUMENTATION)) help_menu.addSeparator() about_action = help_menu.addAction("About...") about_action.triggered.connect(self.__show_about_dialog)
def acceptNavigationRequest(self, url: QUrl, type_: QWebEnginePage.NavigationType, is_main_frame: bool) -> bool: if not is_main_frame: return super().acceptNavigationRequest(url, type_, is_main_frame) if (type_ != QWebEnginePage.NavigationTypeTyped and url.authority() != self.url().authority()): # The web is only allowed pages on the same origin # Cross origin pages would open in browser if url.scheme() in ("http", "https"): QDesktopServices.openUrl(url) return False return super().acceptNavigationRequest(url, type_, is_main_frame)
def setup_menus(self): file_menu = self.menuBar().addMenu("&File") exit_action = file_menu.addAction("E&xit") exit_action.setShortcut(QKeySequence("Ctrl+Q")) character_menu = self.menuBar().addMenu("&Character") import_action = character_menu.addAction("&Import from PDF") import_action.triggered.connect( lambda: self.pdf_wizard_factory.create(self)) import_action = character_menu.addAction("&Create new Character") import_action.triggered.connect(self.create_new_player) export_menu = self.menuBar().addMenu("&Export") export_debug_action = export_menu.addAction("Export Debug") export_debug_action.triggered.connect( lambda: self.export_pdf_wizard_factory.create(self)) resource_menu = self.menuBar().addMenu("&Resources") open_app_data = resource_menu.addAction("Open Appdata Folder") dir_to_open = QStandardPaths.writableLocation( QStandardPaths.AppDataLocation) open_app_data.triggered.connect( lambda: QDesktopServices.openUrl(dir_to_open)) exit_action.triggered.connect(QApplication.instance().quit) logger.debug("Menus set-up")
def openLink(self, key, arg="", fileArg=None): """Use `QDesktopServices` to open an url using the system default applications Parameters: key: the entry key or the link (if `arg` == "link") arg: if `arg` == "file", `fileArg` must be the file name if `arg` == "link", `key` must be the link to be opened for any other values, the link will be generated using the `physbiblio.view.viewWntry.getLink` method fileArg: the file name if `arg` == "file", or the argument passed to `physbiblio.view.viewWntry.getLink` if needed """ if isinstance(key, list): for k in key: self.openLink(k, arg, fileArg) else: if arg == "file": url = QUrl.fromLocalFile(fileArg) elif arg == "link": url = QUrl(key) else: link = self.getLink(key, arg=arg, fileArg=fileArg) url = QUrl(link) if QDesktopServices.openUrl(url): pBLogger.debug(ccstr.openSuccess % (url.toString(), key)) else: pBLogger.warning(ccstr.openFailed % key)
def open_directory(self): """Open this item's data directory in file explorer.""" url = "file:///" + self.data_dir # noinspection PyTypeChecker, PyCallByClass, PyArgumentList res = QDesktopServices.openUrl(QUrl(url, QUrl.TolerantMode)) if not res: self._logger.msg_error.emit( f"Failed to open directory: {self.data_dir}")
def export_html_report(self): # Report file path name = f'MaterialMerger_Report_{datetime.now().strftime("%d%m%Y_%H%M")}.html' report_file = QUrl.fromLocalFile( os.path.abspath(os.path.expanduser(f'~\\Documents\\{name}'))) # Result browser html content html_data = str(self.resultBrowser.toHtml()) # Write report try: with open(report_file.toLocalFile(), 'w') as f: f.write(html_data) except Exception as e: LOGGER.error(e) QDesktopServices.openUrl(report_file)
def _open_psd_file(self, ignore: bool = False): self.ui.lastFileWidget.setEnabled(True) if AppSettings.app['open_editor'] or ignore: external_app_path: Path = Path(AppSettings.app['editor_path']) if external_app_path.exists() and external_app_path.is_file(): # Open Psd in user defined editor args = [ external_app_path.as_posix(), self.current_psd_file.resolve().__str__() ] Popen(args) else: # Default behaviour if no editor set # Open psd thru QDesktopService with OS associated app file_url = QUrl.fromLocalFile(self.current_psd_file.as_posix()) QDesktopServices.openUrl(file_url)
def accessibility_popup(self): global has_prompted_accessibility if has_prompted_accessibility: return has_prompted_accessibility = True msgbox = QMessageBox( QMessageBox.Warning, "Permission required", "RuneKit needs Screen Recording permission\n\nOpen System Preferences > Security > Privacy > Screen Recording to allow this", QMessageBox.Open | QMessageBox.Ignore, ) button = msgbox.exec() if button == QMessageBox.Open: QDesktopServices.openUrl( "x-apple.systempreferences:com.apple.preference.security?Privacy_Screen Recording" )
def data_generate_menu(self, pos): row_num = -1 for i in self.data_list.selectionModel().selection().indexes(): row_num = i.row() if row_num < 0: return menu = QMenu() open_item = menu.addAction("打开文件所在位置") del_item = menu.addAction("移除") delall_item = menu.addAction("移除所有") action = menu.exec_(self.data_list.mapToGlobal(pos)) if action == del_item: self.data_list.takeItem(row_num) elif action == delall_item: self.data_list.clear() elif action == open_item: QDesktopServices.openUrl( QUrl("file:" + os.path.dirname(self.data_list.item(row_num).text())))
def open_results(self, checked=False): """Open output directory in file browser.""" if not os.path.exists(self.output_dir): self._toolbox.msg_warning.emit( "Tool <b>{0}</b> has no results. " "Click Execute to generate them.".format(self.name)) return url = "file:///" + self.output_dir # noinspection PyTypeChecker, PyCallByClass, PyArgumentList res = QDesktopServices.openUrl(QUrl(url, QUrl.TolerantMode)) if not res: self._toolbox.msg_error.emit( "Failed to open directory: {0}".format(self.output_dir))
def doc_action(self, action: QAction): file, tab_page = Path('.'), None if self.context_tab_index >= 0: tab_page = self.ui.view_mgr.tab.widget(self.context_tab_index) file = self.ui.view_mgr.file_mgr.get_file_from_widget( tab_page) or Path('.') if not path_exists(file) or not file.is_file(): self.ui.msg( _('Kein gültiger Pfad für das Dokument gesetzt. Das Dokument muss zuerst gespeichert werden.' ), 5000) return if action == self.copy_action: self.ui.app.clipboard().setText(file.as_posix()) self.ui.msg( _('Dokumenten Pfad wurde in die Zwischenablage kopiert.<br/><i>{}<i>' ).format(file.as_posix())) elif action == self.open_action: q = QUrl.fromLocalFile(file.parent.as_posix()) QDesktopServices.openUrl(q)
def open_reference(self, index): """Open reference in default program.""" if not index: return if not index.isValid(): logging.error("Index not valid") return reference = self.file_references()[index.row()] url = "file:///" + reference # noinspection PyTypeChecker, PyCallByClass, PyArgumentList res = QDesktopServices.openUrl(QUrl(url, QUrl.TolerantMode)) if not res: self._logger.msg_error.emit( f"Failed to open reference:<b>{reference}</b>")
def open_data_file(self, index): """Open data file in default program.""" if not index: return if not index.isValid(): logging.error("Index not valid") return data_file = self.data_files()[index.row()] url = "file:///" + os.path.join(self.data_dir, data_file) # noinspection PyTypeChecker, PyCallByClass, PyArgumentList res = QDesktopServices.openUrl(QUrl(url, QUrl.TolerantMode)) if not res: self._logger.msg_error.emit( f"Opening file <b>{data_file}</b> failed")
def open_url(url): """Opens the given url in the appropriate Web browser for the user's desktop environment, and returns true if successful; otherwise returns false. If the URL is a reference to a local file (i.e., the URL scheme is "file") then it will be opened with a suitable application instead of a Web browser. Handle return value on caller side. Args: url(str): URL to open Returns: bool: True if successful, False otherwise """ return QDesktopServices.openUrl(QUrl(url, QUrl.TolerantMode))
def open_includes_file(self, index): """Open source file in default program.""" if not index: return if not index.isValid(): self._toolbox.msg_error.emit("Selected index not valid") return else: includes_file = self.sourcefiles_model.itemFromIndex(index).text() fname, ext = os.path.splitext(includes_file) if ext in [".bat", ".exe"]: self._toolbox.msg_warning.emit("Sorry, opening files with extension <b>{0}</b> not implemented. " "Please open the file manually.".format(ext)) return url = "file:///" + os.path.join(self.program_path, includes_file) # noinspection PyCallByClass, PyTypeChecker, PyArgumentList res = QDesktopServices.openUrl(QUrl(url, QUrl.TolerantMode)) if not res: self._toolbox.msg_error.emit("Failed to open file: <b>{0}</b>".format(includes_file))
def __init__(self, config): super().__init__() self.config = config self.config.appActivated.connect(self._appActivated) self.mdi = QMdiArea(self) self.mdi.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.mdi.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.setCentralWidget(self.mdi) self.menu = self.menuBar().addMenu("&Windows") self.aboutMenu = QMenuBar(self.menuBar()) self.menuBar().setCornerWidget(self.aboutMenu) m = self.aboutMenu.addMenu("&Help") self.helpNexxT = QAction("Help ...") self.aboutNexxT = QAction("About nexxT ...") self.aboutQt = QAction("About Qt ...") self.aboutPython = QAction("About Python ...") m.addActions([self.helpNexxT]) m.addSeparator() m.addActions([self.aboutNexxT, self.aboutQt, self.aboutPython]) self.helpNexxT.triggered.connect(lambda: QDesktopServices.openUrl( QUrl("https://nexxT.readthedocs.org"))) self.aboutNexxT.triggered.connect(lambda: QMessageBox.about( self, "About nexxT", """\ This program uses <b>nexxT</b> %(version)s, a generic hybrid python/c++ framework for developing computer vision algorithms.<br><br> nexxT is available under the <a href='https://github.com/ifm/nexxT/blob/master/LICENSE'>Apache 2.0 License</a> together with the <a href='https://github.com/ifm/nexxT/blob/master/NOTICE'>notice</a>. """ % dict(version=nexxT.__version__))) self.aboutQt.triggered.connect(lambda: QMessageBox.aboutQt(self)) self.aboutPython.triggered.connect(self._aboutPython) self.toolbar = None self.managedMdiWindows = [] self.managedSubplots = {} self.windows = {} self.activeApp = None self._ignoreCloseEvent = False
def showContextMenu(self, pos: QPoint) -> None: mods = self.getSelectedMods() if not mods: return menu = QMenu(self) actionOpen = menu.addAction(QIcon(str(getRuntimePath('resources/icons/open-folder.ico'))), '&Open Directory') 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( QIcon(str(getRuntimePath('resources/icons/browse.ico'))), 'Open &Nexus Mods page') 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))
def launch(self): QDesktopServices.openUrl(QUrl.fromLocalFile(self.fileName))
def open_version_link(self): if self._current_version_url is None: raise RuntimeError( "Called open_version_link, but _current_version_url is None") QDesktopServices.openUrl(QUrl(self._current_version_url))
def open_doc_link(self): QDesktopServices.openUrl( QUrl("https://docs.angr.io/", QUrl.TolerantMode))
def openFile(file): QDesktopServices.openUrl(QUrl.fromLocalFile(file))
def open_file(file): QDesktopServices.openUrl(QUrl.fromLocalFile(file))
def OpenUrl(self): QDesktopServices.openUrl(QUrl(config.UpdateUrl))
def open_twitter_page(self): """Open the labsquare page on Twitter""" QDesktopServices.openUrl(QUrl("https://twitter.com/labsquare"))
def open_github_page(self): """Open the project page on GitHub""" QDesktopServices.openUrl(QUrl("https://github.com/labsquare/cutevariant"))
def help_action_triggered(self): # opens browser with specified url, directs user to Issues section of GitHub repo QDesktopServices.openUrl( QUrl("https://github.com/SINTEFMedtek/GSI-RADS/issues"))
def launch(self): QDesktopServices.openUrl(QUrl.fromLocalFile(self.fileName))