[gnome-music: 6/11] fix to #44 and cleanup.



commit 944613ee61ae6d33cc322a7112a5eefdfdd56016
Author: Sai <suman sai14 gmail com>
Date:   Thu Jul 25 12:22:40 2013 +0530

    fix to #44 and cleanup.

 gnomemusic/albumArtCache.py |    2 +-
 gnomemusic/player.py        |    2 +-
 gnomemusic/view.py          |   75 ++++++++++++++++++++++---------------------
 gnomemusic/widgets.py       |   53 +++++++++++++++---------------
 gnomemusic/window.py        |    2 +-
 5 files changed, 68 insertions(+), 66 deletions(-)
---
diff --git a/gnomemusic/albumArtCache.py b/gnomemusic/albumArtCache.py
index f6c864d..bfe04c3 100644
--- a/gnomemusic/albumArtCache.py
+++ b/gnomemusic/albumArtCache.py
@@ -206,7 +206,7 @@ class AlbumArtCache:
                 self.get_from_uri(uri, artist, album, width, height,
                                   callback)
 
-            options = Grl.OperationOptions.new(None)
+            options = Grl.OperationOptions()
             options.set_flags(Grl.ResolutionFlags.FULL |
                               Grl.ResolutionFlags.IDLE_RELAY)
             try:
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index d7760e3..5646a6e 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -430,7 +430,7 @@ class Player(GObject.GObject):
         elif self.repeat == RepeatType.SONG:
             icon = 'media-playlist-repeat-song-symbolic'
 
-        self.repeatBtnImage.set_from_icon_name(icon, 0)
+        self.repeatBtnImage.set_from_icon_name(icon, Gtk.IconSize.MENU)
         self.emit('repeat-mode-changed')
 
     def on_progress_scale_change_value(self, scroll):
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 906ec51..a35be43 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -30,7 +30,7 @@ class ViewContainer(Gtk.Stack):
         self._adjustmentValueId = 0
         self._adjustmentChangedId = 0
         self._scrollbarVisibleId = 0
-        self._model = Gtk.ListStore.new([
+        self._model = Gtk.ListStore(
             GObject.TYPE_STRING,
             GObject.TYPE_STRING,
             GObject.TYPE_STRING,
@@ -42,7 +42,7 @@ class ViewContainer(Gtk.Stack):
             GObject.TYPE_STRING,
             GObject.TYPE_BOOLEAN,
             GObject.TYPE_BOOLEAN
-        ])
+        )
         self.view = Gd.MainView(
             shadow_type=Gtk.ShadowType.NONE
         )
@@ -166,7 +166,7 @@ class ViewContainer(Gtk.Stack):
     def _add_item(self, source, param, item):
         if item:
             self._offset += 1
-            itr = self._model.append()
+            _iter = self._model.append()
             artist = "Unknown"
             if item.get_author():
                 artist = item.get_author()
@@ -177,14 +177,14 @@ class ViewContainer(Gtk.Stack):
             try:
                 if item.get_url():
                     self.player.discoverer.discover_uri(item.get_url())
