/
advanced_preferences.py
154 lines (115 loc) · 4.69 KB
/
advanced_preferences.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
152
153
154
# -*- coding: utf-8 -*-
# Copyright 2015 Christoph Reiter
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation
from gi.repository import Gtk
from quodlibet import config
from quodlibet.qltk.entry import UndoEntry
from quodlibet.qltk import Icons
from quodlibet.util.string import decode
from quodlibet.plugins.events import EventPlugin
def _config(section, option, label, tooltip, getter):
def on_changed(entry, *args):
config.set(section, option, entry.get_text())
entry = UndoEntry()
entry.set_tooltip_text(tooltip)
entry.set_text(decode(config.get(section, option)))
entry.connect("changed", on_changed)
def on_reverted(*args):
config.reset(section, option)
entry.set_text(decode(config.get(section, option)))
revert = Gtk.Button()
revert.add(Gtk.Image.new_from_icon_name(
Icons.DOCUMENT_REVERT, Gtk.IconSize.BUTTON))
revert.connect("clicked", on_reverted)
return (Gtk.Label(label=label), entry, revert)
def text_config(section, option, label, tooltip):
def getter(section, option):
return decode(config.get(section, option))
return _config(section, option, label, tooltip, getter)
def boolean_config(section, option, label, tooltip):
def getter(section, option):
return unicode(config.getboolean(section, option))
return _config(section, option, label, tooltip, getter)
def int_config(section, option, label, tooltip):
def getter(section, option):
return unicode(config.getint(section, option))
return _config(section, option, label, tooltip, getter)
class AdvancedPreferences(EventPlugin):
PLUGIN_ID = "Advanced Preferences"
PLUGIN_NAME = _("Advanced Preferences")
PLUGIN_DESC = _("Allow to tweak advanced config settings.")
PLUGIN_CAN_ENABLE = False
def __init_defaults(self):
self.__enabled = False
def PluginPreferences(self, *args):
def changed(entry, name, section="settings"):
config.set(section, name, entry.get_text())
vb = Gtk.VBox(spacing=12)
# Tabulate all settings for neatness
table = Gtk.Table(n_rows=6, n_columns=2)
table.set_col_spacings(6)
table.set_row_spacings(6)
rows = []
# We don't use translations as these things are internal and I don't
# want to burden the translators...
rows.append(
text_config(
"editing", "id3encoding",
"ID3 Encodings:",
("ID3 encodings separated by spaces. "
"UTF-8 is always tried first, and Latin-1 "
"is always tried last.")))
rows.append(
text_config(
"settings", "search_tags",
"Search Tags:",
("Tags which get searched in addition to "
"the ones present in the song list, separate with \",\"")))
rows.append(
text_config(
"settings", "rating_symbol_full",
"Rating Symbol (Full):",
""))
rows.append(
text_config(
"settings", "rating_symbol_blank",
"Rating Symbol (Blank):",
""))
rows.append(
text_config(
"player", "backend",
"Backend:",
"Identifier of the playback backend to use"))
rows.append(
boolean_config(
"settings", "disable_hints",
"Disable Hints:",
"Disable popup windows (treeview hints)"))
rows.append(
boolean_config(
"browsers", "rating_hotkeys",
"Rating Hotkeys:",
"Enable rating by pressing the 0-X keys"))
rows.append(
int_config(
"browsers", "cover_size",
"Album Cover Size:",
("Size of the album cover images in the album list browser "
"(restart required)")))
rows.append(
boolean_config(
"settings", "osx_mmkeys",
"OS X Multimedia Keys:",
"Enable experimental mmkeys support (restart required)"))
for (row, (label, entry, button)) in enumerate(rows):
label.set_alignment(1.0, 0.5)
table.attach(label, 0, 1, row, row + 1,
xoptions=Gtk.AttachOptions.FILL)
table.attach(entry, 1, 2, row, row + 1)
table.attach(button, 2, 3, row, row + 1,
xoptions=Gtk.AttachOptions.SHRINK)
vb.pack_start(table, True, True, 0)
return vb