[gnome-music: 1/2] Small code refactor to _add_item Get rid of invalid pep8 variable and property names, getting rid of



commit db4239afd96a112dffd7afe0c5b5adb47c46d7ae
Author: Seif Lotfy <seif lotfy com>
Date:   Sun Aug 4 12:00:32 2013 +0200

    Small code refactor to _add_item
    Get rid of invalid pep8 variable and property names, getting rid of
    CamelCase

 gnomemusic/toolbar.py |   66 ++++++++++++++++++-----------------
 gnomemusic/view.py    |   94 ++++++++++++++++++++++++------------------------
 gnomemusic/widgets.py |   16 ++++----
 3 files changed, 89 insertions(+), 87 deletions(-)
---
diff --git a/gnomemusic/toolbar.py b/gnomemusic/toolbar.py
index a87c82c..be95568 100644
--- a/gnomemusic/toolbar.py
+++ b/gnomemusic/toolbar.py
@@ -18,48 +18,51 @@ class Toolbar(GObject.GObject):
 
     def __init__(self):
         GObject.GObject.__init__(self)
-        self._stackSwitcher = Gtk.StackSwitcher(margin_top=2, margin_bottom=2)
+        self._stack_switcher = Gtk.StackSwitcher(margin_top=2, margin_bottom=2)
         self._ui = Gtk.Builder()
         self._ui.add_from_resource('/org/gnome/Music/Headerbar.ui')
         self.header_bar = self._ui.get_object('header-bar')
-        self._selectButton = self._ui.get_object('select-button')
-        self._cancelButton = self._ui.get_object('done-button')
-        self._backButton = self._ui.get_object('back-button')
-        self._closeSeparator = self._ui.get_object("close-button-separator")
-        self._closeButton = self._ui.get_object("close-button")
-        self._selectionMenu = self._ui.get_object("selection-menu")
-        self._selectionMenuButton = self._ui.get_object("selection-menu-button")
-        self._selectionMenuButton.set_relief(Gtk.ReliefStyle.NONE)
-        self.header_bar.set_custom_title(self._stackSwitcher)
-        self._searchButton = self._ui.get_object("search-button")
-        self._backButton.connect('clicked', self.on_back_button_clicked)
-        self._closeButton.connect('clicked', self._close_button_clicked)
+        self._select_button = self._ui.get_object('select-button')
+        self._cancel_button = self._ui.get_object('done-button')
+        self._back_button = self._ui.get_object('back-button')
+        self._close_separator = self._ui.get_object("close-button-separator")
+        self._close_button = self._ui.get_object("close-button")
+        self._selection_menu = self._ui.get_object("selection-menu")
+        self._selection_menu_button = self._ui.get_object("selection-menu-button")
+        self._selection_menu_button.set_relief(Gtk.ReliefStyle.NONE)
+        self.header_bar.set_custom_title(self._stack_switcher)
+        self._search_button = self._ui.get_object("search-button")
+        self._back_button.connect('clicked', self.on_back_button_clicked)
+        self._close_button.connect('clicked', self._close_button_clicked)
 
     def _close_button_clicked(self, btn):
-        self._closeButton.get_toplevel().close()
+        self._close_button.get_toplevel().close()
+
+    def reset_header_title(self):
+        self.header_bar.set_custom_title(self._stack_switcher)
 
     def set_stack(self, stack):
-        self._stackSwitcher.set_stack(stack)
+        self._stack_switcher.set_stack(stack)
 
     def get_stack(self):
-        return self._stackSwitcher.get_stack()
+        return self._stack_switcher.get_stack()
 
     def set_selection_mode(self, selectionMode):
         self._selectionMode = selectionMode
         if selectionMode:
-            self._selectButton.hide()
-            self._cancelButton.show()
+            self._select_button.hide()
+            self._cancel_button.show()
             self.header_bar.get_style_context().add_class('selection-mode')
-            self._cancelButton.get_style_context().remove_class('selection-mode')
+            self._cancel_button.get_style_context().remove_class('selection-mode')
         else:
             self.header_bar.get_style_context().remove_class('selection-mode')
-            self._selectButton.set_active(False)
-            self._selectButton.show()
-            self._cancelButton.hide()
+            self._select_button.set_active(False)
+            self._select_button.show()
+            self._cancel_button.hide()
         self._update()
 
     def on_back_button_clicked(self, widget):
-        view = self._stackSwitcher.get_stack().get_visible_child()
+        view = self._stack_switcher.get_stack().get_visible_child()
         view._back_button_clicked(view)
         self.set_state(ToolbarState.ALBUMS)
 
@@ -71,16 +74,15 @@ class Toolbar(GObject.GObject):
     def _update(self):
         if self._state == ToolbarState.SINGLE:
             self.header_bar.set_custom_title(None)
-            self._backButton.show()
+            self._back_button.show()
         else:
-            self.title = ""
-            self.header_bar.set_custom_title(self._stackSwitcher)
-            self._backButton.hide()
+            self.reset_header_title()
+            self._back_button.hide()
 
         if self._selectionMode:
