adopt new playlist style in search window

This commit is contained in:
Martin Wagner 2022-02-01 19:14:59 +01:00
parent d602fd7c04
commit f2e332f1cc

View File

@ -1675,7 +1675,7 @@ class SearchThread(threading.Thread):
if self._stop_flag: if self._stop_flag:
return [] return []
else: else:
self._client.restrict_tagtypes("track", "title", "artist", "album") self._client.restrict_tagtypes("track", "title", "artist", "album", "date")
songs=self._client.search(self._search_tag, self._search_text, "window", f"{start}:{end}") songs=self._client.search(self._search_tag, self._search_text, "window", f"{start}:{end}")
self._client.tagtypes("all") self._client.tagtypes("all")
return songs return songs
@ -1685,15 +1685,17 @@ class SearchThread(threading.Thread):
for song in songs: for song in songs:
if self._stop_flag: if self._stop_flag:
return False return False
try: if "date" in song:
int_track=int(song["track"][0]) date=f"({song['date']})"
except ValueError: else:
int_track=0 date=""
self._store.insert_with_valuesv(-1, range(7), [ album_with_date=" ".join(filter(None, ((song["album"][0], date))))
song["track"][0], song["title"][0], title=(f"<b>{GLib.markup_escape_text(song['title'][0])}</b>"
str(song["artist"]), song["album"][0], f"{GLib.markup_escape_text(str(song['artist']))}\n"
str(song["duration"]), song["file"], f"<small>{GLib.markup_escape_text(album_with_date)}</small>")
int_track self._store.insert_with_valuesv(-1, range(4), [
song["track"][0], title,
str(song["duration"]), song["file"]
]) ])
return True return True
@ -1710,10 +1712,9 @@ class SearchWindow(Gtk.Box):
close_button=Gtk.Button(image=Gtk.Image.new_from_icon_name("window-close-symbolic", Gtk.IconSize.BUTTON), relief=Gtk.ReliefStyle.NONE) close_button=Gtk.Button(image=Gtk.Image.new_from_icon_name("window-close-symbolic", Gtk.IconSize.BUTTON), relief=Gtk.ReliefStyle.NONE)
# songs window # songs window
# (track, title, artist, album, duration, file, sort track) # (track, title, duration, file)
self._store=Gtk.ListStore(str, str, str, str, str, str, int) self._store=Gtk.ListStore(str, str, str, str)
self._store.set_default_sort_func(lambda *args: 0) self._songs_window=SongsWindow(self._client, self._store, 3)
self._songs_window=SongsWindow(self._client, self._store, 5)
self._action_bar=self._songs_window.get_action_bar() self._action_bar=self._songs_window.get_action_bar()
self._songs_view=self._songs_window.get_treeview() self._songs_view=self._songs_window.get_treeview()
@ -1722,21 +1723,17 @@ class SearchWindow(Gtk.Box):
attrs=Pango.AttrList() attrs=Pango.AttrList()
attrs.insert(Pango.AttrFontFeatures.new("tnum 1")) attrs.insert(Pango.AttrFontFeatures.new("tnum 1"))
renderer_text_tnum=Gtk.CellRendererText(attributes=attrs) renderer_text_tnum=Gtk.CellRendererText(attributes=attrs)
renderer_text_ralign_tnum=Gtk.CellRendererText(xalign=1.0, attributes=attrs) renderer_text_centered_tnum=Gtk.CellRendererText(xalign=0.5, attributes=attrs)
column_data=( columns=(
(_("No"), renderer_text_ralign_tnum, False, 0, 6), Gtk.TreeViewColumn(_("No"), renderer_text_centered_tnum, text=0),
(_("Title"), renderer_text, True, 1, 1), Gtk.TreeViewColumn(_("Title"), renderer_text, markup=1),
(_("Artist"), renderer_text, True, 2, 2), Gtk.TreeViewColumn(_("Length"), renderer_text_tnum, text=2)
(_("Album"), renderer_text, True, 3, 3),
(_("Length"), renderer_text_tnum, False, 4, 4),
) )
for title, renderer, expand, text, sort in column_data: for column in columns:
column=Gtk.TreeViewColumn(title, renderer, text=text)
column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
column.set_property("resizable", False) column.set_property("resizable", False)
column.set_property("expand", expand)
column.set_sort_column_id(sort)
self._songs_view.append_column(column) self._songs_view.append_column(column)
columns[1].set_property("expand", True)
# search thread # search thread
self._search_thread=SearchThread(self._client, self.search_entry, self._songs_window, self._hits_label, "any") self._search_thread=SearchThread(self._client, self.search_entry, self._songs_window, self._hits_label, "any")