1"""A GTK dialog which displays a list of Zero Install applications in the menu.""" 2# Copyright (C) 2009, Thomas Leonard 3# See the README file for details, or visit http://0install.net. 4 5fromzeroinstallimport_,gobject 6importos,sys 7importgtk,pango 8importsubprocess 9 10fromzeroinstallimportsupport 11fromzeroinstall.gtkuiimporticon,xdgutils 12fromzeroinstall.injectorimportreader,model,namespaces 13 14gtk2=sys.version_info[0]<3 15
20"""A list of applications which can be displayed in an L{AppListBox}. 21 For example, a program might implement this to display a list of plugins. 22 This default implementation lists applications in the freedesktop.org menus. 23 """
30"""Remove this application from the list.""" 31path=self.apps[uri] 32os.unlink(path)
33 34_tooltips={ 350:_("Run the application"), 361:_("Show documentation files"), 372:_("Upgrade or change versions"), 383:_("Remove launcher from the menu"), 39} 40
115tv.connect('query-tooltip',query_tooltip)116117defleave(widget,lev):118redraw_actions(cell_actions.hover[0])119cell_actions.hover=(None,None,None)120121tv.connect('leave-notify-event',leave)122123self.model.set_sort_column_id(AppListBox.NAME,gtk.SORT_ASCENDING)124125show_cache=builder.get_object('show_cache')126self.window.action_area.set_child_secondary(show_cache,True)127128defresponse(box,resp):129ifresp==0:# Show Cache130subprocess.Popen(['0store','manage'])131elifresp==1:# Add132fromzeroinstall.gtkui.addboximportAddBox133box=AddBox()134box.window.connect('destroy',lambdadialog:self.populate_model())135box.window.show()136else:137box.destroy()138self.window.connect('response',response)139
200fromzeroinstall.injector.configimportload_config201fromzeroinstallimporthelpers202c=load_config()203sels=helpers.ensure_cached(uri,config=c)204ifnotsels:205return206207impl=sels.selections[uri]208assertimpl,"Failed to choose an implementation of %s"%uri209help_dir=impl.attrs.get('doc-dir')210211ifimpl.id.startswith('package:'):212assertos.path.isabs(help_dir),"Package doc-dir must be absolute!"213path=help_dir214else:215path=impl.local_pathorc.stores.lookup_any(impl.digests)216217assertpath,"Chosen implementation is not cached!"218ifhelp_dir:219path=os.path.join(path,help_dir)220else:221main=impl.main222ifmain:223# Hack for ROX applications. They should be updated to224# set doc-dir.225help_dir=os.path.join(path,os.path.dirname(main),'Help')226ifos.path.isdir(help_dir):227path=help_dir228229# xdg-open has no "safe" mode, so check we're not "opening" an application.230ifos.path.exists(os.path.join(path,'AppRun')):231raiseException(_("Documentation directory '%s' is an AppDir; refusing to open")%path)232233subprocess.Popen(['xdg-open',path])
239try:240name=self.iface_cache.get_interface(uri).get_name()241exceptmodel.InvalidInterface:242name=uri243244box=gtk.MessageDialog(self.window,gtk.DIALOG_MODAL,gtk.MESSAGE_QUESTION,gtk.BUTTONS_CANCEL,"")245box.set_markup(_("Remove <b>%s</b> from the menu?")%_pango_escape(name))246box.add_button(gtk.STOCK_DELETE,gtk.RESPONSE_OK)247box.set_default_response(gtk.RESPONSE_OK)248resp=box.run()249box.destroy()250ifresp==gtk.RESPONSE_OK:251try:252self.app_list.remove_app(uri)253exceptExceptionasex:254box=gtk.MessageDialog(self.window,gtk.DIALOG_MODAL,gtk.MESSAGE_ERROR,gtk.BUTTONS_OK,_("Failed to remove %(interface_name)s: %(exception)s")%{'interface_name':name,'exception':ex})255box.run()256box.destroy()257self.populate_model()
265"@param widget: widget used for style information"266gtk.GenericCellRenderer.__init__(self)267self.set_property('mode',gtk.CELL_RENDERER_MODE_ACTIVATABLE)268self.padding=4269270self.applist=applist271272self.size=10273defstock_lookup(name):274pixbuf=widget.render_icon(name,gtk.ICON_SIZE_BUTTON)275self.size=max(self.size,pixbuf.get_width(),pixbuf.get_height())276returnpixbuf