-            self.header_bar.set_custom_title(self._selectionMenuButton)
-            self._closeSeparator.hide()
-            self._closeButton.hide()
+            self.header_bar.set_custom_title(self._selection_menu_button)
+            self._close_separator.hide()
+            self._close_button.hide()
         else:
-            self._closeSeparator.show()
-            self._closeButton.show()
+            self._close_separator.show()
+            self._close_button.show()
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 6750b12..957e110 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -69,9 +69,9 @@ class ViewContainer(Gtk.Stack):
         self.view.connect('item-activated', self._on_item_activated)
         self._cursor = None
         self.header_bar = header_bar
-        self.header_bar._selectButton.connect(
+        self.header_bar._select_button.connect(
             'toggled', self._on_header_bar_toggled)
-        self.header_bar._cancelButton.connect(
+        self.header_bar._cancel_button.connect(
             'clicked', self._on_cancel_button_clicked)
 
         self.title = title
@@ -164,32 +164,31 @@ class ViewContainer(Gtk.Stack):
         print("populate")
 
     def _add_item(self, source, param, item):
-        if item:
-            self._offset += 1
-            _iter = self._model.append()
-            artist = item.get_string(Grl.METADATA_KEY_ARTIST)
-            if not artist:
-                artist = item.get_author()
-            if not artist:
-                artist = _("Unknown Artist")
-            title = albumArtCache.get_media_title(item)
-            item.set_title(title)
-            try:
-                if item.get_url():
-                    self.player.discoverer.discover_uri(item.get_url())
-                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,
-                                [0, 1, 2, 3, 4, 5, 7, 8, 9, 10],
-                                [str(item.get_id()), "", title,
-                                 artist, self._symbolicIcon, item,
-                                 -1, self.errorIconName, False, True])
-            GLib.idle_add(self._update_album_art, item, _iter)
+        if not item:
+            return
+        self._offset += 1
+        _iter = self._model.append()
+        artist = item.get_string(Grl.METADATA_KEY_ARTIST)\
+            or item.get_author()\
+            or _("Unknown Artist")
+        title = albumArtCache.get_media_title(item)
+        item.set_title(title)
+        try:
+            if item.get_url():
+                self.player.discoverer.discover_uri(item.get_url())
+            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,
+                            [0, 1, 2, 3, 4, 5, 7, 8, 9, 10],
+                            [str(item.get_id()), "", title,
+                             artist, self._symbolicIcon, item,
+                             -1, self.errorIconName, False, True])
+        GLib.idle_add(self._update_album_art, item, _iter)
 
     def _get_remaining_item_count(self):
         count = -1
@@ -299,25 +298,26 @@ class Songs(ViewContainer):
         return False
 
     def _add_item(self, source, param, item):
-        if item:
-            self._offset += 1
-            _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(_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(_iter,
-                                [2, 3, 5, 8, 9, 10],
-                                [albumArtCache.get_media_title(item),
-                                 item.get_string(Grl.METADATA_KEY_ARTIST),
-                                 item, self.errorIconName, False, True])
+        if not item:
+            return
+        self._offset += 1
+        _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(_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(_iter,
+                            [2, 3, 5, 8, 9, 10],
+                            [albumArtCache.get_media_title(item),
+                             item.get_string(Grl.METADATA_KEY_ARTIST),
+                             item, self.errorIconName, False, True])
 
     def _add_list_renderers(self):
         list_widget = self.view.get_generic_view()
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index c2db4e1..09b7ae3 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -191,17 +191,17 @@ class AlbumWidget(Gtk.EventBox):
                                        )
             GLib.idle_add(grilo.populate_album_songs, item.get_id(),
                           self._on_populate_album_songs)
-        header_bar._selectButton.connect('toggled',
-                                         self._on_header_select_button_toggled)
-        header_bar._cancelButton.connect('clicked',
-                                         self._on_header_cancel_button_clicked)
+        header_bar._select_button.connect(
+            'toggled', self._on_header_select_button_toggled)
+        header_bar._cancel_button.connect(
+            'clicked', self._on_header_cancel_button_clicked)
         self.view.connect('view-selection-changed',
                           self._on_view_selection_changed)
         self.view.set_model(self.model)
-        escapedArtist = GLib.markup_escape_text(artist)
-        escapedAlbum = GLib.markup_escape_text(album)
-        self.ui.get_object("artist_label").set_markup(escapedArtist)
-        self.ui.get_object("title_label").set_markup(escapedAlbum)
+        escaped_artist = GLib.markup_escape_text(artist)
+        escaped_album = GLib.markup_escape_text(album)
+        self.ui.get_object("artist_label").set_markup(escaped_artist)
+        self.ui.get_object("title_label").set_markup(escaped_album)
         if (item.get_creation_date()):
             self.ui.get_object("released_label_info").set_text(
                 str(item.get_creation_date().get_year()))


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