def __create_view_menu(): items = [] accelerators = [] def show_playing_track_cb(*args): get_main().playlist_container.show_current_track() def show_playing_track_sensitive(): from xl import player return player.PLAYER.get_state() != 'stopped' accelerators.append( Accelerator('<Primary>j', _("_Show Playing Track"), show_playing_track_cb)) items.append( _smi('show-playing-track', [], icon_name='go-jump', callback=accelerators[-1], sensitive_cb=show_playing_track_sensitive)) items.append(_sep('show-playing-track-sep', [items[-1].name])) def playlist_utilities_cb(widget, name, parent, context): settings.set_option('gui/playlist_utilities_bar_visible', widget.get_active()) def playlist_utilities_is_checked(name, parent, context): return settings.get_option('gui/playlist_utilities_bar_visible', True) items.append( menu.check_menu_item('playlist-utilities', [items[-1].name], _("_Playlist Utilities Bar"), playlist_utilities_is_checked, playlist_utilities_cb)) items.append( _smi('columns', [items[-1].name], _('C_olumns'), submenu=menu.ProviderMenu('playlist-columns-menu', get_main()))) def clear_playlist_cb(*args): page = get_main().get_selected_page() if page: page.playlist.clear() accelerators.append( Accelerator('<Primary>l', _('_Clear playlist'), clear_playlist_cb)) items.append( _smi('clear-playlist', [items[-1].name], icon_name='edit-clear-all', callback=accelerators[-1])) for item in items: providers.register('menubar-view-menu', item) for accelerator in accelerators: providers.register('mainwindow-accelerators', accelerator)
def __create_view_menu(): items = [] accelerators = [] def show_playing_track_cb(*args): get_main().playlist_container.show_current_track() items.append( menuitems.ShowCurrentTrackMenuItem('show-playing-track', [], show_playing_track_cb, accelerator='<Control>j')) accelerators.append(Accelerator('<Control>j', show_playing_track_cb)) items.append(_sep('show-playing-track-sep', [items[-1].name])) def playlist_utilities_cb(widget, name, parent, context): settings.set_option('gui/playlist_utilities_bar_visible', widget.get_active()) def playlist_utilities_is_checked(name, parent, context): return settings.get_option('gui/playlist_utilities_bar_visible', True) items.append( menu.check_menu_item('playlist-utilities', [items[-1].name], _("_Playlist Utilities Bar"), playlist_utilities_is_checked, playlist_utilities_cb)) items.append( _smi('columns', [items[-1].name], _('_Columns'), submenu=menu.ProviderMenu('playlist-columns-menu', get_main()))) def clear_playlist_cb(*args): page = get_main().get_selected_page() if page: page.playlist.clear() items.append( _smi('clear-playlist', [items[-1].name], _('C_lear playlist'), gtk.STOCK_CLEAR, clear_playlist_cb, accelerator='<Control>l')) accelerators.append(Accelerator('<Control>l', clear_playlist_cb)) for item in items: providers.register('menubar-view-menu', item) for accelerator in accelerators: providers.register('mainwindow-accelerators', accelerator)
def __init__(self, exaile): """ Connects events to the player object, loads settings and cache """ scrobbler.set_user_agent( exaile.get_user_agent_string('audioscrobbler')) self.connected = False self.connecting = False self.use_menu = False self.exaile = exaile self.cachefile = os.path.join(xdg.get_data_dirs()[0], "audioscrobbler.cache") self.get_options('', '', 'plugin/ascrobbler/cache_size') self.get_options('', '', 'plugin/ascrobbler/user') self.load_cache() event.add_ui_callback(self.get_options, 'plugin_ascrobbler_option_set') event.add_callback(self._save_cache_cb, 'quit_application') # enable accelerator def toggle_submit(*x): logger.debug('Toggling AudioScrobbler submissions.') settings.set_option('plugin/ascrobbler/submit', not self.submit) self.accelerator = Accelerator('<Primary>b', _('Toggle AudioScrobbler submit'), toggle_submit) providers.register('mainwindow-accelerators', self.accelerator)
def __create_pre_init_menu_item(self): self.premenu=menu.simple_menu_item('Connect to Douban.fm',[],_('_Connect to Douban.fm'), gtk.STOCK_ADD, lambda e,r,t,y:self.do_init(), accelerator='<Control>C') self.accelerator_pre = Accelerator('<Control>C',lambda e,r,t,y:self.do_init()) providers.register('menubar-file-menu',self.premenu) providers.register('mainwindow-accelerators', self.accelerator_pre)
def __init__(self, exaile): """ Sets up the mini mode main window and options to access it """ Gtk.Window.__init__(self) self.set_title('Exaile Mini Mode') self.set_resizable(False) self.exaile_window = exaile.gui.main.window controls.register() self.box = controls.ControlBox() self.box.set_spacing(3) self.border_frame = Gtk.Frame() self.border_frame.add(self.box) self.add(self.border_frame) self.accelerator = Accelerator('<Primary><Alt>M', _('Mini Mode'), self.on_menuitem_activate) self.menuitem = menu.simple_menu_item('minimode', ['clear-playlist'], icon_name='exaile-minimode', callback=self.accelerator) providers.register('menubar-view-menu', self.menuitem) providers.register('mainwindow-accelerators', self.accelerator) self.mainbutton = Gtk.Button(label=_('Mini Mode')) self.mainbutton.set_image( Gtk.Image.new_from_icon_name('exaile-minimode', Gtk.IconSize.BUTTON)) self.mainbutton.connect('clicked', self.on_mainbutton_clicked) action_area = exaile.gui.main.info_area.get_action_area() action_area.pack_end(self.mainbutton, False, False, 6) self.__active = False self.__dirty = True # XXX: Until defaults are implemented in xl.settings self.__defaults = { 'plugin/minimode/always_on_top': True, 'plugin/minimode/show_in_panel': False, 'plugin/minimode/on_all_desktops': True, 'plugin/minimode/display_window_decorations': True, 'plugin/minimode/window_decoration_type': 'full', 'plugin/minimode/use_alpha': False, 'plugin/minimode/transparency': 0.3, 'plugin/minimode/horizontal_position': 10, 'plugin/minimode/vertical_position': 10 } exaile.gui.main.connect('main-visible-toggle', self.on_main_visible_toggle) event.add_ui_callback(self.on_option_set, 'plugin_minimode_option_set') self.on_option_set('plugin_minimode_option_set', settings, 'plugin/minimode/button_in_mainwindow')
def __create_edit_menu(): items = [] accelerators = [] def collection_manager_cb(*args): from xlgui import get_controller get_controller().collection_manager() items.append( _smi('collection-manager', [], _("_Collection"), None, collection_manager_cb)) def queue_cb(*args): get_main().playlist_container.show_queue() accelerators.append(Accelerator('<Primary>m', _("_Queue"), queue_cb)) items.append(_smi('queue', [items[-1].name], callback=accelerators[-1])) def cover_manager_cb(*args): from xlgui.cover import CoverManager CoverManager(get_main().window, get_main().collection) items.append( _smi( 'cover-manager', [items[-1].name], _("C_overs"), 'image-x-generic', cover_manager_cb, )) def preferences_cb(*args): from xlgui.preferences import PreferencesDialog dialog = PreferencesDialog(get_main().window, get_main().controller) dialog.run() items.append( _smi( 'preferences', [items[-1].name], _("_Preferences"), 'preferences-system', preferences_cb, )) for item in items: providers.register('menubar-edit-menu', item) for accelerator in accelerators: providers.register('mainwindow-accelerators', accelerator)
def __create_edit_menu(): items = [] accelerators = [] def collection_manager_cb(*args): from xlgui import get_controller get_controller().collection_manager() items.append( _smi('collection-manager', [], _("_Collection"), None, collection_manager_cb)) def queue_cb(*args): get_main().playlist_container.show_queue() items.append( _smi('queue', [items[-1].name], _("_Queue"), callback=queue_cb, accelerator='<Control>m')) accelerators.append(Accelerator('<Control>m', queue_cb)) def cover_manager_cb(*args): from xlgui.cover import CoverManager dialog = CoverManager(get_main().window, get_main().collection) items.append( _smi('cover-manager', [items[-1].name], _("C_overs"), None, cover_manager_cb)) def preferences_cb(*args): from xlgui.preferences import PreferencesDialog dialog = PreferencesDialog(get_main().window, get_main().controller) dialog.run() items.append( _smi('preferences', [items[-1].name], icon_name=gtk.STOCK_PREFERENCES, callback=preferences_cb)) for item in items: providers.register('menubar-edit-menu', item) for accelerator in accelerators: providers.register('mainwindow-accelerators', accelerator)
def __create_menu_item__(self): providers.unregister('menubar-file-menu',self.premenu) self.menu=gtk.Menu() for channel_name in self.channels.keys(): menuItem = gtk.MenuItem(_(channel_name)) menuItem.connect('activate', self.active_douban_radio, self.channels[channel_name]) self.menu.append(menuItem) menuItem.show() self.premenu=menu.simple_menu_item('Open Douban.fm',[],_('_Open Douban.fm'), None, None,[],self.menu) providers.register('menubar-file-menu',self.premenu) self.modemenu=menu.simple_menu_item('DoubanFM Mode',[],_('_DoubanFM Mode'), gtk.STOCK_FULLSCREEN,self.show_mode, accelerator='<Control>D') self.accelerator_mode = Accelerator('<Control>D',self.show_mode) providers.register('menubar-view-menu',self.modemenu) providers.register('mainwindow-accelerators', self.accelerator_mode)
def __init__(self, manager_name, player, hotkey): SmartNotebook.__init__(self) self.tab_manager = PlaylistManager(manager_name) self.manager_name = manager_name self.player = player # For saving closed tab history self._moving_tab = False self.tab_history = [] self.history_counter = 90000 # to get unique (reverse-ordered) item names # Build static menu entries item = menu.simple_separator('clear-sep', []) item.register('playlist-closed-tab-menu', self) item = menu.simple_menu_item( 'clear-history', ['clear-sep'], _("_Clear Tab History"), 'edit-clear-all', self.clear_closed_tabs, ) item.register('playlist-closed-tab-menu', self) # Simple factory for 'Recently Closed Tabs' MenuItem submenu = menu.ProviderMenu('playlist-closed-tab-menu', self) def factory(menu_, parent, context): if self.page_num(parent) == -1: return None item = Gtk.MenuItem.new_with_mnemonic(_("Recently Closed _Tabs")) if len(self.tab_history) > 0: item.set_submenu(submenu) else: item.set_sensitive(False) return item # Add menu to tab context menu item = menu.MenuItem('%s-tab-history' % manager_name, factory, ['tab-close']) item.register('playlist-tab-context-menu') # Add menu to View menu # item = menu.MenuItem('tab-history', factory, ['clear-playlist']) # providers.register('menubar-view-menu', item) # setup notebook actions self.actions = NotebookActionService(self, 'playlist-notebook-actions') # Add hotkey self.accelerator = Accelerator( hotkey, _('Restore closed tab'), lambda *x: self.restore_closed_tab(0) ) providers.register('mainwindow-accelerators', self.accelerator) # Load saved tabs self.load_saved_tabs() self.tab_placement_map = { 'left': Gtk.PositionType.LEFT, 'right': Gtk.PositionType.RIGHT, 'top': Gtk.PositionType.TOP, 'bottom': Gtk.PositionType.BOTTOM, } self.connect('page-added', self.on_page_added) self.connect('page-removed', self.on_page_removed) self.on_option_set('gui_option_set', settings, 'gui/show_tabbar') self.on_option_set('gui_option_set', settings, 'gui/tab_placement') event.add_ui_callback(self.on_option_set, 'gui_option_set')
def _setup_hotkeys(self): """ Sets up accelerators that haven't been set up in UI designer """ def factory(integer, description): """ Generate key bindings for Alt keys """ keybinding = '<Alt>%s' % str(integer) callback = lambda *_e: self._on_focus_playlist_tab(integer - 1) return (keybinding, description, callback) hotkeys = ( ( '<Primary>S', _('Save currently selected playlist'), lambda *_e: self.on_save_playlist(), ), ( '<Shift><Primary>S', _('Save currently selected playlist under a custom name'), lambda *_e: self.on_save_playlist_as(), ), ( '<Primary>F', _('Focus filter in currently focused panel'), lambda *_e: self.on_panel_filter_focus(), ), ( '<Primary>G', _('Focus playlist search'), lambda *_e: self.on_search_playlist_focus(), ), # FIXME ( '<Primary><Alt>l', _('Clear queue'), lambda *_e: player.QUEUE.clear(), ), # FIXME ( '<Primary>P', _('Start, pause or resume the playback'), self._on_playpause_button, ), ( '<Primary>Right', _('Seek to the right'), lambda *_e: self._on_seek_key(True), ), ( '<Primary>Left', _('Seek to the left'), lambda *_e: self._on_seek_key(False), ), ( '<Primary>plus', _('Increase the volume'), lambda *_e: self._on_volume_key(True), ), ( '<Primary>equal', _('Increase the volume'), lambda *_e: self._on_volume_key(True), ), ( '<Primary>minus', _('Decrease the volume'), lambda *_e: self._on_volume_key(False), ), ('<Primary>Page_Up', _('Switch to previous tab'), self._on_prev_tab_key), ('<Primary>Page_Down', _('Switch to next tab'), self._on_next_tab_key), ( '<Alt>N', _('Focus the playlist container'), self._on_focus_playlist_container, ), # These 4 are subject to change.. probably should do this # via a different mechanism too... ( '<Alt>I', _('Focus the files panel'), lambda *_e: self.controller.focus_panel('files'), ), # ('<Alt>C', _('Focus the collection panel'), # TODO: Does not work, why? # lambda *_e: self.controller.focus_panel('collection')), ( '<Alt>R', _('Focus the radio panel'), lambda *_e: self.controller.focus_panel('radio'), ), ( '<Alt>L', _('Focus the playlists panel'), lambda *_e: self.controller.focus_panel('playlists'), ), factory(1, _('Focus the first tab')), factory(2, _('Focus the second tab')), factory(3, _('Focus the third tab')), factory(4, _('Focus the fourth tab')), factory(5, _('Focus the fifth tab')), factory(6, _('Focus the sixth tab')), factory(7, _('Focus the seventh tab')), factory(8, _('Focus the eighth tab')), factory(9, _('Focus the ninth tab')), factory(0, _('Focus the tenth tab')), ) for keys, helptext, function in hotkeys: accelerator = Accelerator(keys, helptext, function) providers.register('mainwindow-accelerators', accelerator)
def __create_file_menu(): items = [] accelerators = [] def new_playlist_cb(*args): get_main().playlist_container.create_new_playlist() items.append( _smi('new-playlist', [], _("_New Playlist"), 'tab-new', new_playlist_cb, accelerator='<Control>t')) accelerators.append(Accelerator('<Control>t', new_playlist_cb)) items.append(_sep('new-sep', [items[-1].name])) def open_cb(*args): dialog = dialogs.MediaOpenDialog(get_main().window) dialog.connect('uris-selected', lambda d, uris: get_main().controller.open_uris(uris)) dialog.show() items.append( _smi('open', [items[-1].name], icon_name=gtk.STOCK_OPEN, callback=open_cb, accelerator='<Control>o')) accelerators.append(Accelerator('<Control>o', open_cb)) def open_uri_cb(*args): dialog = dialogs.URIOpenDialog(get_main().window) dialog.connect('uri-selected', lambda d, uri: get_main().controller.open_uri(uri)) dialog.show() items.append( _smi('open-uri', [items[-1].name], _("Open _URL"), 'applications-internet', open_uri_cb, accelerator='<Control><Shift>o')) accelerators.append(Accelerator('<Control><Shift>o', open_uri_cb)) def open_dirs_cb(*args): dialog = dialogs.DirectoryOpenDialog(get_main().window) dialog.props.create_folders = False dialog.connect('uris-selected', lambda d, uris: get_main().controller.open_uris(uris)) dialog.show() items.append( _smi('open-dirs', [items[-1].name], _("Open Directories"), None, open_dirs_cb)) items.append(_sep('open-sep', [items[-1].name])) items.append( _smi( 'import-playlist', [items[-1].name], _("Import Playlist"), gtk.STOCK_OPEN, lambda *e: get_main().controller.get_panel( 'playlists').import_playlist())) def export_playlist_cb(*args): main = get_main() page = get_selected_playlist() if not page: return def on_message(dialog, message_type, message): """ Show messages in the main window message area """ if message_type == gtk.MESSAGE_INFO: main.message.show_info(markup=message) elif message_type == gtk.MESSAGE_ERROR: main.message.show_error(_('Playlist export failed!'), message) return True dialog = dialogs.PlaylistExportDialog(page.playlist, main.window) dialog.connect('message', on_message) dialog.show() items.append( _smi('export-playlist', [items[-1].name], _("_Export Current Playlist"), gtk.STOCK_SAVE_AS, export_playlist_cb)) items.append(_sep('export-sep', [items[-1].name])) def close_tab_cb(*args): get_main().get_selected_page().tab.close() items.append( _smi('close-tab', [items[-1].name], _("Close Tab"), gtk.STOCK_CLOSE, callback=close_tab_cb, accelerator='<Control>w')) accelerators.append(Accelerator('<Control>w', close_tab_cb)) if get_main().controller.exaile.options.Debug: def restart_cb(*args): from xl import main main.exaile().quit(True) items.append( _smi('restart-application', [items[-1].name], _("Restart"), callback=restart_cb, accelerator='<Control>r')) accelerators.append(Accelerator('<Control>r', restart_cb)) def quit_cb(*args): from xl import main main.exaile().quit() items.append( _smi('quit-application', [items[-1].name], icon_name=gtk.STOCK_QUIT, callback=quit_cb, accelerator='<Control>q')) accelerators.append(Accelerator('<Control>q', quit_cb)) for item in items: providers.register('menubar-file-menu', item) for accelerator in accelerators: providers.register('mainwindow-accelerators', accelerator)
def __init__(self, exaile): """ Sets up the mini mode main window and options to access it """ gtk.Window.__init__(self) self.set_title('Exaile Mini Mode') self.set_resizable(False) self.exaile_window = exaile.gui.main.window controls.register() self.box = controls.ControlBox() self.box.set_spacing(3) alignment = gtk.Alignment(xscale=1, yscale=1) alignment.set_padding(0, 0, 3, 3) alignment.add(self.box) self.border_frame = gtk.Frame() self.border_frame.add(alignment) self.add(self.border_frame) self.menuitem = menu.simple_menu_item('minimode', ['clear-playlist'], _('Mini Mode'), 'exaile-minimode', self.on_menuitem_activate, accelerator='<Control><Alt>M') self.accelerator = Accelerator('<Control><Alt>M', self.on_menuitem_activate) providers.register('menubar-view-menu', self.menuitem) providers.register('mainwindow-accelerators', self.accelerator) mainbutton = gtk.Button(_('Mini Mode')) mainbutton.set_image( gtk.image_new_from_icon_name('exaile-minimode', gtk.ICON_SIZE_BUTTON)) mainbutton.connect('clicked', self.on_mainbutton_clicked) self.mainbutton_alignment = gtk.Alignment(xalign=1) self.mainbutton_alignment.add(mainbutton) action_area = exaile.gui.main.info_area.get_action_area() action_area.pack_start(self.mainbutton_alignment) action_area.reorder_child(self.mainbutton_alignment, 0) self.__active = False self.__dirty = True # XXX: Until defaults are implemented in xl.settings self.__defaults = { 'plugin/minimode/always_on_top': True, 'plugin/minimode/show_in_panel': False, 'plugin/minimode/on_all_desktops': True, 'plugin/minimode/display_window_decorations': True, 'plugin/minimode/window_decoration_type': 'full', 'plugin/minimode/use_alpha': False, 'plugin/minimode/transparency': 0.3, 'plugin/minimode/horizontal_position': 10, 'plugin/minimode/vertical_position': 10 } exaile.gui.main.connect('main-visible-toggle', self.on_main_visible_toggle) event.add_callback(self.on_option_set, 'plugin_minimode_option_set') self.on_option_set('plugin_minimode_option_set', settings, 'plugin/minimode/button_in_mainwindow')
def __create_file_menu(): items = [] accelerators = [] def new_playlist_cb(*args): get_main().playlist_container.create_new_playlist() accelerators.append( Accelerator('<Primary>t', _("_New Playlist"), new_playlist_cb)) items.append( _smi('new-playlist', [], icon_name='tab-new', callback=accelerators[-1])) items.append(_sep('new-sep', [items[-1].name])) def open_cb(*args): dialog = dialogs.MediaOpenDialog(get_main().window) dialog.connect('uris-selected', lambda d, uris: get_main().controller.open_uris(uris)) dialog.show() accelerators.append(Accelerator('<Primary>o', _("_Open"), open_cb)) items.append( _smi( 'open', [items[-1].name], icon_name='document-open', callback=accelerators[-1], )) def open_uri_cb(*args): dialog = dialogs.URIOpenDialog(get_main().window) dialog.connect('uri-selected', lambda d, uri: get_main().controller.open_uri(uri)) dialog.show() accelerators.append( Accelerator('<Primary><Shift>o', _("Open _URL"), open_uri_cb)) items.append( _smi( 'open-uri', [items[-1].name], icon_name='emblem-web', callback=accelerators[-1], )) def open_dirs_cb(*args): dialog = dialogs.DirectoryOpenDialog(get_main().window) dialog.props.create_folders = False dialog.connect('uris-selected', lambda d, uris: get_main().controller.open_uris(uris)) dialog.show() items.append( _smi( 'open-dirs', [items[-1].name], _("Open _Directories"), 'folder-open', open_dirs_cb, )) items.append(_sep('open-sep', [items[-1].name])) items.append( _smi( 'import-playlist', [items[-1].name], _("_Import Playlist"), 'document-open', lambda *e: get_main().controller.get_panel('playlists'). import_playlist(), )) def export_playlist_cb(*args): main = get_main() page = get_selected_playlist() if not page: return def on_message(dialog, message_type, message): """ Show messages in the main window message area """ if message_type == Gtk.MessageType.INFO: main.message.show_info(markup=message) elif message_type == Gtk.MessageType.ERROR: main.message.show_error(_('Playlist export failed!'), message) return True dialog = dialogs.PlaylistExportDialog(page.playlist, main.window) dialog.connect('message', on_message) dialog.show() items.append( _smi( 'export-playlist', [items[-1].name], _("E_xport Current Playlist"), 'document-save-as', export_playlist_cb, )) items.append(_sep('export-sep', [items[-1].name])) def close_tab_cb(*args): get_main().get_selected_page().tab.close() accelerators.append( Accelerator('<Primary>w', _("Close _Tab"), close_tab_cb)) items.append( _smi( 'close-tab', [items[-1].name], icon_name='window-close', callback=accelerators[-1], )) if get_main().controller.exaile.options.Debug: def restart_cb(*args): from xl import main main.exaile().quit(True) accelerators.append( Accelerator('<Primary>r', _("_Restart"), restart_cb)) items.append( _smi('restart-application', [items[-1].name], callback=accelerators[-1])) def quit_cb(*args): from xl import main main.exaile().quit() accelerators.append(Accelerator('<Primary>q', _("_Quit Exaile"), quit_cb)) items.append( _smi( 'quit-application', [items[-1].name], icon_name='application-exit', callback=accelerators[-1], )) for item in items: providers.register('menubar-file-menu', item) for accelerator in accelerators: providers.register('mainwindow-accelerators', accelerator)