-                self._model.set(itr,
+                self._model.set(_iter,
                                 [0, 1, 2, 3, 4, 5, 7, 8, 9, 10],
                                 [str(item.get_id()), "", title,
                                  artist, self._symbolicIcon, item,
                                  -1, self.nowPlayingIconName, False, False])
             except:
                 print("failed to discover url " + item.get_url())
-                self._model.set(iter,
+                self._model.set(_iter,
                                 [0, 1, 2, 3, 4, 5, 7, 8, 9, 10],
                                 [str(item.get_id()), "", title,
                                  artist, self._symbolicIcon, item,
@@ -199,13 +199,13 @@ class ViewContainer(Gtk.Stack):
                 count = cursor.get_integer(0)
         return count - self._offset
 
-    def _update_album_art(self, item, itr):
+    def _update_album_art(self, item, _iter):
         albumArtCache.get_default().lookup_or_resolve(
             item,
             self._iconWidth,
             self._iconHeight,
             lambda icon, data: self._model.set_value(
-                itr, 4,
+                _iter, 4,
                 albumArtCache.get_default()._make_icon_frame(icon)
                 if icon else None))
         return False
@@ -231,7 +231,8 @@ class Empty(Gtk.Stack):
 
 class Albums(ViewContainer):
     def __init__(self, header_bar, selection_toolbar, player):
-        ViewContainer.__init__(self, _("Albums"), header_bar, selection_toolbar)
+        ViewContainer.__init__(self, _("Albums"), header_bar,
+                               selection_toolbar)
         self.view.set_view_type(Gd.MainViewType.ICON)
         self.countQuery = Query.ALBUMS_COUNT
         self._albumWidget = Widgets.AlbumWidget(player)
@@ -241,10 +242,10 @@ class Albums(ViewContainer):
         self.set_visible_child(self._grid)
 
     def _on_item_activated(self, widget, id, path):
-        iter = self._model.get_iter(path)
-        title = self._model.get_value(iter, 2)
-        artist = self._model.get_value(iter, 3)
-        item = self._model.get_value(iter, 5)
+        _iter = self._model.get_iter(path)
+        title = self._model.get_value(_iter, 2)
+        artist = self._model.get_value(_iter, 3)
+        item = self._model.get_value(_iter, 5)
         self._albumWidget.update(artist, title, item,
                                  self.header_bar, self.selection_toolbar)
         self.header_bar.set_state(0)
@@ -258,11 +259,11 @@ class Albums(ViewContainer):
             grilo.populate_albums(self._offset, self._add_item)
 
     def show_album_art_data(self):
-        itr = self._model.get_iter_first()
-        while itr:
-            item = self._model.get_value(itr, 5)
-            GLib.idle_add(self._update_album_art, item, itr)
-            itr = self._model.iter_next(itr)
+        _iter = self._model.get_iter_first()
+        while _iter:
+            item = self._model.get_value(_iter, 5)
+            GLib.idle_add(self._update_album_art, item, _iter)
+            _iter = self._model.iter_next(_iter)
 
 
 class Songs(ViewContainer):
@@ -285,9 +286,9 @@ class Songs(ViewContainer):
         self.player.connect('playlist-item-changed', self.update_model)
 
     def _on_item_activated(self, widget, id, path):
-        itr = self._model.get_iter(path)
-        if self._model.get_value(itr, 8) != self.errorIconName:
-            self.player.set_playlist("Songs", None, self._model, itr, 5)
+        _iter = self._model.get_iter(path)
+        if self._model.get_value(_iter, 8) != self.errorIconName:
+            self.player.set_playlist("Songs", None, self._model, _iter, 5)
             self.player.set_playing(True)
 
     def update_model(self, player, playlist, currentIter):
@@ -304,19 +305,19 @@ class Songs(ViewContainer):
     def _add_item(self, source, param, item):
         if item:
             self._offset += 1
-            itr = self._model.append()
+            _iter = self._model.append()
             item.set_title(albumArtCache.get_media_title(item))
             try:
                 if item.get_url():
                     self.player.discoverer.discover_uri(item.get_url())
-                self._model.set(itr,
+                self._model.set(_iter,
                                 [2, 3, 5, 8, 9, 10],
                                 [albumArtCache.get_media_title(item),
                                  item.get_string(Grl.METADATA_KEY_ARTIST),
                                  item, self.nowPlayingIconName, False, False])
             except:
                 print("failed to discover url " + item.get_url())
-                self._model.set(itr,
+                self._model.set(_iter,
                                 [2, 3, 5, 8, 9, 10],
                                 [albumArtCache.get_media_title(item),
                                  item.get_string(Grl.METADATA_KEY_ARTIST),
@@ -382,25 +383,25 @@ class Songs(ViewContainer):
         list_widget.add_renderer(type_renderer,
                                  self._on_list_widget_type_render, None)
 
-    def _on_list_widget_title_render(self, col, cell, model, itr, data):
+    def _on_list_widget_title_render(self, col, cell, model, _iter, data):
         pass
 
-    def _on_list_widget_star_render(self, col, cell, model, itr, data):
+    def _on_list_widget_star_render(self, col, cell, model, _iter, data):
         pass
 
-    def _on_list_widget_duration_render(self, col, cell, model, itr, data):
-        item = model.get_value(itr, 5)
+    def _on_list_widget_duration_render(self, col, cell, model, _iter, data):
+        item = model.get_value(_iter, 5)
         if item:
             seconds = item.get_duration()
             minutes = seconds // 60
             seconds %= 60
             cell.set_property("text", "%i:%02i" % (minutes, seconds))
 
-    def _on_list_widget_artist_render(self, col, cell, model, itr, data):
+    def _on_list_widget_artist_render(self, col, cell, model, _iter, data):
         pass
 
-    def _on_list_widget_type_render(self, coll, cell, model, itr, data):
-        item = model.get_value(itr, 5)
+    def _on_list_widget_type_render(self, coll, cell, model, _iter, data):
+        item = model.get_value(_iter, 5)
         if item:
             cell.set_property("text", item.get_string(Grl.METADATA_KEY_ALBUM))
 
@@ -480,12 +481,12 @@ class Artists (ViewContainer):
         children = self._artistAlbumsWidget.get_children()
         for child in children:
             self._artistAlbumsWidget.remove(child)
-        itr = self._model.get_iter(path)
-        self._last_selection = itr
-        artist = self._model.get_value(itr, 2)
+        _iter = self._model.get_iter(path)
+        self._last_selection = _iter
+        artist = self._model.get_value(_iter, 2)
         albums = self._artists[artist.lower()]["albums"]
         self.artistAlbums = None
-        if (self._model.get_string_from_iter(itr) ==
+        if (self._model.get_string_from_iter(_iter) ==
                 self._model.get_string_from_iter(self._allIter)):
             self.artistAlbums = Widgets.AllArtistsAlbums(self.player)
         else:
@@ -503,9 +504,9 @@ class Artists (ViewContainer):
         if item.get_string(Grl.METADATA_KEY_ARTIST):
             artist = item.get_string(Grl.METADATA_KEY_ARTIST)
         if not artist.lower() in self._artists:
-            itr = self._model.append()
-            self._artists[artist.lower()] = {"iter": itr, "albums": []}
-            self._model.set(itr, 2, artist)
+            _iter = self._model.append()
+            self._artists[artist.lower()] = {"iter": _iter, "albums": []}
+            self._model.set(_iter, 2, artist)
 
         self._artists[artist.lower()]["albums"].append(item)
 
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index 92102be..6d486e8 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -108,15 +108,15 @@ class AlbumWidget(Gtk.EventBox):
         self.show_all()
 
     def _on_item_activated(self, widget, id, path):
-        iter = self.model.get_iter(path)
-        if(self.model.get_value(iter, 7) != ERROR_ICON_NAME):
+        _iter = self.model.get_iter(path)
+        if(self.model.get_value(_iter, 7) != ERROR_ICON_NAME):
             if (self.iterToClean and self.player.playlistId == self.album):
                 item = self.model.get_value(self.iterToClean, 5)
                 title = AlbumArtCache.get_media_title(item)
                 self.model.set_value(self.iterToClean, 0, title)
                 #Hide now playing icon
                 self.model.set_value(self.iterToClean, 6, False)
-            self.player.set_playlist("Album", self.album, self.model, iter, 5)
+            self.player.set_playlist("Album", self.album, self.model, _iter, 5)
             self.player.set_playing(True)
 
     def _add_list_renderers(self):
@@ -243,11 +243,11 @@ class AlbumWidget(Gtk.EventBox):
         if track:
             self.tracks.append(track)
             self.duration = self.duration + track.get_duration()
-            iter = self.model.append()
+            _iter = self.model.append()
             escapedTitle = AlbumArtCache.get_media_title(track, True)
             try:
                 self.player.discoverer.discover_uri(track.get_url())
-                self.model.set(iter,
+                self.model.set(_iter,
                                [0, 1, 2, 3, 4, 5, 7, 9],
                                [escapedTitle,
                                 self.player.seconds_to_string(
@@ -257,7 +257,7 @@ class AlbumWidget(Gtk.EventBox):
             except Exception as err:
                 logging.debug(err.message)
                 logging.debug("failed to discover url " + track.get_url())
-                self.model.set(iter,
+                self.model.set(_iter,
                                [0, 1, 2, 3, 4, 5, 7, 9],
                                [escapedTitle, "", "", "", None,
                                 track, ERROR_ICON_NAME, True])
@@ -265,9 +265,10 @@ class AlbumWidget(Gtk.EventBox):
                 "%d min" % (int(self.duration / 60) + 1))
 
     def _on_look_up(self, pixbuf, path):
+        _iter = self.iterToClean
         if pixbuf:
             self.ui.get_object("cover").set_from_pixbuf(pixbuf)
-            self.model.set(iter, [4], [pixbuf])
+            self.model.set(_iter, [4], [pixbuf])
 
     def update_model(self, player, playlist, currentIter):
         #self is not our playlist, return
@@ -275,9 +276,9 @@ class AlbumWidget(Gtk.EventBox):
             return False
         currentSong = playlist.get_value(currentIter, 5)
         song_passed = False
-        iter = playlist.get_iter_first()
-        while iter:
-            song = playlist.get_value(iter, 5)
+        _iter = playlist.get_iter_first()
+        while _iter:
+            song = playlist.get_value(_iter, 5)
 
             escapedTitle = AlbumArtCache.get_media_title(song, True)
             if (song == currentSong):
@@ -290,10 +291,10 @@ class AlbumWidget(Gtk.EventBox):
             else:
                 title = "<span color='grey'>%s</span>" % escapedTitle
                 iconVisible = False
-            playlist.set_value(iter, 0, title)
-            if(playlist.get_value(iter, 7) != ERROR_ICON_NAME):
-                playlist.set_value(iter, 9, iconVisible)
-            iter = playlist.iter_next(iter)
+            playlist.set_value(_iter, 0, title)
+            if(playlist.get_value(_iter, 7) != ERROR_ICON_NAME):
+                playlist.set_value(_iter, 9, iconVisible)
+            _iter = playlist.iter_next(_iter)
         return False
 
 
@@ -309,14 +310,14 @@ class ArtistAlbums(Gtk.VBox):
         self.ui.get_object("artist").set_label(self.artist)
         self.widgets = []
 
-        self.model = Gtk.ListStore.new([GObject.TYPE_STRING,   # title
-                                        GObject.TYPE_STRING,
-                                        GObject.TYPE_STRING,
-                                        GObject.TYPE_BOOLEAN,  # icon shown
-                                        GObject.TYPE_STRING,   # icon
-                                        GObject.TYPE_OBJECT,   # song object
-                                        GObject.TYPE_BOOLEAN
-                                        ])
+        self.model = Gtk.ListStore(GObject.TYPE_STRING,   # title
+                                   GObject.TYPE_STRING,
+                                   GObject.TYPE_STRING,
+                                   GObject.TYPE_BOOLEAN,  # icon shown
+                                   GObject.TYPE_STRING,   # icon
+                                   GObject.TYPE_OBJECT,   # song object
+                                   GObject.TYPE_BOOLEAN
+                                   )
 
         self._hbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
         self._albumBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
@@ -511,7 +512,7 @@ class ArtistAlbumWidget(Gtk.HBox):
                 )
                 track.song_widget = song_widget
                 itr = self.model.append()
-                song_widget.iter = itr
+                song_widget._iter = itr
                 song_widget.model = self.model
                 song_widget.title = ui.get_object("title")
 
@@ -552,7 +553,7 @@ class ArtistAlbumWidget(Gtk.HBox):
         if pixbuf:
             self.ui.get_object("cover").set_from_pixbuf(pixbuf)
         else:
-            options = Grl.OperationOptions.new(None)
+            options = Grl.OperationOptions()
             options.set_flags(Grl.ResolutionFlags.FULL
                               | Grl.ResolutionFlags.IDLE_RELAY)
             grilo.tracker.resolve(self.album,
@@ -565,8 +566,8 @@ class ArtistAlbumWidget(Gtk.HBox):
                                      self.album.get_title(), 128, 128,
                                      self.get_album_cover)
 
-    def track_selected(self, widget, iter):
+    def track_selected(self, widget, _iter):
         self.player.stop()
         self.player.set_playlist("Artist", self.album,
-                                 widget.model, widget.iter, 5)
+                                 widget.model, widget._iter, 5)
         self.player.set_playing(True)
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 880799c..b30b40e 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -14,7 +14,7 @@ class Window(Gtk.ApplicationWindow):
         Gtk.ApplicationWindow.__init__(self,
                                        application=app,
                                        title=_('Music'))
-        settings = Gio.Settings.new('org.gnome.Music')
+        settings = Gio.Settings('org.gnome.Music')
         self.add_action(settings.create_action('repeat'))
         self.set_size_request(887, 640)
         self._setup_view()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]