def __init__(self, container, player): PlaylistPageBase.__init__(self) self.plcontainer = container self.player = player self.playlist = player.queue # a queue is a playlist object... self.swindow = Gtk.ScrolledWindow() self.swindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.pack_start(self.swindow, True, True, 0) self.view = PlaylistView(self.player.queue, self.player) self.view.dragdrop_copyonly = True self.swindow.add(self.view) event.add_ui_callback( self.on_length_changed, 'playlist_current_position_changed', self.player.queue, ) event.add_ui_callback(self.on_length_changed, "playlist_tracks_added", self.player.queue) event.add_ui_callback(self.on_length_changed, "playlist_tracks_removed", self.player.queue) self.show_all()
class QueuePage(NotebookPage): menu_provider_name = 'queue-tab-context' def __init__(self, container, player): NotebookPage.__init__(self) self.container = container self.player = player self.playlist = player.queue # a queue is a playlist object... self.swindow = gtk.ScrolledWindow() self.swindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.pack_start(self.swindow, True, True) self.view = PlaylistView(self.player.queue, self.player) self.view.dragdrop_copyonly = True self.swindow.add(self.view) event.add_callback(self.on_length_changed, 'playlist_current_position_changed', self.player.queue) event.add_callback(self.on_length_changed, "playlist_tracks_added", self.player.queue) event.add_callback(self.on_length_changed, "playlist_tracks_removed", self.player.queue) self.show_all() def on_length_changed(self, *args): self.name_changed() if len(self.player.queue) == 0: self.tab.set_closable(True) else: self.container.show_queue(switch=False) self.tab.set_closable(False) ## NotebookPage API ## def focus(self): self.view.grab_focus() def get_page_name(self): qlen = self.player.queue.queue_length() if qlen == -1: return _("Queue") else: return _("Queue (%d)") % qlen def set_tab(self, tab): NotebookPage.set_tab(self, tab) tab.set_closable(not self.do_closing()) def do_closing(self): """ Allows closing only if the queue is empty """ return len(self.player.queue) != 0
def __init__(self, playlist, player): PlaylistPageBase.__init__(self) self.playlist = playlist self.swindow = Gtk.ScrolledWindow() self.swindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.pack_start(self.swindow, True, True, 0) self.view = PlaylistView(self.playlist, player) self.swindow.add(self.view) hbox = Gtk.ButtonBox() hbox.set_halign(Gtk.Align.END) button = Gtk.Button(stock=Gtk.STOCK_CLEAR) button.connect('clicked', self.on_clear_history) hbox.pack_start(button, True, True, 0) button = Gtk.Button(stock=Gtk.STOCK_SAVE) button.connect('clicked', self.on_save_history) hbox.pack_start(button, True, True, 0) self.pack_start(hbox, False, False, 0) self.show_all()
def __init__(self, container, player): PlaylistPageBase.__init__(self) self.plcontainer = container self.player = player self.playlist = player.queue # a queue is a playlist object... self.swindow = Gtk.ScrolledWindow() self.swindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.pack_start(self.swindow, True, True, 0) self.view = PlaylistView(self.player.queue, self.player) self.view.dragdrop_copyonly = True self.swindow.add(self.view) event.add_ui_callback( self.on_length_changed, 'playlist_current_position_changed', self.player.queue, ) event.add_ui_callback( self.on_length_changed, "playlist_tracks_added", self.player.queue ) event.add_ui_callback( self.on_length_changed, "playlist_tracks_removed", self.player.queue ) self.show_all()
def __init__(self, playlist, player): NotebookPage.__init__(self) self.playlist = playlist self.swindow = gtk.ScrolledWindow() self.swindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.pack_start(self.swindow, True, True) self.view = PlaylistView(self.playlist, player) self.swindow.add(self.view) hbox = gtk.HButtonBox() button = gtk.Button(stock=gtk.STOCK_CLEAR) button.connect( 'clicked', self.on_clear_history ) hbox.pack_start( button ) button = gtk.Button(stock=gtk.STOCK_SAVE) button.connect( 'clicked', self.on_save_history ) hbox.pack_start( button ) align = gtk.Alignment( 1.0, 0.0 ) align.add( hbox ) self.pack_start( align, False, False ) self.show_all()
class QueuePage(PlaylistPageBase): def __init__(self, container, player): PlaylistPageBase.__init__(self) self.plcontainer = container self.player = player self.playlist = player.queue # a queue is a playlist object... self.swindow = Gtk.ScrolledWindow() self.swindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.pack_start(self.swindow, True, True, 0) self.view = PlaylistView(self.player.queue, self.player) self.view.dragdrop_copyonly = True self.swindow.add(self.view) event.add_ui_callback(self.on_length_changed, 'playlist_current_position_changed', self.player.queue) event.add_ui_callback(self.on_length_changed, "playlist_tracks_added", self.player.queue) event.add_ui_callback(self.on_length_changed, "playlist_tracks_removed", self.player.queue) self.show_all() def on_length_changed(self, *args): self.name_changed() if len(self.player.queue) == 0: self.tab.set_closable(True) else: self.plcontainer.show_queue(switch=False) self.tab.set_closable(False) ## NotebookPage API ## def focus(self): self.view.grab_focus() def get_page_name(self): qlen = self.player.queue.queue_length() if qlen == -1: return _("Queue") else: return _("Queue (%d)") % qlen def set_tab(self, tab): super(QueuePage, self).set_tab(tab) tab.set_closable(not self.do_closing()) def do_closing(self): """ Allows closing only if the queue is empty """ return len(self.player.queue) != 0 ## End NotebookPage ## def on_saveas(self): exaile = main.exaile() name = dialogs.ask_for_playlist_name( exaile.gui.main.window, exaile.playlists) if name is not None: pl = playlist.Playlist(name, self.playlist[:]) exaile.playlists.save_playlist(pl) self.plcontainer.create_tab_from_playlist(pl)
def __init__(self): Gtk.ToggleButton.__init__(self) BaseControl.__init__(self) QueueAdapter.__init__(self, player.QUEUE) self.set_focus_on_click(False) self.set_size_request(200, -1) box = Gtk.Box() self.arrow = Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.OUT) box.pack_start(self.arrow, False, True, 0) self.label = Gtk.Label(label='') self.label.props.ellipsize = Pango.EllipsizeMode.END box.pack_start(self.label, True, True, 0) self.add(box) self.formatter = TrackFormatter( settings.get_option('plugin/minimode/track_title_format', '$tracknumber - $title')) self.view = PlaylistView(player.QUEUE.current_playlist, player.PLAYER) self.popup = AttachedWindow(self) self.popup.set_default_size( settings.get_option( 'plugin/minimode/' 'playlist_button_popup_width', 350), settings.get_option( 'plugin/minimode/' 'playlist_button_popup_height', 400)) scrollwindow = Gtk.ScrolledWindow() scrollwindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scrollwindow.set_shadow_type(Gtk.ShadowType.IN) scrollwindow.add(self.view) self.popup.add(scrollwindow) self.popup.connect('show', self.on_popup_show) self.popup.connect('hide', self.on_popup_hide) self.popup.connect('configure-event', self.on_popup_configure_event) accel_group = Gtk.AccelGroup() key, modifier = Gtk.accelerator_parse('<Control>J') accel_group.connect(key, modifier, Gtk.AccelFlags.VISIBLE, self.on_accelerator_activate) self.popup.add_accel_group(accel_group) self.tooltip = TrackToolTip(self, player.PLAYER) self.tooltip.set_auto_update(True) if player.PLAYER.current is not None: self.label.set_text(self.formatter.format(player.PLAYER.current)) self._drag_motion_timeout_id = None self._drag_leave_timeout_id = None self.drag_dest_set( Gtk.DestDefaults.ALL, self.view.targets, Gdk.DragAction.COPY | Gdk.DragAction.DEFAULT | Gdk.DragAction.MOVE) self.connect('drag-motion', self.on_drag_motion) self.connect('drag-leave', self.on_drag_leave) self.connect('drag-data-received', self.on_drag_data_received) self.view.connect('drag-motion', self.on_drag_motion) self.view.connect('drag-leave', self.on_drag_leave) event.add_ui_callback(self.on_track_tags_changed, 'track_tags_changed') event.add_ui_callback(self.on_option_set, 'plugin_minimode_option_set') self.on_option_set('plugin_minimode_option_set', settings, 'plugin/minimode/track_title_format')
class PlaylistButtonControl(Gtk.ToggleButton, BaseControl, QueueAdapter): name = 'playlist_button' title = _('Playlist button') description = _('Access the current playlist') __gsignals__ = {'scroll-event': 'override'} def __init__(self): Gtk.ToggleButton.__init__(self) BaseControl.__init__(self) QueueAdapter.__init__(self, player.QUEUE) self.set_focus_on_click(False) self.set_size_request(200, -1) box = Gtk.Box() self.arrow = Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.OUT) box.pack_start(self.arrow, False, True, 0) self.label = Gtk.Label(label='') self.label.props.ellipsize = Pango.EllipsizeMode.END box.pack_start(self.label, True, True, 0) self.add(box) self.formatter = TrackFormatter( settings.get_option('plugin/minimode/track_title_format', '$tracknumber - $title')) self.view = PlaylistView(player.QUEUE.current_playlist, player.PLAYER) self.popup = AttachedWindow(self) self.popup.set_default_size( settings.get_option( 'plugin/minimode/' 'playlist_button_popup_width', 350), settings.get_option( 'plugin/minimode/' 'playlist_button_popup_height', 400)) scrollwindow = Gtk.ScrolledWindow() scrollwindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scrollwindow.set_shadow_type(Gtk.ShadowType.IN) scrollwindow.add(self.view) self.popup.add(scrollwindow) self.popup.connect('show', self.on_popup_show) self.popup.connect('hide', self.on_popup_hide) self.popup.connect('configure-event', self.on_popup_configure_event) accel_group = Gtk.AccelGroup() key, modifier = Gtk.accelerator_parse('<Control>J') accel_group.connect(key, modifier, Gtk.AccelFlags.VISIBLE, self.on_accelerator_activate) self.popup.add_accel_group(accel_group) self.tooltip = TrackToolTip(self, player.PLAYER) self.tooltip.set_auto_update(True) if player.PLAYER.current is not None: self.label.set_text(self.formatter.format(player.PLAYER.current)) self._drag_motion_timeout_id = None self._drag_leave_timeout_id = None self.drag_dest_set( Gtk.DestDefaults.ALL, self.view.targets, Gdk.DragAction.COPY | Gdk.DragAction.DEFAULT | Gdk.DragAction.MOVE) self.connect('drag-motion', self.on_drag_motion) self.connect('drag-leave', self.on_drag_leave) self.connect('drag-data-received', self.on_drag_data_received) self.view.connect('drag-motion', self.on_drag_motion) self.view.connect('drag-leave', self.on_drag_leave) event.add_ui_callback(self.on_track_tags_changed, 'track_tags_changed') event.add_ui_callback(self.on_option_set, 'plugin_minimode_option_set') self.on_option_set('plugin_minimode_option_set', settings, 'plugin/minimode/track_title_format') def destroy(self): """ Cleanups """ self.tooltip.destroy() QueueAdapter.destroy(self) Gtk.ToggleButton.destroy(self) def update_playlist(self, playlist): """ Updates the internally stored playlist """ columns = self.view.get_model().columns model = PlaylistModel(playlist, columns, player.PLAYER) self.view.set_model(model) def do_scroll_event(self, event): """ Changes the current track """ if event.direction == Gdk.ScrollDirection.UP: self.view.playlist.prev() elif event.direction == Gdk.ScrollDirection.DOWN: self.view.playlist.next() else: return position = self.view.playlist.current_position try: track = self.view.playlist[position] except IndexError: pass else: player.QUEUE.play(track) def do_toggled(self): """ Shows or hides the playlist """ if self.get_active(): self.arrow.props.arrow_type = Gtk.ArrowType.DOWN self.popup.show_all() else: self.popup.hide() self.arrow.props.arrow_type = Gtk.ArrowType.RIGHT def on_accelerator_activate(self, accel_group, acceleratable, keyval, modifier): """ Shows the current track """ self.view.scroll_to_cell(self.view.playlist.current_position) self.view.set_cursor(self.view.playlist.current_position) def on_drag_motion(self, widget, context, x, y, time): """ Prepares to show the playlist """ # Defer display of the playlist if self._drag_motion_timeout_id is None: self._drag_motion_timeout_id = GLib.timeout_add( 500, lambda: self.set_active(True)) # Prevent hiding of the playlist if self._drag_leave_timeout_id is not None: GLib.source_remove(self._drag_leave_timeout_id) self._drag_leave_timeout_id = None def on_drag_leave(self, widget, context, time): """ Prepares to hide the playlist """ # Enable display of the playlist on re-enter if self._drag_motion_timeout_id is not None: GLib.source_remove(self._drag_motion_timeout_id) self._drag_motion_timeout_id = None if self._drag_leave_timeout_id is not None: GLib.source_remove(self._drag_leave_timeout_id) # Defer hiding of the playlist self._drag_leave_timeout_id = GLib.timeout_add( 500, lambda: self.set_active(False)) def on_drag_data_received(self, widget, context, x, y, selection, info, time): """ Handles dropped data """ # Enable display of the playlist on re-enter if self._drag_motion_timeout_id is not None: GLib.source_remove(self._drag_motion_timeout_id) self._drag_motion_timeout_id = None # Enable hiding of the playlist on re-enter if self._drag_leave_timeout_id is not None: GLib.source_remove(self._drag_leave_timeout_id) self._drag_leave_timeout_id = None self.view.emit('drag-data-received', context, x, y, selection, info, time) def on_popup_show(self, widget): if not self.get_active(): self.set_active(True) def on_popup_hide(self, widget): if self.get_active(): self.set_active(False) def on_popup_configure_event(self, widget, event): """ Saves the window size after resizing """ width = settings.get_option( 'plugin/minimode/' 'playlist_button_popup_width', 350) height = settings.get_option( 'plugin/minimode/' 'playlist_button_popup_height', 400) if event.width != width: settings.set_option( 'plugin/minimode/' 'playlist_button_popup_width', event.width) if event.height != height: settings.set_option( 'plugin/minimode/' 'playlist_button_popup_height', event.height) def on_queue_current_playlist_changed(self, event, queue, playlist): """ Updates the list on queue changes """ GLib.idle_add(self.update_playlist, playlist) def on_queue_current_position_changed(self, event, playlist, positions): """ Updates the list on queue changes """ try: track = playlist[positions[0]] except IndexError: text = '' else: text = self.formatter.format(track) GLib.idle_add(self.label.set_text, text) def on_track_tags_changed(self, event, track, tag): """ Updates the button on tag changes """ playlist = self.view.playlist track_position = playlist.index(track) if track in playlist and track_position == playlist.current_position: self.label.set_text(self.formatter.format(track)) def on_option_set(self, event, settings, option): """ Updates control upon setting change """ if option == 'plugin/minimode/track_title_format': self.formatter.set_property( 'format', settings.get_option(option, _('$tracknumber - $title')))
def __init__(self): Gtk.ToggleButton.__init__(self) BaseControl.__init__(self) QueueAdapter.__init__(self, player.QUEUE) self.set_focus_on_click(False) self.set_size_request(200, -1) box = Gtk.Box() self.arrow = Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.OUT) box.pack_start(self.arrow, False, True, 0) self.label = Gtk.Label(label='') self.label.props.ellipsize = Pango.EllipsizeMode.END box.pack_start(self.label, True, True, 0) self.add(box) self.formatter = TrackFormatter( settings.get_option( 'plugin/minimode/track_title_format', '$tracknumber - $title' ) ) self.view = PlaylistView(player.QUEUE.current_playlist, player.PLAYER) self.popup = AttachedWindow(self) self.popup.set_default_size( settings.get_option('plugin/minimode/' 'playlist_button_popup_width', 350), settings.get_option('plugin/minimode/' 'playlist_button_popup_height', 400), ) scrollwindow = Gtk.ScrolledWindow() scrollwindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scrollwindow.set_shadow_type(Gtk.ShadowType.IN) scrollwindow.add(self.view) self.popup.add(scrollwindow) self.popup.connect('show', self.on_popup_show) self.popup.connect('hide', self.on_popup_hide) self.popup.connect('configure-event', self.on_popup_configure_event) accel_group = Gtk.AccelGroup() key, modifier = Gtk.accelerator_parse('<Primary>J') accel_group.connect( key, modifier, Gtk.AccelFlags.VISIBLE, self.on_accelerator_activate ) self.popup.add_accel_group(accel_group) self.tooltip = TrackToolTip(self, player.PLAYER) self.tooltip.set_auto_update(True) if player.PLAYER.current is not None: self.label.set_text(self.formatter.format(player.PLAYER.current)) self._drag_motion_timeout_id = None self._drag_leave_timeout_id = None self.drag_dest_set( Gtk.DestDefaults.ALL, self.view.targets, Gdk.DragAction.COPY | Gdk.DragAction.DEFAULT | Gdk.DragAction.MOVE, ) self.connect('drag-motion', self.on_drag_motion) self.connect('drag-leave', self.on_drag_leave) self.connect('drag-data-received', self.on_drag_data_received) self.view.connect('drag-motion', self.on_drag_motion) self.view.connect('drag-leave', self.on_drag_leave) event.add_ui_callback(self.on_track_tags_changed, 'track_tags_changed') event.add_ui_callback(self.on_option_set, 'plugin_minimode_option_set') self.on_option_set( 'plugin_minimode_option_set', settings, 'plugin/minimode/track_title_format' )
class PlaylistButtonControl(Gtk.ToggleButton, BaseControl, QueueAdapter): name = 'playlist_button' title = _('Playlist button') description = _('Access the current playlist') __gsignals__ = {'scroll-event': 'override'} def __init__(self): Gtk.ToggleButton.__init__(self) BaseControl.__init__(self) QueueAdapter.__init__(self, player.QUEUE) self.set_focus_on_click(False) self.set_size_request(200, -1) box = Gtk.Box() self.arrow = Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.OUT) box.pack_start(self.arrow, False, True, 0) self.label = Gtk.Label(label='') self.label.props.ellipsize = Pango.EllipsizeMode.END box.pack_start(self.label, True, True, 0) self.add(box) self.formatter = TrackFormatter( settings.get_option( 'plugin/minimode/track_title_format', '$tracknumber - $title' ) ) self.view = PlaylistView(player.QUEUE.current_playlist, player.PLAYER) self.popup = AttachedWindow(self) self.popup.set_default_size( settings.get_option('plugin/minimode/' 'playlist_button_popup_width', 350), settings.get_option('plugin/minimode/' 'playlist_button_popup_height', 400), ) scrollwindow = Gtk.ScrolledWindow() scrollwindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scrollwindow.set_shadow_type(Gtk.ShadowType.IN) scrollwindow.add(self.view) self.popup.add(scrollwindow) self.popup.connect('show', self.on_popup_show) self.popup.connect('hide', self.on_popup_hide) self.popup.connect('configure-event', self.on_popup_configure_event) accel_group = Gtk.AccelGroup() key, modifier = Gtk.accelerator_parse('<Primary>J') accel_group.connect( key, modifier, Gtk.AccelFlags.VISIBLE, self.on_accelerator_activate ) self.popup.add_accel_group(accel_group) self.tooltip = TrackToolTip(self, player.PLAYER) self.tooltip.set_auto_update(True) if player.PLAYER.current is not None: self.label.set_text(self.formatter.format(player.PLAYER.current)) self._drag_motion_timeout_id = None self._drag_leave_timeout_id = None self.drag_dest_set( Gtk.DestDefaults.ALL, self.view.targets, Gdk.DragAction.COPY | Gdk.DragAction.DEFAULT | Gdk.DragAction.MOVE, ) self.connect('drag-motion', self.on_drag_motion) self.connect('drag-leave', self.on_drag_leave) self.connect('drag-data-received', self.on_drag_data_received) self.view.connect('drag-motion', self.on_drag_motion) self.view.connect('drag-leave', self.on_drag_leave) event.add_ui_callback(self.on_track_tags_changed, 'track_tags_changed') event.add_ui_callback(self.on_option_set, 'plugin_minimode_option_set') self.on_option_set( 'plugin_minimode_option_set', settings, 'plugin/minimode/track_title_format' ) def destroy(self): """ Cleanups """ self.tooltip.destroy() QueueAdapter.destroy(self) Gtk.ToggleButton.destroy(self) def update_playlist(self, playlist): """ Updates the internally stored playlist """ columns = self.view.model.column_names model = PlaylistModel(playlist, columns, player.PLAYER, self.view) self.view.set_model(model) def do_scroll_event(self, event): """ Changes the current track """ if event.direction == Gdk.ScrollDirection.UP: self.view.playlist.prev() elif event.direction == Gdk.ScrollDirection.DOWN: self.view.playlist.next() else: return position = self.view.playlist.current_position try: track = self.view.playlist[position] except IndexError: pass else: player.QUEUE.play(track) def do_toggled(self): """ Shows or hides the playlist """ if self.get_active(): self.arrow.props.arrow_type = Gtk.ArrowType.DOWN self.popup.show_all() else: self.popup.hide() self.arrow.props.arrow_type = Gtk.ArrowType.RIGHT def on_accelerator_activate(self, accel_group, acceleratable, keyval, modifier): """ Shows the current track """ self.view.scroll_to_cell(self.view.playlist.current_position) self.view.set_cursor(self.view.playlist.current_position) def on_drag_motion(self, widget, context, x, y, time): """ Prepares to show the playlist """ # Defer display of the playlist if self._drag_motion_timeout_id is None: self._drag_motion_timeout_id = GLib.timeout_add( 500, lambda: self.set_active(True) ) # Prevent hiding of the playlist if self._drag_leave_timeout_id is not None: GLib.source_remove(self._drag_leave_timeout_id) self._drag_leave_timeout_id = None def on_drag_leave(self, widget, context, time): """ Prepares to hide the playlist """ # Enable display of the playlist on re-enter if self._drag_motion_timeout_id is not None: GLib.source_remove(self._drag_motion_timeout_id) self._drag_motion_timeout_id = None if self._drag_leave_timeout_id is not None: GLib.source_remove(self._drag_leave_timeout_id) # Defer hiding of the playlist self._drag_leave_timeout_id = GLib.timeout_add( 500, lambda: self.set_active(False) ) def on_drag_data_received(self, widget, context, x, y, selection, info, time): """ Handles dropped data """ # Enable display of the playlist on re-enter if self._drag_motion_timeout_id is not None: GLib.source_remove(self._drag_motion_timeout_id) self._drag_motion_timeout_id = None # Enable hiding of the playlist on re-enter if self._drag_leave_timeout_id is not None: GLib.source_remove(self._drag_leave_timeout_id) self._drag_leave_timeout_id = None self.view.emit('drag-data-received', context, x, y, selection, info, time) def on_popup_show(self, widget): if not self.get_active(): self.set_active(True) def on_popup_hide(self, widget): if self.get_active(): self.set_active(False) def on_popup_configure_event(self, widget, event): """ Saves the window size after resizing """ width = settings.get_option( 'plugin/minimode/' 'playlist_button_popup_width', 350 ) height = settings.get_option( 'plugin/minimode/' 'playlist_button_popup_height', 400 ) if event.width != width: settings.set_option( 'plugin/minimode/' 'playlist_button_popup_width', event.width ) if event.height != height: settings.set_option( 'plugin/minimode/' 'playlist_button_popup_height', event.height ) def on_queue_current_playlist_changed(self, event, queue, playlist): """ Updates the list on queue changes """ GLib.idle_add(self.update_playlist, playlist) def on_queue_current_position_changed(self, event, playlist, positions): """ Updates the list on queue changes """ try: track = playlist[positions[0]] except IndexError: text = '' else: text = self.formatter.format(track) GLib.idle_add(self.label.set_text, text) def on_track_tags_changed(self, event, track, tags): """ Updates the button on tag changes """ playlist = self.view.playlist if track not in playlist: return track_position = playlist.index(track) if track_position == playlist.current_position: self.label.set_text(self.formatter.format(track)) def on_option_set(self, event, settings, option): """ Updates control upon setting change """ if option == 'plugin/minimode/track_title_format': self.formatter.set_property( 'format', settings.get_option(option, _('$tracknumber - $title')) )
def __init__(self): gtk.ToggleButton.__init__(self) BaseControl.__init__(self) QueueAdapter.__init__(self, player.QUEUE) self.set_focus_on_click(False) self.set_size_request(200, -1) box = gtk.HBox() self.arrow = gtk.Arrow(gtk.ARROW_RIGHT, gtk.SHADOW_OUT) box.pack_start(self.arrow, expand=False) self.label = gtk.Label('') self.label.props.ellipsize = pango.ELLIPSIZE_END box.pack_start(self.label) self.add(box) self.formatter = TrackFormatter( settings.get_option('plugin/minimode/track_title_format', '$tracknumber - $title')) self.view = PlaylistView(player.QUEUE.current_playlist, player.PLAYER) self.popup = AttachedWindow(self) self.popup.set_default_size( settings.get_option('plugin/minimode/' 'playlist_button_popup_width', 350), settings.get_option('plugin/minimode/' 'playlist_button_popup_height', 400) ) scrollwindow = gtk.ScrolledWindow() scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrollwindow.set_shadow_type(gtk.SHADOW_IN) scrollwindow.add(self.view) self.popup.add(scrollwindow) self.popup.connect('configure-event', self.on_popup_configure_event) accel_group = gtk.AccelGroup() key, modifier = gtk.accelerator_parse('<Control>J') accel_group.connect_group(key, modifier, gtk.ACCEL_VISIBLE, self.on_accelerator_activate) self.popup.add_accel_group(accel_group) self.tooltip = TrackToolTip(self, player.PLAYER) self.tooltip.set_auto_update(True) if player.PLAYER.current is not None: self.label.set_text(self.formatter.format(player.PLAYER.current)) self._drag_motion_timeout_id = None self._drag_leave_timeout_id = None self._toplevel_hide_id = None self._toplevel_window_state_event_id = None self.drag_dest_set(gtk.DEST_DEFAULT_ALL, self.view.targets, gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_MOVE) self.connect('drag-motion', self.on_drag_motion) self.connect('drag-leave', self.on_drag_leave) self.connect('drag-data-received', self.on_drag_data_received) self.view.connect('drag-motion', self.on_drag_motion) self.view.connect('drag-leave', self.on_drag_leave) event.add_callback(self.on_track_tags_changed, 'track_tags_changed') event.add_callback(self.on_option_set, 'plugin_minimode_option_set') self.on_option_set('plugin_minimode_option_set', settings, 'plugin/minimode/track_title_format')
class PlaylistButtonControl(gtk.ToggleButton, BaseControl, QueueAdapter): name = 'playlist_button' title = _('Playlist button') description = _('Access the current playlist') __gsignals__ = {'scroll-event': 'override'} def __init__(self): gtk.ToggleButton.__init__(self) BaseControl.__init__(self) QueueAdapter.__init__(self, player.QUEUE) self.set_focus_on_click(False) self.set_size_request(200, -1) box = gtk.HBox() self.arrow = gtk.Arrow(gtk.ARROW_RIGHT, gtk.SHADOW_OUT) box.pack_start(self.arrow, expand=False) self.label = gtk.Label('') self.label.props.ellipsize = pango.ELLIPSIZE_END box.pack_start(self.label) self.add(box) self.formatter = TrackFormatter( settings.get_option('plugin/minimode/track_title_format', '$tracknumber - $title')) self.view = PlaylistView(player.QUEUE.current_playlist, player.PLAYER) self.popup = AttachedWindow(self) self.popup.set_default_size( settings.get_option('plugin/minimode/' 'playlist_button_popup_width', 350), settings.get_option('plugin/minimode/' 'playlist_button_popup_height', 400) ) scrollwindow = gtk.ScrolledWindow() scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrollwindow.set_shadow_type(gtk.SHADOW_IN) scrollwindow.add(self.view) self.popup.add(scrollwindow) self.popup.connect('configure-event', self.on_popup_configure_event) accel_group = gtk.AccelGroup() key, modifier = gtk.accelerator_parse('<Control>J') accel_group.connect_group(key, modifier, gtk.ACCEL_VISIBLE, self.on_accelerator_activate) self.popup.add_accel_group(accel_group) self.tooltip = TrackToolTip(self, player.PLAYER) self.tooltip.set_auto_update(True) if player.PLAYER.current is not None: self.label.set_text(self.formatter.format(player.PLAYER.current)) self._drag_motion_timeout_id = None self._drag_leave_timeout_id = None self._toplevel_hide_id = None self._toplevel_window_state_event_id = None self.drag_dest_set(gtk.DEST_DEFAULT_ALL, self.view.targets, gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_MOVE) self.connect('drag-motion', self.on_drag_motion) self.connect('drag-leave', self.on_drag_leave) self.connect('drag-data-received', self.on_drag_data_received) self.view.connect('drag-motion', self.on_drag_motion) self.view.connect('drag-leave', self.on_drag_leave) event.add_callback(self.on_track_tags_changed, 'track_tags_changed') event.add_callback(self.on_option_set, 'plugin_minimode_option_set') self.on_option_set('plugin_minimode_option_set', settings, 'plugin/minimode/track_title_format') def destroy(self): """ Cleanups """ self.tooltip.destroy() QueueAdapter.destroy(self) gtk.ToggleButton.destroy(self) def update_playlist(self, playlist): """ Updates the internally stored playlist """ columns = self.view.get_model().columns model = PlaylistModel(playlist, columns, player.PLAYER) self.view.set_model(model) def do_hierarchy_changed(self, previous_toplevel): """ Sets up automatic hiding on parent hide """ if self._toplevel_hide_id is not None: previous_toplevel.disconnect( self._toplevel_hide_id) previous_toplevel.disconnect( self._toplevel_window_state_event_id) toplevel = self.get_toplevel() if isinstance(toplevel, gtk.Window): self._toplevel_hide_id = toplevel.connect( 'hide', self.on_toplevel_hide) self._toplevel_window_state_event_id = toplevel.connect( 'window-state-event', self.on_toplevel_window_state_event) self.popup.set_transient_for(toplevel) def do_scroll_event(self, event): """ Changes the current track """ if event.direction == gtk.gdk.SCROLL_UP: self.view.playlist.prev() elif event.direction == gtk.gdk.SCROLL_DOWN: self.view.playlist.next() else: return position = self.view.playlist.current_position try: track = self.view.playlist[position] except IndexError: pass else: player.QUEUE.play(track) def do_toggled(self): """ Shows or hides the playlist """ if self.get_active(): self.arrow.props.arrow_type = gtk.ARROW_DOWN self.popup.show_all() else: self.popup.hide() self.arrow.props.arrow_type = gtk.ARROW_RIGHT def on_accelerator_activate(self, accel_group, acceleratable, keyval, modifier): """ Shows the current track """ self.view.scroll_to_cell(self.view.playlist.current_position) self.view.set_cursor(self.view.playlist.current_position) def on_drag_motion(self, widget, context, x, y, time): """ Prepares to show the playlist """ # Defer display of the playlist if self._drag_motion_timeout_id is None: self._drag_motion_timeout_id = glib.timeout_add( 500, lambda: self.set_active(True)) # Prevent hiding of the playlist if self._drag_leave_timeout_id is not None: glib.source_remove(self._drag_leave_timeout_id) self._drag_leave_timeout_id = None def on_drag_leave(self, widget, context, time): """ Prepares to hide the playlist """ # Enable display of the playlist on re-enter if self._drag_motion_timeout_id is not None: glib.source_remove(self._drag_motion_timeout_id) self._drag_motion_timeout_id = None if self._drag_leave_timeout_id is not None: glib.source_remove(self._drag_leave_timeout_id) # Defer hiding of the playlist self._drag_leave_timeout_id = glib.timeout_add( 500, lambda: self.set_active(False)) def on_drag_data_received(self, widget, context, x, y, selection, info, time): """ Handles dropped data """ # Enable display of the playlist on re-enter if self._drag_motion_timeout_id is not None: glib.source_remove(self._drag_motion_timeout_id) self._drag_motion_timeout_id = None # Enable hiding of the playlist on re-enter if self._drag_leave_timeout_id is not None: glib.source_remove(self._drag_leave_timeout_id) self._drag_leave_timeout_id = None self.view.emit('drag-data-received', context, x, y, selection, info, time) def on_toplevel_hide(self, widget): """ Hides the playlist """ self.set_active(False) def on_toplevel_window_state_event(self, widget, event): """ Hides the playlist """ self.set_active(False) def on_popup_configure_event(self, widget, event): """ Saves the window size after resizing """ width = settings.get_option('plugin/minimode/' 'playlist_button_popup_width', 350) height = settings.get_option('plugin/minimode/' 'playlist_button_popup_height', 400) if event.width != width: settings.set_option('plugin/minimode/' 'playlist_button_popup_width', event.width) if event.height != height: settings.set_option('plugin/minimode/' 'playlist_button_popup_height', event.height) def on_queue_current_playlist_changed(self, event, queue, playlist): """ Updates the list on queue changes """ glib.idle_add(self.update_playlist, playlist) def on_queue_current_position_changed(self, event, playlist, positions): """ Updates the list on queue changes """ try: track = playlist[positions[0]] except IndexError: text = '' else: text = self.formatter.format(track) glib.idle_add(self.label.set_text, text) def on_track_tags_changed(self, event, track, tag): """ Updates the button on tag changes """ playlist = self.view.playlist track_position = playlist.index(track) if track in playlist and track_position == playlist.current_position: glib.idle_add(self.label.set_text, self.formatter.format(track)) def on_option_set(self, event, settings, option): """ Updates control upon setting change """ if option == 'plugin/minimode/track_title_format': glib.idle_add(self.formatter.set_property, 'format', settings.get_option(option, _('$tracknumber - $title')) )
def __init__(self): gtk.ToggleButton.__init__(self) BaseControl.__init__(self) QueueAdapter.__init__(self, player.QUEUE) self.set_focus_on_click(False) self.set_size_request(200, -1) box = gtk.HBox() self.arrow = gtk.Arrow(gtk.ARROW_RIGHT, gtk.SHADOW_OUT) box.pack_start(self.arrow, expand=False) self.label = gtk.Label('') self.label.props.ellipsize = pango.ELLIPSIZE_END box.pack_start(self.label) self.add(box) self.formatter = TrackFormatter( settings.get_option('plugin/minimode/track_title_format', '$tracknumber - $title')) self.view = PlaylistView(player.QUEUE.current_playlist, player.PLAYER) self.popup = AttachedWindow(self) self.popup.set_default_size( settings.get_option( 'plugin/minimode/' 'playlist_button_popup_width', 350), settings.get_option( 'plugin/minimode/' 'playlist_button_popup_height', 400)) scrollwindow = gtk.ScrolledWindow() scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrollwindow.set_shadow_type(gtk.SHADOW_IN) scrollwindow.add(self.view) self.popup.add(scrollwindow) self.popup.connect('configure-event', self.on_popup_configure_event) accel_group = gtk.AccelGroup() key, modifier = gtk.accelerator_parse('<Control>J') accel_group.connect_group(key, modifier, gtk.ACCEL_VISIBLE, self.on_accelerator_activate) self.popup.add_accel_group(accel_group) self.tooltip = TrackToolTip(self, player.PLAYER) self.tooltip.set_auto_update(True) if player.PLAYER.current is not None: self.label.set_text(self.formatter.format(player.PLAYER.current)) self._drag_motion_timeout_id = None self._drag_leave_timeout_id = None self._toplevel_hide_id = None self._toplevel_window_state_event_id = None self.drag_dest_set( gtk.DEST_DEFAULT_ALL, self.view.targets, gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_MOVE) self.connect('drag-motion', self.on_drag_motion) self.connect('drag-leave', self.on_drag_leave) self.connect('drag-data-received', self.on_drag_data_received) self.view.connect('drag-motion', self.on_drag_motion) self.view.connect('drag-leave', self.on_drag_leave) event.add_callback(self.on_track_tags_changed, 'track_tags_changed') event.add_callback(self.on_option_set, 'plugin_minimode_option_set') self.on_option_set('plugin_minimode_option_set', settings, 'plugin/minimode/track_title_format')
class PlaylistButtonControl(gtk.ToggleButton, BaseControl, QueueAdapter): name = 'playlist_button' title = _('Playlist button') description = _('Access the current playlist') __gsignals__ = {'scroll-event': 'override'} def __init__(self): gtk.ToggleButton.__init__(self) BaseControl.__init__(self) QueueAdapter.__init__(self, player.QUEUE) self.set_focus_on_click(False) self.set_size_request(200, -1) box = gtk.HBox() self.arrow = gtk.Arrow(gtk.ARROW_RIGHT, gtk.SHADOW_OUT) box.pack_start(self.arrow, expand=False) self.label = gtk.Label('') self.label.props.ellipsize = pango.ELLIPSIZE_END box.pack_start(self.label) self.add(box) self.formatter = TrackFormatter( settings.get_option('plugin/minimode/track_title_format', '$tracknumber - $title')) self.view = PlaylistView(player.QUEUE.current_playlist, player.PLAYER) self.popup = AttachedWindow(self) self.popup.set_default_size( settings.get_option( 'plugin/minimode/' 'playlist_button_popup_width', 350), settings.get_option( 'plugin/minimode/' 'playlist_button_popup_height', 400)) scrollwindow = gtk.ScrolledWindow() scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrollwindow.set_shadow_type(gtk.SHADOW_IN) scrollwindow.add(self.view) self.popup.add(scrollwindow) self.popup.connect('configure-event', self.on_popup_configure_event) accel_group = gtk.AccelGroup() key, modifier = gtk.accelerator_parse('<Control>J') accel_group.connect_group(key, modifier, gtk.ACCEL_VISIBLE, self.on_accelerator_activate) self.popup.add_accel_group(accel_group) self.tooltip = TrackToolTip(self, player.PLAYER) self.tooltip.set_auto_update(True) if player.PLAYER.current is not None: self.label.set_text(self.formatter.format(player.PLAYER.current)) self._drag_motion_timeout_id = None self._drag_leave_timeout_id = None self._toplevel_hide_id = None self._toplevel_window_state_event_id = None self.drag_dest_set( gtk.DEST_DEFAULT_ALL, self.view.targets, gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_MOVE) self.connect('drag-motion', self.on_drag_motion) self.connect('drag-leave', self.on_drag_leave) self.connect('drag-data-received', self.on_drag_data_received) self.view.connect('drag-motion', self.on_drag_motion) self.view.connect('drag-leave', self.on_drag_leave) event.add_callback(self.on_track_tags_changed, 'track_tags_changed') event.add_callback(self.on_option_set, 'plugin_minimode_option_set') self.on_option_set('plugin_minimode_option_set', settings, 'plugin/minimode/track_title_format') def destroy(self): """ Cleanups """ self.tooltip.destroy() QueueAdapter.destroy(self) gtk.ToggleButton.destroy(self) def update_playlist(self, playlist): """ Updates the internally stored playlist """ columns = self.view.get_model().columns model = PlaylistModel(playlist, columns, player.PLAYER) self.view.set_model(model) def do_hierarchy_changed(self, previous_toplevel): """ Sets up automatic hiding on parent hide """ if self._toplevel_hide_id is not None: previous_toplevel.disconnect(self._toplevel_hide_id) previous_toplevel.disconnect(self._toplevel_window_state_event_id) toplevel = self.get_toplevel() if isinstance(toplevel, gtk.Window): self._toplevel_hide_id = toplevel.connect('hide', self.on_toplevel_hide) self._toplevel_window_state_event_id = toplevel.connect( 'window-state-event', self.on_toplevel_window_state_event) self.popup.set_transient_for(toplevel) def do_scroll_event(self, event): """ Changes the current track """ if event.direction == gtk.gdk.SCROLL_UP: self.view.playlist.prev() elif event.direction == gtk.gdk.SCROLL_DOWN: self.view.playlist.next() else: return position = self.view.playlist.current_position try: track = self.view.playlist[position] except IndexError: pass else: player.QUEUE.play(track) def do_toggled(self): """ Shows or hides the playlist """ if self.get_active(): self.arrow.props.arrow_type = gtk.ARROW_DOWN self.popup.show_all() else: self.popup.hide() self.arrow.props.arrow_type = gtk.ARROW_RIGHT def on_accelerator_activate(self, accel_group, acceleratable, keyval, modifier): """ Shows the current track """ self.view.scroll_to_cell(self.view.playlist.current_position) self.view.set_cursor(self.view.playlist.current_position) def on_drag_motion(self, widget, context, x, y, time): """ Prepares to show the playlist """ # Defer display of the playlist if self._drag_motion_timeout_id is None: self._drag_motion_timeout_id = glib.timeout_add( 500, lambda: self.set_active(True)) # Prevent hiding of the playlist if self._drag_leave_timeout_id is not None: glib.source_remove(self._drag_leave_timeout_id) self._drag_leave_timeout_id = None def on_drag_leave(self, widget, context, time): """ Prepares to hide the playlist """ # Enable display of the playlist on re-enter if self._drag_motion_timeout_id is not None: glib.source_remove(self._drag_motion_timeout_id) self._drag_motion_timeout_id = None if self._drag_leave_timeout_id is not None: glib.source_remove(self._drag_leave_timeout_id) # Defer hiding of the playlist self._drag_leave_timeout_id = glib.timeout_add( 500, lambda: self.set_active(False)) def on_drag_data_received(self, widget, context, x, y, selection, info, time): """ Handles dropped data """ # Enable display of the playlist on re-enter if self._drag_motion_timeout_id is not None: glib.source_remove(self._drag_motion_timeout_id) self._drag_motion_timeout_id = None # Enable hiding of the playlist on re-enter if self._drag_leave_timeout_id is not None: glib.source_remove(self._drag_leave_timeout_id) self._drag_leave_timeout_id = None self.view.emit('drag-data-received', context, x, y, selection, info, time) def on_toplevel_hide(self, widget): """ Hides the playlist """ self.set_active(False) def on_toplevel_window_state_event(self, widget, event): """ Hides the playlist """ self.set_active(False) def on_popup_configure_event(self, widget, event): """ Saves the window size after resizing """ width = settings.get_option( 'plugin/minimode/' 'playlist_button_popup_width', 350) height = settings.get_option( 'plugin/minimode/' 'playlist_button_popup_height', 400) if event.width != width: settings.set_option( 'plugin/minimode/' 'playlist_button_popup_width', event.width) if event.height != height: settings.set_option( 'plugin/minimode/' 'playlist_button_popup_height', event.height) def on_queue_current_playlist_changed(self, event, queue, playlist): """ Updates the list on queue changes """ glib.idle_add(self.update_playlist, playlist) def on_queue_current_position_changed(self, event, playlist, positions): """ Updates the list on queue changes """ try: track = playlist[positions[0]] except IndexError: text = '' else: text = self.formatter.format(track) glib.idle_add(self.label.set_text, text) def on_track_tags_changed(self, event, track, tag): """ Updates the button on tag changes """ playlist = self.view.playlist track_position = playlist.index(track) if track in playlist and track_position == playlist.current_position: glib.idle_add(self.label.set_text, self.formatter.format(track)) def on_option_set(self, event, settings, option): """ Updates control upon setting change """ if option == 'plugin/minimode/track_title_format': glib.idle_add( self.formatter.set_property, 'format', settings.get_option(option, _('$tracknumber - $title')))