/
tracks.py
151 lines (114 loc) · 4.61 KB
/
tracks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Copyright 2004-2022 Joe Wreschnig, Michael Urman, Iñigo Serna,
# Christoph Reiter, Steven Robertson, Nick Boultbee,
# 2018-2019 Peter Strulo
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
from gi.repository import Gtk, GLib
from quodlibet import config
from quodlibet import qltk
from quodlibet import _
from quodlibet.browsers import Browser
from quodlibet.qltk.ccb import ConfigCheckMenuItem
from quodlibet.qltk.completion import LibraryTagCompletion
from quodlibet.qltk.menubutton import MenuButton
from quodlibet.qltk.searchbar import MultiSearchBarBox
from quodlibet.qltk.songlist import SongList
from quodlibet.qltk.x import SymbolicIconImage, Align
from quodlibet.qltk import Icons
class PreferencesButton(Gtk.HBox):
def __init__(self, search_bar_box):
super().__init__()
menu = Gtk.Menu()
limit_item = ConfigCheckMenuItem(
_("_Limit Results"), "browsers", "search_limit", True)
limit_item.connect("toggled", search_bar_box.toggle_limit_widgets)
menu.append(limit_item)
multi_item = ConfigCheckMenuItem(
_("_Allow multiple queries"), "browsers", "multiple_queries", True)
multi_item.connect("toggled", search_bar_box.toggle_multi)
menu.append(multi_item)
menu.show_all()
button = MenuButton(
SymbolicIconImage(Icons.EMBLEM_SYSTEM, Gtk.IconSize.MENU),
arrow=True)
button.set_menu(menu)
self.pack_start(button, True, True, 0)
class TrackList(Browser):
name = _("Track List")
accelerated_name = _("_Track List")
keys = ["SearchBar", "TrackList"]
priority = 1
def pack(self, songpane):
container = Gtk.VBox(spacing=6)
container.pack_start(self, False, True, 0)
container.pack_start(songpane, True, True, 0)
return container
def unpack(self, container, songpane):
container.remove(songpane)
container.remove(self)
def __init__(self, library):
super().__init__(spacing=6, orientation=Gtk.Orientation.VERTICAL)
self._query = None
self._library = library
completion = LibraryTagCompletion(library.librarian)
self.accelerators = Gtk.AccelGroup()
show_limit = config.getboolean("browsers", "search_limit")
show_multi = config.getboolean("browsers", "multiple_queries")
sbb = MultiSearchBarBox(completion=completion,
accel_group=self.accelerators,
show_limit=show_limit,
show_multi=show_multi)
sbb.connect('query-changed', self.__text_parse)
sbb.connect('focus-out', self.__focus)
self._sb_box = sbb
prefs = PreferencesButton(sbb)
sbb.pack_start(prefs, False, True, 0)
self.pack_start(Align(sbb, left=6, right=6), False, True, 0)
self.pack_start(sbb.flow_box, False, True, 0)
self.connect('destroy', self.__destroy)
self.show_all()
def _get_text(self):
return self._sb_box.get_text()
def _set_text(self, text):
self._sb_box.set_text(text)
def __destroy(self, *args):
self._sb_box = None
def __focus(self, widget, *args):
qltk.get_top_parent(widget).songlist.grab_focus()
def _get_songs(self):
self._query = self._sb_box.get_query(SongList.star)
return self._query.filter(self._library) if self._query else None
def activate(self):
songs = self._get_songs()
if songs is not None:
songs = self._sb_box.limit(songs)
GLib.idle_add(self.songs_selected, songs)
def __text_parse(self, bar, text):
self.activate()
def save(self):
config.settext("browsers", "query_text", self._get_text())
self._sb_box.save()
def restore(self):
text = config.gettext("browsers", "query_text")
self._set_text(text)
self._sb_box.load()
def finalize(self, restore):
config.set("browsers", "query_text", "")
def can_filter_text(self):
return True
def filter_text(self, text):
self._set_text(text)
self.activate()
def get_filter_text(self):
return self._get_text()
def unfilter(self):
self.filter_text("")
def active_filter(self, song):
if self._query is not None:
return self._query.search(song)
else:
return True
browsers = [TrackList]