add filter buttons to artist info to allow filtering by similar artist - issue #279

Esse commit está contido em:
fossfreedom
2014-03-17 21:31:41 +00:00
commit 873571f1ab
3 arquivos alterados com 96 adições e 3 exclusões
+29
Ver Arquivo
@@ -545,7 +545,35 @@ class AlbumFilters(object):
return RB.search_fold(searchtext) in RB.search_fold(album.artists)
return filt
@classmethod
def similar_artist_filter(cls, searchtext=None):
def filt(album):
# this filter is more complicated: for each word in the search
# text, it tries to find at least one match on the params of
# the album. If no match is given, then the album doesn't match
if not searchtext:
return True
words = RB.search_fold(searchtext).split()
params = list(map(RB.search_fold, [album.artist,
album.artists]))
matches = []
for word in words:
match = False
for param in params:
if word in param:
match = True
break
matches.append(match)
return False not in matches
return filt
@classmethod
def album_name_filter(cls, searchtext=None):
def filt(album):
@@ -628,6 +656,7 @@ AlbumFilters.keys = {
'album_artist': AlbumFilters.album_artist_filter,
'artist': AlbumFilters.artist_filter,
'quick_artist': AlbumFilters.artist_filter,
'similar_artist': AlbumFilters.similar_artist_filter,
'album_name': AlbumFilters.album_name_filter,
'track': AlbumFilters.track_title_filter,
'genre': AlbumFilters.genre_filter,
+14
Ver Arquivo
@@ -91,6 +91,7 @@ class ArtistInfoPane(GObject.GObject):
self.webview = WebKit.WebView()
self.webview.connect("navigation-requested", self.navigation_request_cb)
self.webview.connect("notify::title", self.view_title_change)
self.info_scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
self.info_scrolled_window.add (self.webview)
self.info_scrolled_window.show_all()
@@ -155,6 +156,19 @@ class ArtistInfoPane(GObject.GObject):
# lets also listen for changes to the view to set the paned position
self.source.viewmgr.connect('new-view', self.on_view_changed)
def view_title_change(self, webview, param):
title = webview.get_title()
if title:
args = json.loads(title)
artist = args['artist']
if args['toggle']:
self.source.album_manager.model.replace_filter('similar_artist', artist)
else:
self.source.album_manager.model.remove_filter('similar_artist')
else:
self.source.album_manager.model.remove_filter('similar_artist')
def on_view_changed(self, widget, view_name):
self._change_paned_pos(view_name)
+53 -3
Ver Arquivo
@@ -15,13 +15,48 @@
<head>
<meta http-equiv="content-type" content="text-html; charset=utf-8">
<link rel="stylesheet" href="${stylesheet}" type="text/css" />
<script language="javascript">
function swapText (element, text1, text2) {
elt = document.getElementById(element);
var retval = (elt.innerHTML == text1)
elt.innerHTML = (elt.innerHTML == text1) ? text2 : text1;
return (retval==false)
}
function toggle_filter(id, filterval) {
// first toggle the chosen button label
hide = ${ '"' + _("Unfilter") + '"' };
show = ${ '"' + _("Filter") + '"' };
var toggle = swapText('btn_'+id, hide, show);
// next ensure all buttons except for the chosen button is correctly labelled
var menus = document.getElementsByTagName("button");
var x = parseInt(id, 10);
for (var i = menus.length - 1; i >= 0; i--)
{
if (i != x) {
elt = document.getElementById('btn_'+i);
elt.innerHTML = show;
}
}
// lastly send back the value of the button i.e. the artist name
var obj = { }
obj['artist'] = filterval;
obj['toggle'] = toggle;
document.title = JSON.stringify(obj);
};
</script>
<style type="text/css">
.shown p,
.similar td,
.links a
{ font-size: 10pt;
{
font-size: 10pt;
font-family: sans-serif;
vertical-align: middle;
}
.links img
@@ -59,12 +94,27 @@
</div>
<div class="similar">
<h1>Similar Artists</h1>
<h1>${ _("Similar Artists") }</h1>
<table id="similar">
%for i, entry in enumerate(similar) :
<tr><td><img width="64" src="${entry['image_url'] | h}" alt="${entry['image_url'] | h}"/></td><td>${entry['name']} ${entry['similarity']}% similar</td></tr>
<% artist = entry['name'] %>
<tr>
<td rowspan="2">
<img style="float: right;" width="64" src="${entry['image_url'] | h}" alt="${entry['image_url'] | h}"/>
</td>
<td>
${entry['name']} ${entry['similarity']}% ${ _("similar") }
</td>
</tr>
<tr>
<td>
<button id="btn_${i | h}" onclick="toggle_filter('${i | h}', '${artist | h}')">
${ _("Filter") }
</button>
</td>
</tr>
%endfor
</table>
</div>