[gnome-music/wip/merge: 148/343] General fixes to make things work
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/merge: 148/343] General fixes to make things work
- Date: Thu, 25 Jul 2013 11:25:26 +0000 (UTC)
commit 974457e63023d8bac0e0466a082210663e915320
Author: Seif Lotfy <seif lotfy com>
Date: Tue Jul 16 14:29:09 2013 +0200
General fixes to make things work
* Change albumArtCache.py to use proper python pep8 stylings
* Fix regression in AlbumArtCache to stop iterating non-stop
* Adapt classes to changes in albumArtCache.py
* Fix Minor styling issues
* Fix LoadMore Button behaviour
gnomemusic/albumArtCache.py | 57 +++++++++++++++++++++++-------------------
gnomemusic/grilo.py | 1 -
gnomemusic/player.py | 2 +-
gnomemusic/view.py | 32 ++++++++++++++----------
gnomemusic/widgets.py | 6 ++--
gnomemusic/window.py | 4 +-
6 files changed, 56 insertions(+), 46 deletions(-)
---
diff --git a/gnomemusic/albumArtCache.py b/gnomemusic/albumArtCache.py
index 7200e16..2cd8d3d 100644
--- a/gnomemusic/albumArtCache.py
+++ b/gnomemusic/albumArtCache.py
@@ -26,11 +26,11 @@ class AlbumArtCache:
self._keybuilder_funcs = [
lambda artist, album:
- "album-" + self.normalizeAndHash(artist) +
- "-" + self.normalizeAndHash(album),
+ "album-" + self._normalize_and_hash(artist) +
+ "-" + self._normalize_and_hash(album),
lambda artist, album:
- "album-" + self.normalizeAndHash(album) +
- "-" + self.normalizeAndHash(None)
+ "album-" + self._normalize_and_hash(album) +
+ "-" + self._normalize_and_hash(None)
]
try:
@@ -38,7 +38,7 @@ class AlbumArtCache:
except:
pass
- def makeDefaultIcon(self, width, height):
+ def make_default_icon(self, width, height):
path = "/usr/share/icons/gnome/scalable/places/folder-music-symbolic.svg"
# get a small pixbuf with the given path
icon = GdkPixbuf.Pixbuf.new_from_file_at_scale(path,
@@ -62,9 +62,9 @@ class AlbumArtCache:
icon.get_height() * 3 / 2,
1, 1,
GdkPixbuf.InterpType.NEAREST, 0xff)
- return self.makeIconFrame(result)
+ return self._make_icon_frame(result)
- def makeIconFrame(self, pixbuf):
+ def _make_icon_frame(self, pixbuf):
border = 1.5
pixbuf = pixbuf.scale_simple(pixbuf.get_width() - border * 2,
pixbuf.get_height() - border * 2,
@@ -74,7 +74,7 @@ class AlbumArtCache:
int(pixbuf.get_width() + border * 2),
int(pixbuf.get_height() + border * 2))
ctx = cairo.Context(surface)
- self.drawRoundedPath(ctx, 0, 0,
+ self._draw_rounded_path(ctx, 0, 0,
pixbuf.get_width() + border * 2,
pixbuf.get_height() + border * 2,
3)
@@ -90,7 +90,7 @@ class AlbumArtCache:
return result
- def drawRoundedPath(self, ctx, x, y, width, height, radius):
+ def _draw_rounded_path(self, ctx, x, y, width, height, radius):
degrees = pi / 180
ctx.new_sub_path()
ctx.arc(x + width - radius, y + radius, radius - 0.5, -90 * degrees, 0 * degrees)
@@ -104,22 +104,21 @@ class AlbumArtCache:
ctx.set_source_rgb(1, 1, 1)
ctx.fill()
- def _tryLoad(self, size, artist, album, i, format, callback):
+ def _try_load(self, size, artist, album, i, icon_format, callback):
if i >= len(self._keybuilder_funcs):
- if format == 'jpeg':
- self._tryLoad(size, artist, album, 0, 'png', callback)
+ if icon_format == 'jpeg':
+ self._try_load(size, artist, album, 0, 'png', callback)
else:
- callback(None)
+ callback(None, None)
return
key = self._keybuilder_funcs[i].__call__(artist, album)
- path = GLib.build_filenamev([self.cacheDir, key + '.' + format])
+ path = GLib.build_filenamev([self.cacheDir, key + '.' + icon_format])
file = Gio.File.new_for_path(path)
def on_read_ready(object, res, data=None):
try:
stream = object.read_finish(res)
-
def on_pixbuf_ready(source, res, data=None):
try:
pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(res)
@@ -136,7 +135,8 @@ class AlbumArtCache:
if self.logLookupErrors:
print("ERROR:", error)
- self._tryLoad(size, artist, album, ++i, format, callback)
+ self._try_load(size, artist, album, i+1,
+ icon_format, callback)
GdkPixbuf.Pixbuf.new_from_stream_async(stream, None,
on_pixbuf_ready, None)
@@ -146,14 +146,15 @@ class AlbumArtCache:
if self.logLookupErrors:
print("ERROR:", error)
- self._tryLoad(size, artist, album, ++i, format, callback)
+
+ self._try_load(size, artist, album, i+1, icon_format, callback)
file.read_async(GLib.PRIORITY_DEFAULT, None, on_read_ready, None)
def lookup(self, size, artist, album, callback):
- self._tryLoad(size, artist, album, 0, 'jpeg', callback)
+ self._try_load(size, artist, album, 0, 'jpeg', callback)
- def lookupOrResolve(self, item, width, height, callback):
+ def lookup_or_resolve(self, item, width, height, callback):
artist = None
if item.get_author() is not None:
artist = item.get_author()
@@ -182,16 +183,20 @@ class AlbumArtCache:
options = Grl.OperationOptions.new(None)
options.set_flags(Grl.ResolutionFlags.FULL |
Grl.ResolutionFlags.IDLE_RELAY)
- grilo.tracker.resolve(item, [Grl.METADATA_KEY_THUMBNAIL],
- options, resolve_ready)
+ #FIXME: Tracker goes missing here
+ try:
+ grilo.tracker.resolve(item, [Grl.METADATA_KEY_THUMBNAIL],
+ options, resolve_ready)
+ except:
+ pass
self.lookup(height, artist, album, lookup_ready)
- def normalizeAndHash(self, input_str):
+ def _normalize_and_hash(self, input_str):
normalized = " "
if input_str is not None and len(input_str) > 0:
- normalized = self.stripInvalidEntities(input_str)
+ normalized = self._strip_invalid_entities(input_str)
normalized = GLib.utf8_normalize(normalized, -1,
GLib.NormalizeMode.NFKD)
normalized = normalized.lower()
@@ -199,7 +204,7 @@ class AlbumArtCache:
return GLib.compute_checksum_for_string(GLib.ChecksumType.MD5,
normalized, -1)
- def stripFindNextBlock(self, original, open_char, close_char):
+ def _strip_find_next_block(self, original, open_char, close_char):
open_pos = original.find(open_char)
if open_pos >= 0:
close_pos = original.find(close_char, open_pos + 1)
@@ -207,7 +212,7 @@ class AlbumArtCache:
return [True, open_pos, close_pos]
return [False, -1, -1]
- def stripInvalidEntities(self, original):
+ def _strip_invalid_entities(self, original):
blocks_done = False
invalid_chars = '[()<>\[\]{}_! #$^&*+=|\\\/\"\'?~]'
blocks = [['(', ')'], ['{', '}'], ['[', ']'], ['<', '>']]
@@ -220,7 +225,7 @@ class AlbumArtCache:
for block_pair in blocks:
# Go through blocks, find the earliest block we can
- [success, start, end] = self.stripFindNextBlock(p,
+ [success, start, end] = self._strip_find_next_block(p,
block_pair[0],
block_pair[1])
if success:
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index 52a113b..828ff26 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -2,7 +2,6 @@ from gi.repository import Grl, GLib, GObject
from gnomemusic.query import Query
-
class Grilo(GObject.GObject):
__gsignals__ = {
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index f600203..b406902 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -72,7 +72,7 @@ class Player(GObject.GObject):
self.currentTrack = None
self._lastState = Gst.State.PAUSED
self.cache = AlbumArtCache.getDefault()
- self._symbolicIcon = self.cache.makeDefaultIcon(ART_SIZE, ART_SIZE)
+ self._symbolicIcon = self.cache.make_default_icon(ART_SIZE, ART_SIZE)
Gst.init(None)
self.discoverer = GstPbutils.Discoverer()
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 50cc0a5..ee7410a 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -61,7 +61,7 @@ class ViewContainer(Gtk.Stack):
self._loadMore = Widgets.LoadMoreButton(self._getRemainingItemCount)
box.pack_end(self._loadMore.widget, False, False, 0)
- self._loadMore.widget.connect("clicked", self.populate)
+ self._loadMore.widget.connect("clicked", self._populate)
self.view.connect('item-activated', self._onItemActivated)
self._cursor = None
self.headerBar = headerBar
@@ -76,7 +76,7 @@ class ViewContainer(Gtk.Stack):
self._loadMore.widget.hide()
self._connectView()
self.cache = albumArtCache.getDefault()
- self._symbolicIcon = self.cache.makeDefaultIcon(self._iconHeight, self._iconWidth)
+ self._symbolicIcon = self.cache.make_default_icon(self._iconHeight, self._iconWidth)
self._init = False
grilo.connect('ready', self._onGriloReady)
@@ -148,10 +148,10 @@ class ViewContainer(Gtk.Stack):
end = False
self._loadMore.setBlock(not end)
- def populate():
- pass
+ def populate(self):
+ print ("populate")
- def _addItem(self, source, param, item, a, b, c):
+ def _add_item(self, source, param, item, a, b, c):
if item is not None:
self._offset += 1
iter = self._model.append()
@@ -186,12 +186,17 @@ class ViewContainer(Gtk.Stack):
def _updateAlbumArt(self, item, iter):
def _albumArtCacheLookUp(icon, data=None):
if icon:
- self._model.set_value(iter, 4, albumArtCache.getDefault().makeIconFrame(icon))
+ self._model.set_value(iter, 4,
+ albumArtCache.getDefault()._make_icon_frame(icon))
else:
self._model.set_value(iter, 4, None)
self.emit("album-art-updated")
+ pass
- albumArtCache.getDefault().lookupOrResolve(item, self._iconWidth, self._iconHeight,
_albumArtCacheLookUp)
+ albumArtCache.getDefault().lookup_or_resolve(item,
+ self._iconWidth,
+ self._iconHeight,
+ _albumArtCacheLookUp)
return False
def _addListRenderers(self):
@@ -238,7 +243,7 @@ class Albums(ViewContainer):
def populate(self):
if grilo.tracker is not None:
- grilo.populateAlbums(self._offset, self._addItem)
+ grilo.populateAlbums(self._offset, self._add_item)
class Songs(ViewContainer):
@@ -252,7 +257,8 @@ class Songs(ViewContainer):
self._iconHeight = 32
self._iconWidth = 32
self.cache = albumArtCache.getDefault()
- self._symbolicIcon = self.cache.makeDefaultIcon(self._iconHeight, self._iconWidth)
+ self._symbolicIcon = self.cache.make_default_icon(self._iconHeight,
+ self._iconWidth)
self._addListRenderers()
self.player = player
self.player.connect('playlist-item-changed', self.updateModel)
@@ -273,7 +279,7 @@ class Songs(ViewContainer):
self.iterToClean = currentIter.copy()
return False
- def _addItem(self, source, param, item):
+ def _add_item(self, source, param, item):
if item is not None:
self._offset += 1
iter = self._model.append()
@@ -364,7 +370,7 @@ class Songs(ViewContainer):
def populate(self):
if grilo.tracker is not None:
- grilo.populateSongs(self._offset, self._addItem, None)
+ grilo.populateSongs(self._offset, self._add_item, None)
class Playlist(ViewContainer):
@@ -443,7 +449,7 @@ class Artists (ViewContainer):
self.artistAlbums = Widgets.ArtistAlbums(artist, albums, self.player)
self._artistAlbumsWidget.add(self.artistAlbums)
- def _addItem(self, source, param, item):
+ def _add_item(self, source, param, item):
self._offset += 1
if item is None:
return
@@ -466,5 +472,5 @@ class Artists (ViewContainer):
def populate(self):
if grilo.tracker is not None:
- grilo.populateArtists(self._offset, self._addItem, None)
+ grilo.populateArtists(self._offset, self._add_item, None)
#FIXME: We're emitting self too early, need to wait for all artists to be filled in
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index aa5c085..8163d27 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -38,7 +38,7 @@ class LoadMoreButton:
def _onItemCountChanged(self):
remainingDocs = self._counter()
- visible = remainingDocs <= 0 or self._block
+ visible = remainingDocs >= 0 and not self._block
self.widget.set_visible(visible)
if visible:
@@ -65,7 +65,7 @@ class AlbumWidget(Gtk.EventBox):
self.hbox = Gtk.HBox()
self.iterToClean = None
self.cache = AlbumArtCache.getDefault()
- self._symbolicIcon = self.cache.makeDefaultIcon(256, 256)
+ self._symbolicIcon = self.cache.make_default_icon(256, 256)
self.ui = Gtk.Builder()
self.ui.add_from_resource('/org/gnome/music/AlbumWidget.ui')
@@ -426,7 +426,7 @@ class ArtistAlbumWidget(Gtk.HBox):
self.ui.add_from_resource('/org/gnome/music/ArtistAlbumWidget.ui')
self.cache = AlbumArtCache.getDefault()
- pixbuf = self.cache.makeDefaultIcon(128, 128)
+ pixbuf = self.cache.make_default_icon(128, 128)
GLib.idle_add(self._updateAlbumArt)
self.ui.get_object("cover").set_from_pixbuf(pixbuf)
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index efc278f..554024d 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -3,8 +3,8 @@ from gettext import gettext as _
from gnomemusic.toolbar import Toolbar, ToolbarState
from gnomemusic.player import Player, SelectionToolbar
-import gnomemusic.view as Views
from gnomemusic.query import Query
+import gnomemusic.view as Views
tracker = Tracker.SparqlConnection.get(None)
@@ -77,7 +77,7 @@ class Window(Gtk.ApplicationWindow):
self.views.append(Views.Albums(self.toolbar, self.selectionToolbar, self.player))
self.views.append(Views.Artists(self.toolbar, self.selectionToolbar, self.player))
self.views.append(Views.Songs(self.toolbar, self.selectionToolbar, self.player))
- self.views.append(Views.Playlist(self.toolbar, self.selectionToolbar, self.player))
+ #self.views.append(Views.Playlist(self.toolbar, self.selectionToolbar, self.player))
for i in self.views:
self._stack.add_titled(i, i.title, i.title)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]