def _on_button_release_event(self, widget, event): """ Open menu on right click """ if not event.button == 3: return selection = self.get_selection() model, iter = selection.get_selected() self._popup = Gtk.Menu() # Program url url = create_menuitem(_("Program page"), "web-browser") url.set_size_request(100, -1) event_url = model.get_value(iter, 4) url.connect("activate", self._on_url, event_url) self._popup.append(url) if model.get_value(iter, 1): # Play program if not model.get_value(iter, 12): play = create_menuitem(_("Play program"), "media-playback-start") else: play = create_menuitem(_("Don't play"), "gtk-cancel") play.connect("activate", self._on_play, model, iter) self._popup.append(play) # Record program if not model.get_value(iter, 11): rec = create_menuitem(_("Record program"), "media-record") else: rec = create_menuitem(_("Don't record"), "gtk-cancel") rec.connect("activate", self._on_record, model, iter) self._popup.append(rec) self._popup.show_all() self._popup.popup(None, None, None, None, event.button, event.time)
def _popup_menu_create(self): """ Show menu on right click """ popup_menu = Gtk.Menu() if APP_INDICATOR: # Since appindicator doesn't support left click event activate = Gtk.MenuItem(_("Activate")) activate.connect("activate", self._on_activate) popup_menu.append(activate) separator = Gtk.SeparatorMenuItem() popup_menu.append(separator) # Playback text, icon = get_playback_label(not self._playing) play = create_menuitem(text, icon) play.connect("activate", self._on_playback) play.set_size_request(100, -1) # Record text, icon = get_record_label(not self._recording) record = create_menuitem(text, icon) record.connect("activate", self._on_recorder) # Mute mute = Gtk.CheckMenuItem(_("Mute")) mute.set_active(self._muted) mute.connect("toggled", self._on_mute) # IM im = create_menuitem(_("Send message"), "gtk-edit") im.connect("activate", self._on_im) # Preferences preferences = create_menuitem(_("Preferences"), "gtk-preferences") preferences.connect("activate", self._on_prefs) # Quit quit = create_menuitem(_("Quit"), "gtk-quit") quit.connect("activate", self._on_quit) # Separator sep = [] for i in range(4): sep.append(Gtk.SeparatorMenuItem()) # Pack for item in [play, record, sep[0], mute, sep[1], im, sep[2], preferences, sep[3], quit]: popup_menu.append(item) popup_menu.show_all() return popup_menu
def __init__(self, app): Gtk.MenuBar.__init__(self) self._app = app self.accel_group = Gtk.AccelGroup() # Play self._play = create_menuitem(_("Play"), "media-playback-start") self._play.set_size_request(90, -1) self._play.connect("activate", self._on_play) key, mod = Gtk.accelerator_parse("F6") self._play.add_accelerator("activate", self.accel_group, key, mod, Gtk.AccelFlags.VISIBLE) # Stop self._stop = create_menuitem(_("Stop"), "media-playback-stop") self._stop.set_sensitive(False) self._stop.connect("activate", self._on_stop) key, mod = Gtk.accelerator_parse("F7") self._stop.add_accelerator("activate", self.accel_group, key, mod, Gtk.AccelFlags.VISIBLE) # Record self._record = create_menuitem(_("Record program"), "media-record") self._record.connect("activate", self._on_record) key, mod = Gtk.accelerator_parse("F8") self._record.add_accelerator("activate", self.accel_group, key, mod, Gtk.AccelFlags.VISIBLE) # Stop recording self._stop_recording = create_menuitem(_("Stop recording"), "media-playback-stop") self._stop_recording.set_sensitive(False) self._stop_recording.connect("activate", self._on_stop_record) key, mod = Gtk.accelerator_parse("F9") self._stop_recording.add_accelerator("activate", self.accel_group, key, mod, Gtk.AccelFlags.VISIBLE) # Mute self._mute = Gtk.CheckMenuItem(_("Mute")) self._mute_handler = self._mute.connect("toggled", self._on_mute) key, mod = Gtk.accelerator_parse("<Control>M") self._mute.add_accelerator("activate", self.accel_group, key, mod, Gtk.AccelFlags.VISIBLE) # Refresh refresh = create_menuitem(_("Update schedule"), "gtk-refresh") refresh.connect("activate", self._on_refresh) key, mod = Gtk.accelerator_parse("F5") refresh.add_accelerator("activate", self.accel_group, key, mod, Gtk.AccelFlags.VISIBLE) # Messenger msg = create_menuitem(_("Send message"), "gtk-edit") msg.connect("activate", self._on_im) key, mod = Gtk.accelerator_parse("<Control>S") msg.add_accelerator("activate", self.accel_group, key, mod, Gtk.AccelFlags.VISIBLE) # Preferences prefs = create_menuitem(_("Preferences"), "gtk-preferences") prefs.connect("activate", self._on_prefs) key, mod = Gtk.accelerator_parse("<Control>P") prefs.add_accelerator("activate", self.accel_group, key, mod, Gtk.AccelFlags.VISIBLE) # Quit quit = create_menuitem(_("Quit"), "gtk-quit") quit.connect("activate", self._on_quit) key, mod = Gtk.accelerator_parse("<Control>Q") quit.add_accelerator("activate", self.accel_group, key, mod, Gtk.AccelFlags.VISIBLE) # Separator sep = [] for i in range(5): sep.append(Gtk.SeparatorMenuItem()) # Radio Menu radio_menu = Gtk.Menu() radio = Gtk.MenuItem(_("Radio")) radio.set_submenu(radio_menu) for item in [ self._play, self._stop, self._record, self._stop_recording, sep[0], self._mute, sep[1], refresh, sep[2], msg, sep[3], prefs, sep[4], quit ]: radio_menu.append(item) # About about = create_menuitem("About", "gtk-about") about.set_size_request(90, -1) about.connect("activate", self._on_about) key, mod = Gtk.accelerator_parse("F1") about.add_accelerator("activate", self.accel_group, key, mod, Gtk.AccelFlags.VISIBLE) # silver.ru silver = create_menuitem(_("Official website"), "web-browser") silver.set_size_request(90, -1) silver.connect("activate", self._on_silver) key, mod = Gtk.accelerator_parse("F2") silver.add_accelerator("activate", self.accel_group, key, mod, Gtk.AccelFlags.VISIBLE) # Help Menu help_menu = Gtk.Menu() help = Gtk.MenuItem(_("Help")) help.set_submenu(help_menu) help_menu.append(about) help_menu.append(silver) self.append(radio) self.append(help) self.show_all()