def on_help(self, *args): url = "file://" + os.path.join(package.get_datadir(), "help/index.html") Gtk.show_uri_on_window(self.window, url, Gdk.CURRENT_TIME) if self.window: # see https://gitlab.gnome.org/GNOME/gtk/-/issues/1211 self.window.get_window().set_cursor(self.cursor)
def OpenUri(uri, window): """Open a URI in an external (web) browser. The given argument has to be a properly formed URI including the scheme (fe. HTTP). As of now failures will be silently discarded.""" # Situation 1, user defined a way of handling the protocol protocol = uri[:uri.find(":")] if protocol in PROTOCOL_HANDLERS: if isinstance(PROTOCOL_HANDLERS[protocol], types.MethodType): PROTOCOL_HANDLERS[protocol](uri.strip()) return if PROTOCOL_HANDLERS[protocol]: executeCommand(PROTOCOL_HANDLERS[protocol], uri) return # Situation 2, user did not define a way of handling the protocol if sys.platform == "win32" and webbrowser: webbrowser.open(uri) return try: gtk.show_uri_on_window(window, uri, Gdk.CURRENT_TIME) except AttributeError: screen = window.get_screen() gtk.show_uri(screen, uri, Gdk.CURRENT_TIME)
def __on_snapshot(self, webview, result, first_pass): """ Set snapshot on main image @param webview as WebView @param result as Gio.AsyncResult @param first_pass as bool """ try: snapshot = webview.get_snapshot_finish(result) pixbuf = Gdk.pixbuf_get_from_surface(snapshot, 0, 0, snapshot.get_width(), snapshot.get_height()) pixbuf.savev("/tmp/eolie_snapshot.png", "png", [None], [None]) Gtk.show_uri_on_window(self._window, "file:///tmp/eolie_snapshot.png", Gtk.get_current_event_time()) except Exception as e: Logger.error("WebView::__on_snapshot(): %s", e) # The 32767 limit on the width/height dimensions # of an image surface is new in cairo 1.10, # try with WebKit2.SnapshotRegion.VISIBLE if first_pass: self.get_snapshot(WebKit2.SnapshotRegion.VISIBLE, WebKit2.SnapshotOptions.NONE, None, self.__on_snapshot, False)
def open_uri(uri, window): """Open a URI in an external (web) browser. The given argument has to be a properly formed URI including the scheme (fe. HTTP). As of now failures will be silently discarded.""" # Situation 1, user defined a way of handling the protocol protocol = uri[:uri.find(":")] protocol_handlers = NICOTINE.np.config.sections["urls"]["protocols"] if protocol in protocol_handlers and protocol_handlers[protocol]: try: execute_command(protocol_handlers[protocol], uri) return except RuntimeError as e: log.add_warning("%s", e) if protocol == "slsk": on_soul_seek_uri(uri.strip()) # Situation 2, user did not define a way of handling the protocol if sys.platform == "win32": import webbrowser webbrowser.open(uri) return try: Gtk.show_uri_on_window(window, uri, Gdk.CURRENT_TIME) except AttributeError: screen = window.get_screen() Gtk.show_uri(screen, uri, Gdk.CURRENT_TIME)
def open_url(url, parent_window=None, prompt=True): """Open an HTTP URL. Try to run as non-root.""" # drop privileges so the web browser is running as a normal process if os.name == 'posix' and os.getuid() == 0: msg = _( "Because you are running as root, please manually open this link in a web browser:\n%s" ) % url message_dialog(None, msg, Gtk.MessageType.INFO) return if prompt: # find hostname import re ret = re.search('^http(s)?://([a-z.]+)', url) if not ret: host = url else: host = ret.group(2) # TRANSLATORS: %s expands to www.bleachbit.org or similar msg = _("Open web browser to %s?") % host resp = message_dialog(parent_window, msg, Gtk.MessageType.QUESTION, Gtk.ButtonsType.OK_CANCEL) if Gtk.ResponseType.OK != resp: return # open web browser if os.name == 'nt': # in Gtk.show_uri() avoid 'glib.GError: No application is registered as # handling this file' import webbrowser webbrowser.open(url) else: Gtk.show_uri_on_window(parent_window, url, Gdk.CURRENT_TIME)
def on_april_fools(self, *args): """Action callback, rickrolling the user.""" Gtk.show_uri_on_window( self.props.active_window, \ 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',\ Gdk.CURRENT_TIME \ )
def on_dl_report_pdf_activate(self, widget, event=None): selection = self.tree_view_reports.get_selection() (model, path_list) = selection.get_selected_rows() for path in path_list: tree_iter = model.get_iter(path) value = model.get_value(tree_iter, 7)[:-4] + "pdf" Gtk.show_uri_on_window( None, self.scan.host[:-8] + value, Gdk.CURRENT_TIME)
def openLocal(widget): localFolder = "file://{}".format(Config().getValue("folder")) if os.getenv("SNAP") is not None: logger.debug("Opening {} in snap: xdg-open".format(localFolder)) subprocess.call(["xdg-open", localFolder]) else: logger.debug("Opening {}: show_uri_on_window".format(localFolder)) Gtk.show_uri_on_window(None, localFolder, Gdk.CURRENT_TIME)
def on_dl_report_html_activate(self, widget, event=None): selection = self.tree_view_reports.get_selection() (model, path_list) = selection.get_selected_rows() for path in path_list: tree_iter = model.get_iter(path) value = ast.literal_eval(model.get_value(tree_iter, 7)) if value is not None: Gtk.show_uri_on_window(None, self.scan.host[:-8] + value[0], Gdk.CURRENT_TIME)
def on_edit(self, *args): path = self._user_dictionary.get_text().strip() path = os.path.join(package.get_user_datadir(), path) with open(path, 'a+') as f: pass try: Gtk.show_uri_on_window(None, 'file://' + path, Gdk.CURRENT_TIME) except Exception: pass
def on_settings_action(self, button): if button.props.label == "Add Shortcut": Gtk.show_uri_on_window(self, "settings://input/keyboard/shortcuts", GLib.get_current_time()) if button.props.label == "Quit Stashed": self.destroy() if button.props.label == "Buy Me Coffee": Gtk.show_uri_on_window(None, "https://www.buymeacoffee.com/hezral", GLib.get_current_time())
def view_path(self, path): if os.path.isdir(path): uri = "file://%s" % path if "show_uri_on_window" in dir(Gtk): Gtk.show_uri_on_window(None, uri, 0) else: Gtk.show_uri(None, uri, 0) else: binary = self.get_editor_executable() subprocess.Popen([binary, path])
def __on_buy_action_activate(self, action, variant): """ Launch a browser for Qobuz @param Gio.SimpleAction @param GLib.Variant """ artists = " ".join(self.__object.artists) search = "%s %s" % (artists, self.__object.name) uri = "https://www.qobuz.com/search?q=%s" % (GLib.uri_escape_string( search, None, True)) Gtk.show_uri_on_window(App().window, uri, Gdk.CURRENT_TIME)
def _on_open_clicked(self, button): """ Open download folder @param button as Gtk.button """ directory_uri = App().settings.get_value("download-uri").get_string() if not directory_uri: directory = GLib.get_user_special_dir( GLib.UserDirectory.DIRECTORY_DOWNLOAD) directory_uri = GLib.filename_to_uri(directory, None) Gtk.show_uri_on_window(self.__window, directory_uri, Gdk.CURRENT_TIME) self.hide()
def on_open_with_browser_activate(self, widget, event=None): selection = self.tree_view_vulnerabilities_info.get_selection() (model, path_list) = selection.get_selected_rows() for path in path_list: tree_iter = model.get_iter(path) target_url = model.get_value(tree_iter, 2) raw = model.get_value(tree_iter, 3) request_info = util.HTTPRequest( raw_http_request=ast.literal_eval(raw).decode()) scheme, netloc, path, query, fragment = urllib.parse.urlsplit( target_url) value = scheme + "://" + netloc + request_info.path Gtk.show_uri_on_window(None, value, Gdk.CURRENT_TIME)
def __on_label_button_release_event(self, button, event): """ Show information cache (for edition) @param button as Gtk.Button @param event as Gdk.Event """ uri = "file://%s/%s.txt" % (App().art._INFO_PATH, escape(self.__artist_name)) f = Gio.File.new_for_uri(uri) if not f.query_exists(): f.replace_contents(b"", None, False, Gio.FileCreateFlags.NONE, None) Gtk.show_uri_on_window(App().window, uri, Gdk.CURRENT_TIME)
def __on_row_activated(self, listbox, row): """ Launch row if download finished @param listbox as Gtk.ListBox @param row as Row """ try: if row.finished: Gtk.show_uri_on_window(self.__window, row.download.get_destination(), Gdk.CURRENT_TIME) self.hide() except Exception as e: Logger.error("DownloadsPopover::__on_row_activated(): %s", e)
def open_browser(url, parent=None, timestamp=0): logging.info("Opening URL {}".format(url)) if not timestamp: timestamp = Gtk.get_current_event_time() try: if hasattr(Gtk, 'show_uri_on_window'): Gtk.show_uri_on_window(parent, url, timestamp) else: # Gtk <= 3.20 screen = None if parent: screen = parent.get_screen() Gtk.show_uri(screen, url, timestamp) except GLib.Error as e: logging.warning('Failed to open URL: {}'.format(e.message))
def show_uri(label, uri): """Shows a uri. The uri can be anything handled by GIO or a quodlibet specific one. Currently handled quodlibet uris: - quodlibet:///prefs/plugins/<plugin id> Args: label (str) uri (str) the uri to show Returns: True on success, False on error """ parsed = urlparse(uri) if parsed.scheme == "quodlibet": if parsed.netloc != "": print_w("Unknown QuodLibet URL format (%s)" % uri) return False else: return __show_quodlibet_uri(parsed) else: # Gtk.show_uri_on_window exists since 3.22 if hasattr(Gtk, "show_uri_on_window"): from quodlibet.qltk import get_top_parent return Gtk.show_uri_on_window(get_top_parent(label), uri, 0) else: return Gtk.show_uri(None, uri, 0)
def __on_uri_button_clicked(self, button): """ Launch URI @param button as Gtk.Button """ visible = self.__stack.get_visible_child() index = self.__stack.get_children().index(visible) uri = self.__rules[index]["uri"] if uri == "": button.set_label(_("Can't contact this service")) button.set_sensitive(False) self.__left_button.set_label(_("Finish")) self.__right_button.set_sensitive(False) for child in self.__stack.get_children()[index + 1:]: self.__stack.remove(child) Gtk.show_uri_on_window(App().window, uri, Gdk.CURRENT_TIME)
def view_path(self, path): if os.path.isdir(path): uri = "file://%s" % path if "show_uri_on_window" in dir(Gtk): Gtk.show_uri_on_window(None, uri, 0) else: Gtk.show_uri(None, uri, 0) else: if not find_program("pkexec"): binary = self.get_editor_executable() subprocess.Popen([binary, path]) elif self.file_is_writable(path): binary = self.get_editor_executable() subprocess.Popen([binary, path]) else: binary = self.get_root_editor_executable() subprocess.Popen(["pkexec", binary, path])
def __show_donation(self): """ Show a notification telling user to donate a little """ from eolie.app_notification import AppNotification notification = AppNotification( _("Please consider a donation to the project"), [_("PayPal"), _("Liberapay")], [ lambda: Gtk.show_uri_on_window( App().active_window, "https://www.paypal.me/lollypopgnome", Gdk.CURRENT_TIME), lambda: Gtk.show_uri_on_window( App().active_window, "https://liberapay.com/gnumdk", Gdk.CURRENT_TIME) ]) self.add_overlay(notification) notification.show() notification.set_reveal_child(True) App().settings.set_value("show-donation", GLib.Variant("b", False))
def __show_donation(self): """ Show a notification telling user to donate a little """ from lollypop.app_notification import AppNotification notification = AppNotification( _("Please consider a donation to the project"), [_("PayPal"), _("Patreon")], [ lambda: Gtk.show_uri_on_window( App().window, "https://www.paypal.me/lollypopgnome", Gdk. CURRENT_TIME), lambda: Gtk.show_uri_on_window( App().window, "https://www.patreon.com/gnumdk", Gdk. CURRENT_TIME) ]) self.add_overlay(notification) notification.show() notification.set_reveal_child(True) self.__set_gsettings_value(self.__DONATION)
def show_uri(label, uri): """Shows a uri. The uri can be anything handled by GIO or a quodlibet specific one. Currently handled quodlibet uris: - quodlibet:///prefs/plugins/<plugin id> Args: label (str) uri (str) the uri to show Returns: True on success, False on error """ parsed = urlparse(uri) if parsed.scheme == "quodlibet": if parsed.netloc != "": print_w("Unknown QuodLibet URL format (%s)" % uri) return False else: return __show_quodlibet_uri(parsed) elif parsed.scheme == "file" and (is_windows() or is_osx()): # Gio on non-Linux can't handle file URIs for some reason, # fall back to our own implementation for now from quodlibet.qltk.showfiles import show_files try: filepath = uri2fsn(uri) except ValueError: return False else: return show_files(filepath, []) else: # Gtk.show_uri_on_window exists since 3.22 try: if hasattr(Gtk, "show_uri_on_window"): from quodlibet.qltk import get_top_parent return Gtk.show_uri_on_window(get_top_parent(label), uri, 0) else: return Gtk.show_uri(None, uri, 0) except GLib.Error: return False
def _show_uri(uri, window): if (Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION) >= (3, 22): Gtk.show_uri_on_window(window, uri, Gdk.CURRENT_TIME) else: Gtk.show_uri(window.get_screen(), uri, Gdk.CURRENT_TIME)
def show_help_page(self, suffix): win = self.props.active_window Gtk.show_uri_on_window(win, 'help:drawing' + suffix, Gdk.CURRENT_TIME)
def on_open_module_ref_clicked(self, warning_dialog): self.set_self_module() Gtk.show_uri_on_window(None, self.module.uri, Gdk.CURRENT_TIME)
def on_report(self, *args): """Action callback, opening a new issue on the github repo.""" win = self.props.active_window Gtk.show_uri_on_window(win, self.git_url + '/issues/new', Gdk.CURRENT_TIME)
def _open_torrents(self, torrents): for torrent in torrents: Gtk.show_uri_on_window(self.get_toplevel(), torrent.uri, Gdk.CURRENT_TIME)
def on_report(self, *args): """Action callback, opening a new issue on the github repo.""" win = self.props.active_window url = 'https://github.com/maoschanz/drawing/issues/new' Gtk.show_uri_on_window(win, url, Gdk.CURRENT_TIME)
def _on_open_uri(self, action, param): uri = param.get_string() Gtk.show_uri_on_window(self.window, uri, Gdk.CURRENT_TIME)
def on_report(self, *args): """Action callback, opening a new issue on the github repo.""" win = self.props.active_window Gtk.show_uri_on_window(win, BUG_REPORT_URL, Gdk.CURRENT_TIME)