def show(self, widget, event=None): """Display the context menu""" terminal = self.terminal menu = Gtk.Menu() self.popup_menu = menu url = None button = None time = None self.config.set_profile(terminal.get_profile()) if event: url = terminal.vte.match_check_event(event) button = event.button time = event.time else: time = 0 button = 3 if url and url[0]: dbg("URL matches id: %d" % url[1]) if not url[1] in terminal.matches.values(): err("Unknown URL match id: %d" % url[1]) dbg("Available matches: %s" % terminal.matches) nameopen = None namecopy = None if url[1] == terminal.matches['email']: nameopen = _('_Send email to...') namecopy = _('_Copy email address') elif url[1] == terminal.matches['voip']: nameopen = _('Ca_ll VoIP address') namecopy = _('_Copy VoIP address') elif url[1] in terminal.matches.values(): # This is a plugin match for pluginname in terminal.matches: if terminal.matches[pluginname] == url[1]: break dbg("Found match ID (%d) in terminal.matches plugin %s" % (url[1], pluginname)) registry = plugin.PluginRegistry() registry.load_plugins() plugins = registry.get_plugins_by_capability('url_handler') for urlplugin in plugins: if urlplugin.handler_name == pluginname: dbg("Identified matching plugin: %s" % urlplugin.handler_name) nameopen = _(urlplugin.nameopen) namecopy = _(urlplugin.namecopy) break if not nameopen: nameopen = _('_Open link') if not namecopy: namecopy = _('_Copy address') icon = Gtk.Image.new_from_stock(Gtk.STOCK_JUMP_TO, Gtk.IconSize.MENU) item = Gtk.ImageMenuItem.new_with_mnemonic(nameopen) item.set_property('image', icon) item.connect('activate', lambda x: terminal.open_url(url, True)) menu.append(item) item = Gtk.MenuItem.new_with_mnemonic(namecopy) item.connect( 'activate', lambda x: terminal.clipboard.set_text( terminal.prepare_url(url), len(terminal.prepare_url(url)))) menu.append(item) menu.append(Gtk.SeparatorMenuItem()) item = Gtk.ImageMenuItem.new_with_mnemonic(_('_Copy')) item.connect('activate', lambda x: terminal.vte.copy_clipboard()) item.set_sensitive(terminal.vte.get_has_selection()) menu.append(item) item = Gtk.ImageMenuItem.new_with_mnemonic(_('_Paste')) item.connect('activate', lambda x: terminal.paste_clipboard()) menu.append(item) menu.append(Gtk.SeparatorMenuItem()) if not terminal.is_zoomed(): item = Gtk.ImageMenuItem.new_with_mnemonic( _('Split H_orizontally')) image = Gtk.Image() image.set_from_icon_name(APP_NAME + '_horiz', Gtk.IconSize.MENU) item.set_image(image) if hasattr(item, 'set_always_show_image'): item.set_always_show_image(True) item.connect( 'activate', lambda x: terminal.emit('split-horiz', self.terminal.get_cwd())) menu.append(item) item = Gtk.ImageMenuItem.new_with_mnemonic(_('Split V_ertically')) image = Gtk.Image() image.set_from_icon_name(APP_NAME + '_vert', Gtk.IconSize.MENU) item.set_image(image) if hasattr(item, 'set_always_show_image'): item.set_always_show_image(True) item.connect( 'activate', lambda x: terminal.emit('split-vert', self.terminal.get_cwd())) menu.append(item) item = Gtk.MenuItem.new_with_mnemonic(_('Open _Tab')) item.connect('activate', lambda x: terminal.emit('tab-new', False, terminal)) menu.append(item) if self.terminator.debug_address is not None: item = Gtk.MenuItem.new_with_mnemonic(_('Open _Debug Tab')) item.connect( 'activate', lambda x: terminal.emit('tab-new', True, terminal)) menu.append(item) menu.append(Gtk.SeparatorMenuItem()) item = Gtk.ImageMenuItem.new_with_mnemonic(_('_Close')) item.connect('activate', lambda x: terminal.close()) menu.append(item) menu.append(Gtk.SeparatorMenuItem()) if not terminal.is_zoomed(): sensitive = not terminal.get_toplevel() == terminal.get_parent() item = Gtk.MenuItem.new_with_mnemonic(_('_Zoom terminal')) item.connect('activate', terminal.zoom) item.set_sensitive(sensitive) menu.append(item) item = Gtk.MenuItem.new_with_mnemonic(_('Ma_ximize terminal')) item.connect('activate', terminal.maximise) item.set_sensitive(sensitive) menu.append(item) menu.append(Gtk.SeparatorMenuItem()) else: item = Gtk.MenuItem.new_with_mnemonic(_('_Restore all terminals')) item.connect('activate', terminal.unzoom) menu.append(item) menu.append(Gtk.SeparatorMenuItem()) if self.config['show_titlebar'] == False: item = Gtk.MenuItem.new_with_mnemonic(_('Grouping')) submenu = self.terminal.populate_group_menu() submenu.show_all() item.set_submenu(submenu) menu.append(item) menu.append(Gtk.SeparatorMenuItem()) item = Gtk.CheckMenuItem.new_with_mnemonic(_('Show _scrollbar')) item.set_active(terminal.scrollbar.get_property('visible')) item.connect('toggled', lambda x: terminal.do_scrollbar_toggle()) menu.append(item) item = gtk.CheckMenuItem(_('Toggle tab visibility')) item.set_active(terminal.scrollbar.get_property('visible')) item.connect('toggled', self.toggle_tab_visibility) menu.append(item) if hasattr(Gtk, 'Builder'): # VERIFY FOR GTK3: is this ever false? item = Gtk.MenuItem.new_with_mnemonic(_('_Preferences')) item.connect('activate', lambda x: PrefsEditor(self.terminal)) menu.append(item) profilelist = sorted(self.config.list_profiles(), key=string.lower) if len(profilelist) > 1: item = Gtk.MenuItem.new_with_mnemonic(_('Profiles')) submenu = Gtk.Menu() item.set_submenu(submenu) menu.append(item) current = terminal.get_profile() group = None for profile in profilelist: profile_label = profile if profile_label == 'default': profile_label = profile.capitalize() item = Gtk.RadioMenuItem(profile_label, group) if profile == current: item.set_active(True) item.connect('activate', terminal.force_set_profile, profile) submenu.append(item) self.add_encoding_items(menu) try: menuitems = [] registry = plugin.PluginRegistry() registry.load_plugins() plugins = registry.get_plugins_by_capability('terminal_menu') for menuplugin in plugins: menuplugin.callback(menuitems, menu, terminal) if len(menuitems) > 0: menu.append(Gtk.SeparatorMenuItem()) for menuitem in menuitems: menu.append(menuitem) except Exception, ex: err('TerminalPopupMenu::show: %s' % ex)
def loadPluginsAndWebApps(self): # First read all plugins, the webapps depend on them. self.plugins = plugin.PluginRegistry() self.plugins.load(self) # Check if a dirlister plugin is present. If not, install the default. if not 'DirLister' in self.plugins.getPluginNames(): self.plugins.addPlugin(None, DefaultDirListerPlugin()) # Now read the webapps. Start with the virtual host config. try: vhostconfig = __import__(self.WEBAPPSDIR) if vhostconfig.ENABLED: if vhostconfig.virtualhosts is None or vhostconfig.webroots is None or vhostconfig.defaultvhost is None or vhostconfig.aliases is None: raise ImportError( "not everything is configured in the vhost config") except ImportError: log.error("no correct virtual host config found!") log.error( "Please read and edit the __init__.py file in the webapps directory." ) raise InvalidConfigurationException if not vhostconfig.ENABLED: log.warn("\NOTICE: VirtualHost configuration is NOT enabled.") log.warn( "Defaulting to loading all available web apps to the current host." ) vhost = self.server_address[0] or socket.gethostname() webapps = [ app for app in os.listdir(self.WEBAPPSDIR) if os.path.isdir(os.path.join(self.WEBAPPSDIR, app)) ] if 'CVS' in webapps and os.access( os.path.join(self.WEBAPPSDIR, 'CVS', 'Entries'), os.R_OK): webapps.remove('CVS') # ignore CVS directory if '.svn' in webapps and os.access( os.path.join(self.WEBAPPSDIR, '.svn', 'entries'), os.R_OK): webapps.remove('.svn') # ignore Subversion directory vhostconfig.virtualhosts = {vhost: webapps} vhostconfig.webroots = {} if 'ROOT' in webapps: vhostconfig.webroots = {vhost: 'ROOT'} webapps.remove('ROOT') vhostconfig.aliases = {} vhostconfig.defaultvhost = vhost self.useVirtualHosts = False # do some sanity checks if vhostconfig.defaultvhost not in vhostconfig.virtualhosts: raise ValueError("invalid default virtualhost specified: " + vhostconfig.defaultvhost) for vhost in vhostconfig.aliases.values(): if vhost not in vhostconfig.virtualhosts and vhost not in vhostconfig.webroots: raise ValueError("invalid vhost specified in aliases: " + vhost) if vhost in vhostconfig.aliases: raise ValueError("alias cycle: " + vhost) invalidAliases = [ vhost for vhost in vhostconfig.aliases.keys() if vhost in vhostconfig.virtualhosts or vhost in vhostconfig.webroots ] if invalidAliases: raise ValueError("aliases defined for true vhosts: " + str(invalidAliases)) for webroothost in vhostconfig.webroots: if webroothost not in vhostconfig.virtualhosts: raise ValueError("web root host is not a known virtualhost: " + webroothost) self.vhostAliases = vhostconfig.aliases self.allWebApps.clear() self.defaultVirtualHost = ( vhostconfig.defaultvhost, self.externalPort ) # XXX server port is static for now (no multiple connectors) webappsAlreadyPrecompiled = [ ] # list of webapps whose Ypages have already been precompiled. # scan regular web applications self.virtualHosts.clear() for (virtualhost, webapps) in vhostconfig.virtualhosts.iteritems(): log.info("Processing virtual host '%s'" % virtualhost) if type(webapps) not in (list, tuple): raise ValueError( "mapping value must be list of webapp names, but it isn't. vhost='%s'" % virtualhost) self.virtualHosts[virtualhost] = [] webapps = list(webapps) for webname in webapps: log.info("Loading webapp '%s'" % webname) if webapps.count(webname) > 1: raise ValueError( "Web application '%s' occurs more than once for vhost '%s'" % (webname, virtualhost)) WA = self.readWebApp(webname, virtualhost, isRoot=False) if WA: if self.precompileYPages: if webname not in webappsAlreadyPrecompiled: WA.precompileYPages() webappsAlreadyPrecompiled.append(webname) else: log.debug("(already precompiled all Ypages)") log.info("Got webapp: " + str(WA)) self._registerWebApp(virtualhost, WA, isRoot=False) # scan root web applications self.webRoots.clear() for (virtualhost, webname) in vhostconfig.webroots.iteritems(): if webname: log.info("Processing virtual host '%s' root webapp '%s'" % (virtualhost, webname)) WA = self.readWebApp(webname, virtualhost, isRoot=True) if WA: if self.precompileYPages: if webname not in webappsAlreadyPrecompiled: WA.precompileYPages() webappsAlreadyPrecompiled.append(webname) else: log.debug("(already precompiled all Ypages)") log.debug("Got webapp: " + str(WA)) self._registerWebApp(virtualhost, WA, isRoot=True) log.info("Default virtual host: %s:%d" % self.defaultVirtualHost) log.info("%d webapps registered." % len(self.allWebApps)) if not self.allWebApps: print >> sys.stderr, "There are no webapps!" raise InvalidConfigurationException
def show(self, widget, event=None): """Display the context menu""" terminal = self.terminal menu = gtk.Menu() url = None button = None time = None self.config.set_profile(terminal.get_profile()) if event: url = terminal.check_for_url(event) button = event.button time = event.time else: time = 0 button = 3 if url: if url[1] == terminal.matches['email']: nameopen = _('_Send email to...') namecopy = _('_Copy email address') elif url[1] == terminal.matches['voip']: nameopen = _('Ca_ll VoIP address') namecopy = _('_Copy VoIP address') else: nameopen = _('_Open link') namecopy = _('_Copy address') icon = gtk.image_new_from_stock(gtk.STOCK_JUMP_TO, gtk.ICON_SIZE_MENU) item = gtk.ImageMenuItem(nameopen) item.set_property('image', icon) item.connect('activate', lambda x: terminal.open_url(url, True)) menu.append(item) item = gtk.MenuItem(namecopy) item.connect('activate', lambda x: terminal.clipboard.set_text(url[0])) menu.append(item) menu.append(gtk.MenuItem()) item = gtk.ImageMenuItem(gtk.STOCK_COPY) item.connect('activate', lambda x: terminal.vte.copy_clipboard()) item.set_sensitive(terminal.vte.get_has_selection()) menu.append(item) item = gtk.ImageMenuItem(gtk.STOCK_PASTE) item.connect('activate', lambda x: terminal.paste_clipboard()) menu.append(item) menu.append(gtk.MenuItem()) if not terminal.is_zoomed(): item = gtk.ImageMenuItem(_('Split H_orizontally')) image = gtk.Image() image.set_from_icon_name(APP_NAME + '_horiz', gtk.ICON_SIZE_MENU) item.set_image(image) if hasattr(item, 'set_always_show_image'): item.set_always_show_image(True) item.connect('activate', lambda x: terminal.emit('split-horiz', self.terminator.pid_cwd(self.terminal.pid))) menu.append(item) item = gtk.ImageMenuItem(_('Split V_ertically')) image = gtk.Image() image.set_from_icon_name(APP_NAME + '_vert', gtk.ICON_SIZE_MENU) item.set_image(image) if hasattr(item, 'set_always_show_image'): item.set_always_show_image(True) item.connect('activate', lambda x: terminal.emit('split-vert', self.terminator.pid_cwd(self.terminal.pid))) menu.append(item) item = gtk.MenuItem(_('Open _Tab')) item.connect('activate', lambda x: terminal.emit('tab-new', False, terminal)) menu.append(item) if self.terminator.debug_address is not None: item = gtk.MenuItem(_('Open _Debug Tab')) item.connect('activate', lambda x: terminal.emit('tab-new', True, terminal)) menu.append(item) menu.append(gtk.MenuItem()) item = gtk.ImageMenuItem(gtk.STOCK_CLOSE) item.connect('activate', lambda x: terminal.close()) menu.append(item) menu.append(gtk.MenuItem()) if not terminal.is_zoomed(): item = gtk.MenuItem(_('_Zoom terminal')) item.connect('activate', terminal.zoom) menu.append(item) item = gtk.MenuItem(_('Ma_ximise terminal')) item.connect('activate', terminal.maximise) menu.append(item) menu.append(gtk.MenuItem()) else: item = gtk.MenuItem(_('_Restore all terminals')) item.connect('activate', terminal.unzoom) menu.append(item) menu.append(gtk.MenuItem()) if self.config['show_titlebar'] == False: item = gtk.MenuItem(_('Grouping')) submenu = self.terminal.populate_group_menu() submenu.show_all() item.set_submenu(submenu) menu.append(item) menu.append(gtk.MenuItem()) item = gtk.CheckMenuItem(_('Show _scrollbar')) item.set_active(terminal.scrollbar.get_property('visible')) item.connect('toggled', lambda x: terminal.do_scrollbar_toggle()) menu.append(item) if hasattr(gtk, 'Builder'): item = gtk.MenuItem(_('_Preferences')) item.connect('activate', lambda x: PrefsEditor(self.terminal)) menu.append(item) profilelist = self.config.list_profiles() if len(profilelist) > 1: item = gtk.MenuItem(_('Profiles')) submenu = gtk.Menu() item.set_submenu(submenu) menu.append(item) current = terminal.get_profile() group = None for profile in profilelist: item = gtk.RadioMenuItem(group, profile.capitalize()) if profile == current: item.set_active(True) item.connect('activate', terminal.force_set_profile, profile) submenu.append(item) self.add_encoding_items(menu) try: menuitems = [] registry = plugin.PluginRegistry() registry.load_plugins() plugins = registry.get_plugins_by_capability('terminal_menu') for menuplugin in plugins: menuplugin.callback(menuitems, menu, terminal) if len(menuitems) > 0: menu.append(gtk.MenuItem()) for menuitem in menuitems: menu.append(menuitem) except Exception, ex: err('TerminalPopupMenu::show: %s' % ex)