def do_search(self, searchMenu): """Launch DuckDuckGo search for string""" if not self.searchstring: return base_uri = "https://duckduckgo.com/?q=%s" uri = base_uri % urllib.quote(self.searchstring.encode("utf-8")) gtk.show_uri(None, uri, gtk.gdk.CURRENT_TIME)
def launch_url (url, ext=""): if os.name == 'nt': os.startfile(url) elif os.name == 'posix': try: gtk.show_uri(gtk.gdk.Screen(),url,0L) except ImportError: print 'gtk libraries not available, trying builtins' if not ext: ext=os.path.splitext(url) for regexp,l in launchers: if regexp.match('\.?%s'%regexp, ext): if is_on_system(app): os.popen(app + " " + url) return # if that fails... print 'builtins failing, using python webbrowser functions' try: import webbrowser webbrowser.open(url) except ImportError: dialog_extras.show_message("Unable to open",sublabel="Failed to launch URL: %s"%url) except gobject.GError, err: #print dir(err) label = _('Unable to open URL') for reg, msg in [('mailto:',_('Unable to launch mail reader.')), ('http:',_('Unable to open website.')), ('file:',_('Unable to open file.'))]: if re.match(reg,url.lower()): label = msg dialog_extras.show_message( label=label, sublabel=err.message, expander=[_('_Details'), _("There was an error launching the url: %s"%url)] )
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 'posix' == os.name and 0 == os.getuid(): msg = _( "Because you are running as root, please manually open this link in a web browser:\n%s") % url message_dialog(None, msg, gtk.MESSAGE_INFO) return if prompt: # find hostname import re ret = re.search('^http(s)?://([a-z.]+)', url) if None == 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.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL) if gtk.RESPONSE_OK != resp: return # open web browser if 'nt' == os.name: # in gtk.show_uri() avoid 'glib.GError: No application is registered as # handling this file' import webbrowser webbrowser.open(url) else: gtk.show_uri(None, url, gtk.gdk.CURRENT_TIME)
def on_btn_help__clicked(self, _button): """Preliminary help function.""" help_url = 'http://mhoffman.github.com/kmcos/doc/build/html/index.html' issues_url = 'https://github.com/mhoffman/kmcos/issues' gtk.show_uri(None, help_url, gtk.gdk.CURRENT_TIME) self.toast(('Please refer to online help at\n%s.\n\n' 'Or post issues at\n%s.') % (help_url, issues_url))
def show_uri(uri): # use gtk_show_uri if available, otherwise use gnome-vfs if hasattr(gtk, 'show_uri'): gtk.show_uri(gtk.gdk.Screen(), uri, 0) else: import gnomevfs gnomevfs.url_show(uri)
def do_search(self, searchMenu): """Launch Wikipedia search for string""" if not self.searchstring: return base_uri = "https://wikipedia.org/w/index.php?search=%s" uri = base_uri % urllib.quote(self.searchstring.encode("utf-8")) gtk.show_uri(None, uri, gtk.gdk.CURRENT_TIME)
def show_section(section, screen=None): if library.uninstalled: root = library.get_root() uri = os.path.join(root, 'docs', 'manual', 'pt_BR') if section != '': uri += '/' + section + '.page' else: if library.get_resource_exists('stoq', 'docs', 'manual', 'pt_BR'): manual_dir = library.get_resource_filename('stoq', 'docs', 'manual', 'pt_BR') if section: uri = os.path.join(manual_dir, section + '.page') else: uri = manual_dir else: uri = 'stoq' if section: uri += '?' + section if not screen: toplevel = get_current_toplevel() if toplevel: screen = toplevel.get_screen() try: gtk.show_uri(screen, 'ghelp:' + uri, gtk.get_current_event_time()) except glib.GError: open_browser( 'http://doc.stoq.com.br/manual/%s/%s.html' % ( stoq.short_version, section or 'index', ), screen)
def show_section(section, screen=None): if library.uninstalled: root = library.get_root() uri = os.path.join(root, 'docs', 'manual', 'pt_BR') if section != '': uri += '/' + section + '.page' else: if library.get_resource_exists('stoq', 'docs', 'manual', 'pt_BR'): manual_dir = library.get_resource_filename( 'stoq', 'docs', 'manual', 'pt_BR') if section: uri = os.path.join(manual_dir, section + '.page') else: uri = manual_dir else: uri = 'stoq' if section: uri += '?' + section if not screen: toplevel = get_current_toplevel() if toplevel: screen = toplevel.get_screen() try: gtk.show_uri(screen, 'ghelp:' + uri, gtk.get_current_event_time()) except glib.GError: open_browser('http://doc.stoq.com.br/manual/%s/%s.html' % ( stoq.short_version, section or 'index', ), screen)
def do_search(self, searchMenu): """Launch Github Issues search for string""" if not self.searchstring: return base_uri = "https://github.com/search?q=%s&ref=opensearch&type=Issues" uri = base_uri % urllib.quote(self.searchstring.encode("utf-8")) gtk.show_uri(None, uri, gtk.gdk.CURRENT_TIME)
def _on_help_clicked(self, widget): """Gtk+ callback""" try: gtk.show_uri(self.mainWindow.get_screen(), "ghelp:glchess", gtk.get_current_event_time()) except gobject.GError, e: # TODO: This should be a pop-up dialog print _('Unable to display help: %s') % str(e)
def files_list_w_row_activated_cb(self, widget, data=None): uri_header = "file://" selected = widget.get_selected_rows() # don't do anything if multiple files are selected if len(selected) == 1: path = selected[0].full_path gtk.show_uri(gtk.gdk.Screen(), uri_header + path, int(time.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 'posix' == os.name and 0 == os.getuid(): msg = _( "Because you are running as root, please manually open this link in a web browser:\n%s" ) % url message_dialog(None, msg, gtk.MESSAGE_INFO) return if prompt: # find hostname import re ret = re.search('^http(s)?://([a-z\.]+)', url) if None == ret: host = url else: host = ret.group(2) # TRANSLATORS: %s expands to bleachbit.sourceforge.net or similar msg = _("Open web browser to %s?") % host resp = message_dialog(parent_window, msg, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL) if gtk.RESPONSE_OK != resp: return # open web browser if 'nt' == os.name: # in gtk.show_uri() avoid 'glib.GError: No application is registered as # handling this file' import webbrowser webbrowser.open(url) else: gtk.show_uri(None, url, gtk.gdk.CURRENT_TIME)
def do_search(self, searchMenu): """Launch Google search for string""" if not self.searchstring: return base_uri = "http://www.google.com/search?q=%s" uri = base_uri % urllib.quote(self.searchstring.encode("utf-8")) gtk.show_uri(None, uri, gtk.gdk.CURRENT_TIME)
def do_url(self, about, url, data): try: gtk.show_uri(None, url, gtk.get_current_event_time()) #For GTK < 2.14 except: os.system('xdg-open %s &' % url)
def button_press(self, terminal, event): """Handles the button press event in the terminal widget. If any match string is caught, another aplication is open to handle the matched resource uri. """ self.matched_value = '' matched_string = self.match_check( int(event.x / self.get_char_width()), int(event.y / self.get_char_height())) if event.button == 1 \ and event.get_state() & gtk.gdk.CONTROL_MASK \ and matched_string: value, tag = matched_string if TERMINAL_MATCH_TAGS[tag] == 'schema': # value here should not be changed, it is right and # ready to be used. pass elif TERMINAL_MATCH_TAGS[tag] == 'http': value = 'http://%s' % value elif TERMINAL_MATCH_TAGS[tag] == 'email': value = 'mailto:%s' % value gtk.show_uri(self.window.get_screen(), value, gtk.gdk.x11_get_server_time(self.window)) elif event.button == 3 and matched_string: self.matched_value = matched_string[0]
def export_data(self): """Exports the data This method handles the export options given in the dialog and calls the ``export`` method of the choosen `export filter`_. .. _export filter: cf.plugins.core.ExportPlugin.html """ self.app.config.set("editor.export.recent_folder", self.get_current_folder()) plugin = self.get_filter().get_data("plugin") self.app.config.set("editor.export.recent_filter", plugin.id) if self.export_selection.get_property("sensitive") \ and self.export_selection.get_active(): rows = [] for i in self.selected: rows.append(self.data[i]) else: rows = self.data opts = { "filename": self.get_filename(), "uri": self.get_uri(), "query": self.statement } if self.edit_export_options.get_property("sensitive") \ and self.edit_export_options.get_active(): opts.update(plugin.show_options(self.description, rows)) plugin.export(self.description, rows, opts) if self.open_file is not None and self.open_file.get_active(): gtk.show_uri(gtk.gdk.screen_get_default(), opts['uri'], 0)
def _dialog_response_cb(dialog, resp, trace, exctyp, value): global exception_dialog_active if resp == RESPONSE_QUIT and gtk.main_level() > 0: if not quit_confirmation_func: sys.exit(1) # Exit code is important for IDEs else: if quit_confirmation_func(): sys.exit(1) # Exit code is important for IDEs else: dialog.destroy() exception_dialog_active = False elif resp == RESPONSE_SEARCH: search_url = ("https://github.com/mypaint/mypaint/search" "?utf8=%E2%9C%93" "&q={}+{}" "&type=Issues").format(quote_plus(exctyp.__name__, "/"), quote_plus(str(value), "/")) gtk.show_uri(None, search_url, gtk.gdk.CURRENT_TIME) if "-" in lib.meta.MYPAINT_VERSION: dialog.set_response_sensitive(RESPONSE_REPORT, True) elif resp == RESPONSE_REPORT: #TRANSLATORS: Crash report template for github, preceding a traceback. #TRANSLATORS: Please ask users kindly to supply at least an English #TRANSLATORS: title if they are able. body = _(u"""\ #### Description Give this report a short descriptive title. Use something like "{feature-that-broke}: {what-went-wrong}" for the title, if you can. Then please replace this text with a longer description of the bug. Screenshots or videos are great, too! #### Steps to reproduce Please tell us what you were doing when the error message popped up. If you can provide step-by-step instructions on how to reproduce the bug, that's even better. #### Traceback """) body = "\n\n".join([ "".join(textwrap.wrap(p, sys.maxint)) for p in textwrap.dedent(body).split("\n\n") ] + [trace]) report_url = ("https://github.com/mypaint/mypaint/issues/new" "?title={title}" "&body={body}").format( title="", body=quote_plus(body.encode("utf-8"), "/"), ) gtk.show_uri(None, report_url, gtk.gdk.CURRENT_TIME) else: dialog.destroy() exception_dialog_active = False
def showConsoleOutput(self, *args, **kwargs): """ Launch browser on last build's console output """ if not hasattr(self, "lastCompletedBuild"): #todo display error dialog return url = urlparse.urljoin(self.lastCompletedBuild["url"], "console") gtk.show_uri(DEFAULT_SCREEN, url, int(time.time()))
def __download_p2plink (self, result, albumid): if result is None: emsg = _("Error looking up p2plink for album %s on jamendo.com") % (albumid) gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, emsg).run() return gtk.show_uri(self.props.shell.props.window.get_screen(), result, gtk.gdk.CURRENT_TIME)
def navigation_request_cb(self, view, frame, request): # open HTTP URIs externally. this isn't a web browser. if request.get_uri().startswith('http'): print "opening uri %s" % request.get_uri() gtk.show_uri(self.shell.props.window.get_screen(), request.get_uri(), gtk.gdk.CURRENT_TIME) return 1 # WEBKIT_NAVIGATION_RESPONSE_IGNORE else: return 0 # WEBKIT_NAVIGATION_RESPONSE_ACCEPT
def on_plugins_window_response(self, dialog, response): if response == gtk.RESPONSE_DELETE_EVENT or response == gtk.RESPONSE_CLOSE: dialog.destroy() glipper.GCONF_CLIENT.notify_remove(self.autostart_plugins_notify) PluginsWindow.__instance = None elif response == gtk.RESPONSE_HELP: gtk.show_uri(None, 'ghelp:glipper?plugins', gtk.gdk.CURRENT_TIME)
def on_imagemenuitem_help_activate(self, widget): """ Open TextFlow documentation in a browser. @param widget: Reference to a ImageMenuItem. @type widget: A ImageMenuItem object. """ gtk.show_uri(gtk.gdk.Screen(), "http://docs.textflowproject.org", 0)
def show_uri(self, uri): if sys.platform == 'win32': os.startfile(uri) elif sys.platform == 'darwin': os.spawnl(os.P_NOWAIT, '/usr/bin/open', uri) else: gtk.show_uri(gtk.gdk.screen_get_default(), uri, gtk.get_current_event_time())
def do_upload(self, searchMenu): """Launch Hastebin with the url""" if not self.searchstring: return base_uri = "http://hastebin.com" resp = requests.post(base_uri + "/documents", data=self.searchstring) rdict = json.loads(resp.text) gtk.show_uri(None, base_uri + "/" + rdict['key'], gtk.gdk.CURRENT_TIME)
def _open_link(self,linkTag,widget,event,iterator): if event.type == gtk.gdk.BUTTON_PRESS: begin = iterator.copy() begin.backward_to_tag_toggle(linkTag) end = iterator end.forward_to_tag_toggle(linkTag) gtk.show_uri(gtk.gdk.screen_get_default(), self.messageBuffer.get_text(begin,end,False), 0)
def on_open (self, action): """ Open item clicked in the menu will open the project page """ titer = self.model.get_iter (self.path) if titer: url = self.model.get_value (titer, self.COL_URL) gtk.show_uri (self.window.get_screen(), url, 0)
def _url_handler(self, url): self.frontend.info('Url activated : ' + url) if self._is_url(url): # just to be sure and prevent shell injection rc = call("xdg-open %s"%url, shell=True) if rc != 0: # failover to gtk.show_uri, if xdg-open fails or is not installed gtk.show_uri(None, url, gtk.gdk.CURRENT_TIME) else: self.frontend.warning("%s is not an url" % url)
def open_url(self, widget, url): if url.strip() != '': try: gtk.show_uri(None, url, gtk.get_current_event_time()) #For GTK < 2.14 except: os.system('xdg-open "%s" &' % url)
def __init_ui(self): self.menu = gtk.Menu() self.database_item = gtk.MenuItem(_('Database')) self.database_item.show() self.database_item.set_sensitive(False) self.unlock_item = gtk.MenuItem(_('Unlock File')) self.unlock_item.show() self.unlock_item.connect( 'activate', lambda w, d=None: self.file_open(self.config.get("file")) ) self.lock_item = gtk.MenuItem(_('Lock File')) self.lock_item.connect( 'activate', lambda w, d=None: self.file_close() ) self.prefs_item = gtk.MenuItem(_('Preferences')) self.prefs_item.show() self.prefs_item.connect( 'activate', lambda w, d=None: self.prefs() ) self.about_item = gtk.MenuItem(_('About')) self.about_item.show() self.about_item.connect('activate', self.__cb_about) self.quit_item = gtk.MenuItem('Quit') self.quit_item.show() self.quit_item.connect('activate', gtk.main_quit) self.menu.append(self.database_item) self.menu.append(gtk.SeparatorMenuItem()) self.menu.append(self.unlock_item) self.menu.append(self.lock_item) self.menu.append(gtk.SeparatorMenuItem()) self.menu.append(self.prefs_item) self.menu.append(self.about_item) self.menu.append(self.quit_item) self.ind.set_menu(self.menu) #self.menu.show_all() gtk.about_dialog_set_url_hook( lambda d, l: gtk.show_uri(None, l, gtk.get_current_event_time()) ) gtk.about_dialog_set_email_hook( lambda d, l: gtk.show_uri(None, "mailto:" + l, gtk.get_current_event_time()) ) ## set up various ui element holders self.popup_entryview = None self.popup_entrylist = None
def show_user_manual(): time_now = int(time.time()) for uri in (APPMANUALURL_OFFLINE, APPMANUALURL_ONLINE): try: gtk.show_uri(None, uri, time_now) return except Exception, e: log.debug("utils", "Failed loading URI %s: %s", uri, e) continue
def on_documentation (self, *args): import gobject timestamp = gtk.gdk.CURRENT_TIME try: gtk.show_uri (None, "help:pybliographer", timestamp) except gobject.GError, msg: Utils.error_dialog_s(_(u"Can’t display documentation:\n%s") % msg)
def show_uri(self, uri): if sys.platform=='win32': os.startfile(uri) elif sys.platform == 'darwin': os.spawnl(os.P_NOWAIT, '/usr/bin/open', uri) else: gtk.show_uri(gtk.gdk.screen_get_default(), uri, gtk.get_current_event_time())
def show_url(url): """Open any @url with default viewer""" from gtk import show_uri, get_current_event_time from gtk.gdk import screen_get_default from glib import GError try: show_uri(screen_get_default(), url, get_current_event_time()) except GError, e: logger.error("Error in gtk.show_uri: " + e)
def on_documentation (self, *args): import gobject timestamp = gtk.gdk.CURRENT_TIME try: gtk.show_uri (None, "ghelp:pybliographer", timestamp) except gobject.GError, msg: self.w.error (_("Can't display documentation:\n%s") % msg)
def onClick(self, widget, event, applet): if event.type == gtk.gdk.BUTTON_PRESS: if event.button == MOUSE_RIGHT_BUTTON: widget.emit_stop_by_name("button_press_event") self.createRightClickMenu(widget, event, applet) elif event.button == MOUSE_LEFT_BUTTON: widget.emit_stop_by_name("button_press_event") url = self.preferences.jenkinsURL gtk.show_uri(DEFAULT_SCREEN, url, event.time)
def __on_help_button_clicked (self, widget, data=None): if os.name == "posix": try: gtk.show_uri(None , "ghelp:nanny", gtk.get_current_event_time()) except: os.system("yelp ghelp:nanny") elif os.name == "nt": win32api.ShellExecute(None, "open", "http://library.gnome.org/users/nanny/stable/", None, None, win32con.SW_SHOWNORMAL)
def _do_show_help(self, src, index): try: uri = "ghelp:%s" % self.config.get_appname() if index: uri += "#%s" % index logging.debug("Showing help for %s", uri) gtk.show_uri(None, uri, gtk.get_current_event_time()) except Exception, e: src.err.show_err(_("Unable to display documentation: %s") % e)
def open_uri(uri, timestamp=0): try: gtk.show_uri(gtk.gdk.screen_get_default(), uri, timestamp) except gio.Error: if uri.startswith("http://"): import webbrowser webbrowser.open_new_tab(uri) else: # Unhandled URI pass
def show_uri(self, dialog, link): """open a uri.""" # TODO: according to the docs at: # http://www.pygtk.org/docs/pygtk/class-gtkmountoperation.html#function-gtk--show-uri # the constant: gtk.gdk.CURRENT_TIME should exist but doesn't. # find out how to get it and put it in the function below. maybe # the latest version of pygtk will fix this. we should also be # able to remove self.about.get_screen() and replace with: None. self.log.debug('showing uri: %s' % link) gtk.show_uri(dialog.get_screen(), link, 0)
def on_response (self, dialog, response): """ Dialog response will open the Help if necessary, otherwise save the configuration. """ if response == gtk.RESPONSE_HELP: gtk.show_uri (self.window.get_screen(), "ghelp:freespeak?freespeak-prefs", 0) return self.write_config () self.destroy()
def on_manual_menu_activate(self, *args): try: gtk.show_uri(None, 'ghelp:gnome-schedule', 0) except gobject.GError, error: dialog = gtk.MessageDialog(self.widget, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE) dialog.set_markup("<b>" + _("Could not display help") + "</b>") dialog.format_secondary_text("%s" % error) dialog.run() dialog.destroy()
def launch_in_browser(page): # The difficulty here is that the default open method for local files may not be # a browser (even with python webbrowser module). That's why we try first to read # the gconf key try: import gconf client = gconf.client_get_default() prog = client.get_string("/desktop/gnome/url-handlers/http/command") subprocess.Popen(prog % page, shell=True) except: gtk.show_uri(None, "file:///"+page, int(time.time()))
def upload_done_cb(self, success, url): """Open the uploaded photos redirection website.""" if url: gtk.show_uri(gtk.gdk.screen_get_default(), url, gtk.get_current_event_time()) if success: self.preview_window.emit('close') else: self.preview_window.alert('Upload to Flickr failed!', exit_on_close=True)
def openUrl(self, url): # check if the device module handles URL opening if self.modrana.dmod.handles_url_opening: self.modrana.dmod.open_url(url) else: try: gtk.show_uri(None, url, gtk.gdk.CURRENT_TIME) except Exception: self.log.exception("calling gtk.show_uri() failed, probably due to old GTK version") self.log.warning("using the webbrowser module as fallback") import webbrowser webbrowser.open(url)
def on_button_press(self, widget, event): # on double clicks, open the cover image (if there is one) in the default # image viewer if event.type != gtk.gdk._2BUTTON_PRESS or event.button != 1: return if self.art_widget.current_uri is None: return f = gio.File(self.art_widget.current_uri) gtk.show_uri(self.shell.props.window.get_screen(), f.get_uri(), event.time)
def display_artist_info(self): screen = self.props.shell.props.window.get_screen() tracks = self.get_entry_view().get_selected_entries() urls = set([]) for tr in tracks: sku = self.__sku_dict[self.__db.entry_get(tr, rhythmdb.PROP_LOCATION)] url = self.__home_dict[sku] if url not in urls: gtk.show_uri(screen, url, gtk.gdk.CURRENT_TIME) urls.add(url)