def __init__(self, exaile): self.bookmarks = [] # self.auto_db = {} self.exaile = exaile self.use_covers = settings.get_option('plugin/bookmarks/use_covers', False) self.counter = 0 # setup menus self.menu = menu.Menu(self) self.delete_menu = menu.Menu(self) # define factory-factory for sensitive-aware menuitems def factory_factory(display_name, icon_name, callback=None, submenu=None): def factory(menu_, parent, context): item = Gtk.ImageMenuItem.new_with_mnemonic(display_name) image = Gtk.Image.new_from_icon_name(icon_name, size=Gtk.IconSize.MENU) item.set_image(image) # insensitive if no bookmarks present if len(self.bookmarks) == 0: item.set_sensitive(False) else: if callback is not None: item.connect('activate', callback) if submenu is not None: item.set_submenu(submenu) return item return factory items = [] items.append( _smi('bookmark', [], _('_Bookmark This Track'), 'bookmark-new', self.add_bookmark)) items.append( menu.MenuItem( 'delete', factory_factory(_('_Delete Bookmark'), 'gtk-close', submenu=self.delete_menu), ['bookmark'])) items.append( menu.MenuItem( 'clear', factory_factory(_('_Clear Bookmarks'), 'gtk-clear', callback=self.clear), ['delete'])) items.append(_sep('sep', ['clear'])) for item in items: self.menu.add_item(item)
def __setup_menu(self): self.menu = menu.Menu(self) self.delete_menu = menu.Menu(self) def factory_factory(display_name, icon_name, callback=None, submenu=None): "define factory-factory for sensitive-aware menuitems" def factory(_menu, _parent, _context): item = Gtk.ImageMenuItem.new_with_mnemonic(display_name) image = Gtk.Image.new_from_icon_name(icon_name, size=Gtk.IconSize.MENU) item.set_image(image) if callback is not None: item.connect('activate', callback) if submenu is not None: item.set_submenu(submenu) # insensitive if no bookmarks present if len(self.__bookmarks) == 0: item.set_sensitive(False) return item return factory items = [] items.append( _smi( 'bookmark', [], _('_Bookmark This Track'), 'bookmark-new', self.__on_add_bookmark, )) delete_cb = factory_factory(_('_Delete Bookmark'), 'gtk-close', submenu=self.delete_menu) items.append(menu.MenuItem('delete', delete_cb, ['bookmark'])) clear_cb = factory_factory(_('_Clear Bookmarks'), 'gtk-clear', callback=self.__clear_bookmarks) items.append(menu.MenuItem('clear', clear_cb, ['delete'])) items.append(_sep('sep', ['clear'])) for item in items: self.menu.add_item(item)
def on_gui_loaded(self): event.add_callback(self.__on_settings_changed, 'plugin_daapclient_option_set') menu_ = menu.Menu(None) providers.register('menubar-tools-menu', _sep('plugin-sep', ['track-properties'])) item = _smi('daap', ['plugin-sep'], _('Connect to DAAP...'), submenu=menu_) providers.register('menubar-tools-menu', item) if AVAHI: try: avahi_interface = DaapAvahiInterface(self.__exaile, menu_) except RuntimeError: # no dbus? avahi_interface = None logger.warning( 'avahi interface could not be initialized (no dbus?)') except dbus.exceptions.DBusException as s: avahi_interface = None logger.error('Got DBUS error: %s' % s) logger.error('is avahi-daemon running?') else: avahi_interface = None logger.warning( 'AVAHI could not be imported, you will not see broadcast shares.' ) self.__manager = DaapManager(self.__exaile, menu_, avahi_interface)
def __init__(self, exaile, _menu, avahi): ''' Init! Create manual menu item, and connect to avahi signal. ''' self.exaile = exaile self.avahi = avahi self.panels = {} hmenu = menu.Menu(None) def hmfactory(_menu, _parent, _context): item = Gtk.MenuItem.new_with_mnemonic(_('History')) item.set_submenu(hmenu) sens = settings.get_option('plugin/daapclient/history', True) item.set_sensitive(sens) return item _menu.add_item( _smi('manual', [], _('Manually...'), callback=self.manual_connect)) _menu.add_item(menu.MenuItem('history', hmfactory, ['manual'])) _menu.add_item(_sep('sep', ['history'])) if avahi is not None: avahi.connect("connect", self.connect_share) self.history = DaapHistory(5, menu=hmenu, callback=self.connect_share)
def get_menu(self): """ Returns the menu that all radio stations use """ m = menu.Menu(None) m.add_simple(_("Refresh"), self.on_reload, Gtk.STOCK_REFRESH) return m
def on_gui_loaded(self): event.add_callback(self.__on_settings_changed, 'plugin_daapclient_option_set') menu_ = menu.Menu(None) providers.register('menubar-tools-menu', _sep('plugin-sep', ['track-properties'])) item = _smi('daap', ['plugin-sep'], _('Connect to DAAP...'), submenu=menu_) providers.register('menubar-tools-menu', item) autodiscover = None if ZEROCONF: try: autodiscover = DaapZeroconfInterface(self.__exaile, menu_) except RuntimeError: logger.warning('zeroconf interface could not be initialized') else: logger.warning( 'python-zeroconf is not available; disabling DAAP share auto-discovery!' ) self.__manager = DaapManager(self.__exaile, menu_, autodiscover)
def __init__(self, exaile, gui): notebook.SmartNotebook.__init__(self) self.exaile = exaile self.panels = {} # key: name, value: PanelData object self.set_tab_pos(Gtk.PositionType.LEFT) self.set_add_tab_on_empty(False) self.loading_panels = True self.connect('page-removed', self.on_panel_removed) self.connect('page-reordered', self.on_panel_reordered) self.connect('switch-page', self.on_panel_switch) _register_builtin_panels(exaile, gui.main.window) self.view_menu = menu.Menu(None) # setup/register the view menu menu.simple_menu_item('panel-menu', ['show-playing-track'], _('P_anels'), submenu=self.view_menu) \ .register('menubar-view-menu') providers.ProviderHandler.__init__(self, 'main-panel', simple_init=True) # Provide interface for adding buttons to the notebook self.actions = notebook.NotebookActionService(self, 'main-panel-actions') if not self.exaile.loading: self.on_gui_loaded()
def __init__(self, parent, library, mgr): """ Expects a parent Gtk.Window, and a daap connection. """ self.name = library.daap_share.name self.daap_share = library.daap_share self.net_collection = collection.Collection(self.name) self.net_collection.add_library(library) CollectionPanel.__init__(self, parent, self.net_collection, self.name, _show_collection_empty_message=False) self.all = [] self.label = self.name self.connect_id = None self.menu = menu.Menu(self) def get_tracks_func(*args): return self.tree.get_selected_tracks() self.menu.add_item(menuitems.AppendMenuItem('append', [], get_tracks_func)) self.menu.add_item(menuitems.EnqueueMenuItem('enqueue', ['append'], get_tracks_func)) self.menu.add_item(menuitems.PropertiesMenuItem('props', ['enqueue'], get_tracks_func)) self.menu.add_item(_sep('sep',['props'])) self.menu.add_item(_smi('refresh', ['sep'], _('Refresh Server List'), callback = lambda *x: mgr.refresh_share(self.name))) self.menu.add_item(_smi('disconnect', ['refresh'], _('Disconnect from Server'), callback = lambda *x: mgr.disconnect_share(self.name)))
def create_menu(self): sep = menu.simple_separator('furas-item-sep', ['properties']) #sep._pos = 'normal' self.provider_register(sep, 'playlist-context-menu') for n, (name, url) in enumerate(DATA): item = menu.simple_menu_item( 'furas-item-%i' % n, # unique name ['furas-item-sep'], # after ie. [] or ['properties'] name, # displayed text 'gtk-save', # icon name # ie. 'document-properties' self.webbrowser_cb, # callback function callback_args=[url] # callback extra arguments ) #print(dir(item)) self.provider_register(item, 'playlist-context-menu') print '---------------------------------' print 'TESTING: register menu #1' ### submenu ### self.submenu = menu.Menu(self, inherit_context=True) for n, (name, url) in enumerate(DATA): self.submenu.add_item( menu.simple_menu_item( 'furas-item-sub-%i' % n, # unique name [], # after ie. [] or ['properties'] name, # displayed text 'gtk-save', # icon name # ie. 'document-properties' self.webbrowser_cb, # callback function callback_args=[url] # callback extra arguments )) item = menu.simple_menu_item( 'furas-item-sub', # unique name ['furas-item-sep'], # after ie. [] or ['properties'] 'Szukaj', submenu=self.submenu) self.provider_register(item, 'playlist-context-menu') print 'TESTING: self.submenu._items:' print self.submenu._items print '---------------------------------' print 'TESTING: register menu #2' for p in providers.get('playlist-context-menu'): print 'TESTING: -> menu:', p.name, p._pos, p.after print '---------------------------------'
def on_stop_button_press_event(self, widget, event): """ Called when the user clicks on the stop button """ if event.button == Gdk.BUTTON_PRIMARY: if event.get_state() & Gdk.ModifierType.SHIFT_MASK: self.on_spat_clicked() elif event.triggers_context_menu(): m = menu.Menu(self) m.attach_to_widget(widget) m.add_simple(_("Toggle: Stop after Selected Track"), self.on_spat_clicked, 'process-stop') m.popup(event)
def on_refresh_button_press_event(self, button, event): """ Called on mouse activation of the refresh button """ if event.triggers_context_menu(): m = menu.Menu(None) m.attach_to_widget(button) m.add_simple(_('Rescan Collection'), xlgui.get_controller().on_rescan_collection, Gtk.STOCK_REFRESH) m.popup(event) return if event.get_state() & Gdk.ModifierType.SHIFT_MASK: xlgui.get_controller().on_rescan_collection(None) else: self.load_tree()
def _setup_widgets(self): self.model = Gtk.ListStore(str, str) self.tree = self.builder.get_object('podcast_tree') self.tree.set_model(self.model) text = Gtk.CellRendererText() self.column = Gtk.TreeViewColumn(_('Podcast')) self.column.pack_start(text, True) self.column.set_expand(True) self.column.set_attributes(text, text=0) self.tree.append_column(self.column) self.status = self.builder.get_object('podcast_statusbar') self.menu = menu.Menu(self) self.menu.add_simple(_('Refresh Podcast'), self._on_refresh, Gtk.STOCK_REFRESH) self.menu.add_simple(_('Delete'), self._on_delete, Gtk.STOCK_DELETE) self.menu.attach_to_widget(self.tree)
def __init__(self, player, plugin): Gtk.Frame.__init__(self, label=_('BPM Counter')) self.init_template() self.player = player self.plugin = plugin self.taps = [] # TODO: Add preferences to adjust these settings.. # number of seconds to average taps over so it converges faster self.tap_history = settings.get_option('plugin/bpm/tap_history', 5.0) # if no tap received, then restart self.stale_time = settings.get_option('plugin/bpm/stale_period', 2.0) # Autodetect plugin self.menu = None if autodetect_enabled: self.menu = menu.Menu(None) item = menu.simple_menu_item( '_bpm', [], _('Autodetect BPM'), callback=self.on_auto_menuitem ) self.menu.add_item(item) # Be notified when a new track is playing event.add_ui_callback( self.playback_track_start, 'playback_track_start', self.player ) # get the main exaile window, and dock our window next to it if possible # trigger start event if exaile is currently playing something if self.player.is_playing(): self.playback_track_start(None, self.player, self.player.current) else: self.track = None self.bpm = None self.taps = [] self.update_ui()
def _enable(exaile): global MANAGER event.add_callback(on_settings_change, 'plugin_daapclient_option_set') menu_ = menu.Menu(None) providers.register('menubar-tools-menu', _sep('plugin-sep', ['track-properties'])) item = _smi('daap', ['plugin-sep'], _('Connect to DAAP...'), submenu=menu_) providers.register('menubar-tools-menu', item) if AVAHI: try: avahi_interface = DaapAvahiInterface(exaile, menu_) except RuntimeError: # no dbus? avahi_interface = None logger.warning( 'avahi interface could not be initialized (no dbus?)') except dbus.exceptions.DBusException, s: avahi_interface = None logger.error('Got DBUS error: %s' % s) logger.error('is avahi-daemon running?')
def on_gui_loaded(self): self.track = None self.tag_dialog = None migrate_settings() self.panel = gt_widgets.GroupTaggerPanel(self.exaile) self.panel.show_all() self.setup_panel_font(False) self.panel.tagger.view.connect('category-changed', self.on_category_change) self.panel.tagger.view.connect('category-edited', self.on_category_edited) self.panel.tagger.view.connect('group-changed', self.on_group_change) # add to exaile's panel interface providers.register('main-panel', self.panel) # ok, register for some events event.add_ui_callback(self.on_playback_track_start, 'playback_track_start') event.add_ui_callback( self.on_playlist_cursor_changed, 'playlist_cursor_changed' ) event.add_ui_callback( self.on_plugin_options_set, 'plugin_grouptagger_option_set' ) # add our own submenu for functionality tools_submenu = menu.Menu(None, context_func=lambda p: self.exaile) tools_submenu.add_item( menu.simple_menu_item( 'gt_get_tags', [], _('_Get all tags from collection'), callback=self.on_get_tags_menu, ) ) tools_submenu.add_item( menu.simple_menu_item( 'gt_import', [], _('_Import tags from directory'), callback=self.on_import_tags, ) ) tools_submenu.add_item( menu.simple_menu_item( 'gt_rename', [], _('_Mass rename/delete tags'), callback=self.on_mass_rename, ) ) tools_submenu.add_item( menu.simple_menu_item( 'gt_export', [], _('E_xport collecton tags to JSON'), callback=self.on_export_tags, ) ) # group them together to make it not too long self.tools_menuitem = menu.simple_menu_item( 'grouptagger', ['plugin-sep'], _('_GroupTagger'), submenu=tools_submenu ) providers.register('menubar-tools-menu', self.tools_menuitem) # playlist context menu items self.provider_items = [] track_subitem = menu.Menu(None, inherit_context=True) track_subitem.add_item( menu.simple_menu_item( 'gt_search_all', [], _('Show tracks with all tags'), callback=self.on_playlist_context_select_all_menu, callback_args=[self.exaile], ) ) track_subitem.add_item( menu.simple_menu_item( 'gt_search_custom', ['gt_search_all'], _('Show tracks with tags (custom)'), callback=self.on_playlist_context_select_custom_menu, callback_args=[self.exaile], ) ) tag_cond_fn = lambda n, p, c: c['selection-count'] > 1 track_subitem.add_item( menu.simple_menu_item( 'gt_tag_add_multi', ['gt_search_custom'], _('Add tags to all'), callback=self.on_add_tags, condition_fn=tag_cond_fn, callback_args=[self.exaile], ) ) track_subitem.add_item( menu.simple_menu_item( 'gt_tag_rm_multi', ['gt_tag_add_multi'], _('Remove tags from all'), callback=self.on_rm_tags, condition_fn=tag_cond_fn, callback_args=[self.exaile], ) ) self.provider_items.append( menu.simple_menu_item( 'grouptagger', ['rating'], _('GroupTagger'), submenu=track_subitem ) ) for item in self.provider_items: providers.register('playlist-context-menu', item) # Hm, doesn't work.. # providers.register('track-panel-menu', item) # trigger start event if exaile is currently playing something if player.PLAYER.is_playing(): self.set_display_track(player.PLAYER.current) else: self.panel.tagger.set_categories([], get_group_categories())
def __init__(self, exaile): self.track = None self.tag_dialog = None migrate_settings() self.panel = gt_widgets.GroupTaggerPanel(exaile) self.panel.show_all() self.setup_panel_font(False) self.panel.tagger.view.connect('category-changed', self.on_category_change) self.panel.tagger.view.connect('category-edited', self.on_category_edited) self.panel.tagger.view.connect('group-changed', self.on_group_change) # add to exaile's panel interface providers.register('main-panel', self.panel) # ok, register for some events event.add_callback(self.on_playback_track_start, 'playback_track_start') event.add_callback(self.on_playlist_cursor_changed, 'playlist_cursor_changed') event.add_callback(self.on_plugin_options_set, 'plugin_grouptagger_option_set') # add our own submenu for functionality self.tools_submenu = menu.Menu(None, context_func=lambda p: exaile) self.tools_submenu.add_item( menu.simple_menu_item('gt_get_tags', [], _('Get all tags from collection'), callback=self.on_get_tags_menu)) self.tools_submenu.add_item( menu.simple_menu_item('gt_import', [], _('Import tags from directory'), callback=self.on_import_tags)) self.tools_submenu.add_item( menu.simple_menu_item('gt_rename', [], _('Mass rename/delete tags'), callback=self.on_mass_rename)) # group them together to make it not too long self.tools_menuitem = menu.simple_menu_item('grouptagger', ['plugin-sep'], _('GroupTagger'), submenu=self.tools_submenu) providers.register('menubar-tools-menu', self.tools_menuitem) # playlist context menu items self.selectall_menuitem = menu.simple_menu_item( 'gt_search_all', ['rating'], _('Show tracks with all tags'), callback=self.on_playlist_context_select_all_menu, callback_args=[exaile]) providers.register('playlist-context-menu', self.selectall_menuitem) self.selectcustom_menuitem = menu.simple_menu_item( 'gt_search_custom', ['rating'], _('Show tracks with tags (custom)'), callback=self.on_playlist_context_select_custom_menu, callback_args=[exaile]) providers.register('playlist-context-menu', self.selectcustom_menuitem) # trigger start event if exaile is currently playing something if player.PLAYER.is_playing(): self.set_display_track(player.PLAYER.current) else: self.panel.tagger.set_categories([], get_group_categories())