Permalink
Browse files

add album rating support and remove entry view menu rating stuff - is…

…sue #71
  • Loading branch information...
1 parent 4fc1ff3 commit b3e1c5ec5e79f3948483e2a0f872c6673145c070 @fossfreedom committed Nov 11, 2012
Showing with 709 additions and 114 deletions.
  1. +15 −5 coverart_album.py
  2. +46 −2 coverart_browser_source.py
  3. +0 −18 coverart_entryview.py
  4. +55 −0 em.py
  5. +593 −0 stars.py
  6. +0 −89 ui/coverart_entryview.ui
View
@@ -852,7 +852,6 @@ def year(self):
if y < 0:
y=0
- #print y
self._year = y
return y
@@ -863,16 +862,14 @@ def rating(self):
Returns this album's rating.
'''
r = self._rating
- #print "here"
- #print r
if r == -1:
num = 0
r = 0
for e in self.entries:
track_rating = e.get_double(RB.RhythmDBPropType.RATING)
- #print track_rating
+
if track_rating > 0:
r += track_rating
num += 1
@@ -883,7 +880,6 @@ def rating(self):
r = 0
self._rating = r
- #print r
return r
@@ -926,6 +922,20 @@ def favourite_entries(self, threshold):
return songs
+ def set_rating(self, rating):
+ '''
+ sets all the RBRhythmDBEntry's for the album
+ to have the given rating
+ '''
+
+ for entry in self.entries:
+ db = AlbumLoader.get_instance().db
+ db.entry_set(entry, RB.RhythmDBPropType.RATING,
+ rating)
+
+
+ AlbumLoader.get_instance().emit('album-modified', self)
+
def _create_tooltip(self):
'''
Utility function that creates the tooltip for this album to set into
View
@@ -31,6 +31,7 @@
from coverart_search import CoverSearchPane
from coverart_browser_prefs import GSetting
from coverart_browser_prefs import CoverLocale
+from stars import ReactiveStar
class CoverArtBrowserSource(RB.Source):
@@ -394,15 +395,27 @@ def _setup_source(self):
self.covers_view.connect('drag-drop', self.on_drag_drop)
self.covers_view.connect('drag-data-received',
self.on_drag_data_received)
+ self.covers_view.connect('selection-changed',
+ self.on_selection_changed)
# setup entry-view objects and widgets
y = self.gs.get_value(self.gs.Path.PLUGIN,
self.gs.PluginKey.PANED_POSITION)
self.paned.set_position(y)
self.entry_view = CoverArtEntryView(self.shell, self)
- self.entry_view.show_all()
- self.notebook.append_page(self.entry_view, Gtk.Label(_("Tracks")))
+ self.stars = ReactiveStar()
+ self.stars.set_rating(0)
+ a = Gtk.Alignment.new(0.5, 0.5, 0, 0)
+ a.add(self.stars)
+
+ self.stars.connect('changed', self.rating_changed_callback)
+
+ vbox = Gtk.VBox()
+ vbox.pack_start(self.entry_view, True, True, 0)
+ vbox.pack_start(a, False, False, 1)
+ vbox.show_all()
+ self.notebook.append_page(vbox, Gtk.Label(_("Tracks")))
# setup cover search pane
try:
@@ -1410,6 +1423,19 @@ def on_drag_drop(self, widget, context, x, y, time):
return result
+ def on_selection_changed(self, widget):
+ '''
+ Callback called when the iconview selection changes
+ '''
+ print "CoverArtBrowser DEBUG - on_selection_changed"
+
+ if len(self.get_selected_albums()) == 1:
+ self.stars.set_rating(self.get_selected_albums()[0].rating)
+ else:
+ self.stars.set_rating(0)
+
+ print "CoverArtBrowser DEBUG - end on_selection_changed"
+
def on_drag_data_received(self, widget, drag_context, x, y, data, info,
time):
'''
@@ -1454,6 +1480,24 @@ def notebook_switch_page_callback(self, notebook, page, page_num):
print "CoverArtBrowser DEBUG - end notebook_switch_page_callback"
+ def rating_changed_callback(self, widget):
+ '''
+ Callback called when the Rating stars is changed
+ '''
+ print "CoverArtBrowser DEBUG - rating_changed_callback"
+
+ rating = widget.get_rating()
+
+ if len(self.entry_view.get_selected_entries()) > 0:
+ self.entry_view.love_track(rating)
+ return
+
+ if len(self.get_selected_albums()) > 0:
+ for album in self.get_selected_albums():
+ album.set_rating(rating)
+
+ print "CoverArtBrowser DEBUG - end rating_changed_callback"
+
def do_delete_thyself(self):
'''
View
@@ -175,24 +175,6 @@ def add_tracks_to_source(self, source):
print "CoverArtBrowser DEBUG - queue_track_menu_item_callback()"
- def love_track_menu_item_callback5(self, entry):
- self.love_track(5)
-
- def love_track_menu_item_callback4(self, entry):
- self.love_track(4)
-
- def love_track_menu_item_callback3(self, entry):
- self.love_track(3)
-
- def love_track_menu_item_callback2(self, entry):
- self.love_track(2)
-
- def love_track_menu_item_callback1(self, entry):
- self.love_track(1)
-
- def love_track_menu_item_callback0(self, entry):
- self.love_track(0)
-
def love_track(self, rating):
'''
utility function to set the rating for selected tracks
View
55 em.py
@@ -0,0 +1,55 @@
+import gi
+from gi.repository import Pango
+from gi.repository import Gtk
+gi.require_version("Gtk", "3.0")
+
+import logging
+
+LOG = logging.getLogger(__name__)
+
+
+def get_em(size=""):
+ # calc the height of a character, use as 1em
+ if size:
+ m = '<%s>M</%s>' % (size, size)
+ else:
+ m = 'M'
+
+ l = Gtk.Label()
+ l.set_markup(m)
+ w, h = l.get_layout().get_size()
+ return h / Pango.SCALE
+
+
+def get_small_em():
+ return get_em("small")
+
+
+def get_big_em():
+ return get_em("big")
+
+
+EM = get_em()
+SMALL_EM = get_small_em()
+BIG_EM = get_big_em()
+LOG.debug("EM's: %s %s %s" % (EM, SMALL_EM, BIG_EM))
+
+
+def em(multiplier=1, min=1):
+ return max(int(min), int(round(EM * multiplier, 0)))
+
+
+def small_em(multiplier=1, min=1):
+ return max(int(min), int(round(SMALL_EM * multiplier, 0)))
+
+
+def big_em(multiplier=1, min=1):
+ return max(int(min), int(round(BIG_EM * multiplier, 0)))
+
+
+# common values
+class StockEms:
+ XLARGE = em(1.33, 5)
+ LARGE = em(min=3)
+ MEDIUM = em(0.666, 2)
+ SMALL = em(0.333, 1)
Oops, something went wrong.

0 comments on commit b3e1c5e

Please sign in to comment.