def show_popup(self, status_icon, button, activate_time): """ Create the popupmenu """ ## From the PyGTK 2.10 documentation # status_icon : the object which received the signal # button : the button that was pressed, or 0 if the signal is not emitted in response to a button press event # activate_time : the timestamp of the event that triggered the signal emission # Create menu items if self.specto.specto_gconf.get_entry("always_show_icon") and self.specto.notifier.get_state(): self.item_show = create_menu_item(_("Hide window"), self.show_notifier, None) else: self.item_show = create_menu_item(_("Show window"), self.show_notifier, None) self.item_pref = create_menu_item(gtk.STOCK_PREFERENCES, self.show_preferences, gtk.STOCK_PREFERENCES) self.item_help = create_menu_item(gtk.STOCK_HELP, self.show_help, gtk.STOCK_HELP) self.item_about = create_menu_item(gtk.STOCK_ABOUT, self.show_about, gtk.STOCK_ABOUT) self.item_quit = create_menu_item(gtk.STOCK_QUIT, self.quit, gtk.STOCK_QUIT) self.item_clear = create_menu_item(_("Mark as read"), None, None) self.item_refresh = create_menu_item(_("Refresh All"), self.refresh, gtk.STOCK_REFRESH) # create submenu for changed watches self.sub_menu = gtk.Menu() self.sub_item_clear = create_menu_item( _("_Mark all read"), self.specto.notifier.mark_all_as_read, gtk.STOCK_CLEAR ) self.sub_menu.append(self.sub_item_clear) self.sub_menu.append(gtk.SeparatorMenuItem()) for watch in self.specto.watch_db: if watch.changed == True: image = gtk.image_new_from_pixbuf(self.notifier.get_icon(watch.icon, 0, False)) self.sub_item_clear = create_menu_item(watch.name, None, image) self.sub_item_clear.connect("activate", self.specto.notifier.mark_watch_as_read, watch.id) self.sub_menu.append(self.sub_item_clear) self.sub_menu.show_all() self.item_clear.set_submenu(self.sub_menu) # Create the menu self.menu = gtk.Menu() # Append menu items to the menu self.menu.append(self.item_show) self.menu.append(gtk.SeparatorMenuItem()) self.menu.append(self.item_refresh) self.menu.append(self.item_clear) self.menu.append(gtk.SeparatorMenuItem()) self.menu.append(self.item_pref) self.menu.append(self.item_help) self.menu.append(self.item_about) self.menu.append(gtk.SeparatorMenuItem()) self.menu.append(self.item_quit) self.menu.show_all() self.menu.popup( None, None, gtk.status_icon_position_menu, button, activate_time, self.tray ) # the last argument is to tell gtk.status_icon_position_menu where to grab the coordinates to position the popup menu correctly
def create_menu(self, window, event, data=None): model, iter = self.treeview.get_selection().get_selected() id = int(model.get_value(iter, 3)) watch = self.specto.watch_db[id] menu = gtk.Menu() menuItem = None menuItem = create_menu_item(_("Refresh"), self.refresh_watch, gtk.STOCK_REFRESH) if not watch.active: menuItem.set_sensitive(False) menu.append(menuItem) menuItem = create_menu_item(_("Mark as read"), self._mark_watch_as_read, gtk.STOCK_CLEAR) if not watch.changed: menuItem.set_sensitive(False) menu.append(menuItem) separator = gtk.SeparatorMenuItem() menu.append(separator) menuItem = create_menu_item(_("Edit"), self.edit_watch, gtk.STOCK_EDIT) menu.append(menuItem) menuItem = create_menu_item(_("Remove"), self.remove_watch, gtk.STOCK_REMOVE) menu.append(menuItem) menu.show_all() return menu