From bd0842033bfc054ea5fa6219ae49a6b64e1af1de Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Wed, 27 Mar 2013 13:37:01 +0000 Subject: Syncronize element been playerd with selection in the treeview In PlayList class code, two properties were used to track the item been playes, _current_playing and the method set_cursor to set the position in the treeview. As _current_playing was modified outside of the class, they lost sync. Methods set_curren_playing() and get_current_playing are added and the private prop is not used anymore outside of the class. The method set_cursor is now private. Signed-off-by: Gonzalo Odiard --- diff --git a/activity.py b/activity.py index c780980..d4bf2ff 100644 --- a/activity.py +++ b/activity.py @@ -202,17 +202,16 @@ class JukeboxActivity(activity.Activity): # Select the first stream to be played when Play button will # be pressed - self.playlist_widget._current_playing = 0 + self.playlist_widget.set_current_playing(0) self.control.check_if_next_prev() def songchange(self, direction): - current_playing = self.playlist_widget._current_playing + current_playing = self.playlist_widget.get_current_playing() if direction == 'prev' and current_playing > 0: self.play_index(current_playing - 1) elif direction == 'next' and \ current_playing < len(self.playlist_widget._items) - 1: self.play_index(current_playing + 1) - else: self.emit('playlist-finished') @@ -220,7 +219,7 @@ class JukeboxActivity(activity.Activity): # README: this line is no more necessary because of the # .playing_video() method # self._switch_canvas(show_video=True) - self.playlist_widget._current_playing = index + self.playlist_widget.set_current_playing(index) path = self.playlist_widget._items[index]['path'] if self.playlist_widget.check_available_media(path): @@ -237,7 +236,7 @@ class JukeboxActivity(activity.Activity): # README: this line is no more necessary because of the # .playing_video() method # self._switch_canvas(show_video=True) - self.playlist_widget._current_playing = index + self.playlist_widget.set_current_playing(index) if self.playlist_widget.is_from_journal(path): path = self.playlist_widget.get_path_from_journal(path) @@ -334,7 +333,8 @@ class JukeboxActivity(activity.Activity): logging.error('ERROR MESSAGE: %s', message) logging.error('ERROR DETAIL: %s', detail) - file_path = self.playlist_widget._items[self.playlist_widget._current_playing]['path'] + file_path = self.playlist_widget._items[ + self.playlist_widget.get_current_playing()]['path'] mimetype = mime.get_for_file(file_path) title = _('Error') diff --git a/controls.py b/controls.py index d2484c9..c94afe0 100644 --- a/controls.py +++ b/controls.py @@ -186,7 +186,7 @@ class Controls(GObject.GObject): self.activity.songchange('next') def check_if_next_prev(self): - current_playing = self.activity.playlist_widget._current_playing + current_playing = self.activity.playlist_widget.get_current_playing() if len(self.activity.playlist_widget._items) == 0: # There is no media in the playlist self.prev_button.set_sensitive(False) @@ -195,7 +195,6 @@ class Controls(GObject.GObject): else: self.button.set_sensitive(True) - current_playing = self.activity.playlist_widget._current_playing if current_playing == 0: self.prev_button.set_sensitive(False) else: @@ -227,7 +226,7 @@ class Controls(GObject.GObject): path = self.activity.playlist_widget._items[0]['path'] self.activity.playlist_widget.emit( 'play-index', 0, path) - self.activity.playlist_widget._current_playing = 0 + self.activity.playlist_widget.set_current_playing(0) else: self.activity.player.play() self.activity._switch_canvas(True) diff --git a/playlist.py b/playlist.py index f91110d..d295f79 100644 --- a/playlist.py +++ b/playlist.py @@ -79,7 +79,6 @@ class PlayList(Gtk.ScrolledWindow): self.listview.set_enable_search(False) self.listview.connect('row-activated', self.__on_row_activated) - self.add(self.listview) def __on_row_activated(self, treeview, path, col): @@ -91,10 +90,16 @@ class PlayList(Gtk.ScrolledWindow): path = self._items[index]['path'] available = self._items[index]['available'] if available: - self._current_playing = index - self.set_cursor(index) + self.set_current_playing(index) self.emit('play-index', index, path) + def set_current_playing(self, index): + self._current_playing = index + self._set_cursor(index) + + def get_current_playing(self): + return self._current_playing + def _set_number(self, column, cell, model, it, data): idx = model.get_value(it, COLUMNS['index']) cell.set_property('text', idx + 1) @@ -113,7 +118,7 @@ class PlayList(Gtk.ScrolledWindow): available = model.get_value(it, COLUMNS['available']) cell.set_property('visible', not available) - def set_cursor(self, index): + def _set_cursor(self, index): self.listview.set_cursor((index,)) def delete_selected_items(self): -- cgit v0.9.1