1
# This file is part of the Frescobaldi project, http://www.frescobaldi.org/
3
# Copyright (c) 2008 - 2011 by Wilbert Berendsen
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; either version 2
8
# of the License, or (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# See http://www.gnu.org/licenses/ for more information.
21
The Preferences Dialog.
24
from __future__ import unicode_literals
27
from PyQt4.QtCore import QSettings, QSize, Qt, pyqtSignal
28
from PyQt4.QtGui import (
29
QDialog, QDialogButtonBox, QGroupBox, QHBoxLayout, QListWidget,
30
QListWidgetItem, QStackedWidget, QVBoxLayout, QWidget)
38
_prefsindex = 0 # global setting for selected prefs page but not saved on exit
41
class PreferencesDialog(QDialog):
43
def __init__(self, mainwindow):
44
super(PreferencesDialog, self).__init__(mainwindow)
45
self.setWindowModality(Qt.WindowModal)
46
self.addAction(mainwindow.actionCollection.help_whatsthis)
47
layout = QVBoxLayout()
49
self.setLayout(layout)
51
# listview to the left, stacked widget to the right
55
self.pagelist = QListWidget(self)
56
self.stack = QStackedWidget(self)
57
top.addWidget(self.pagelist, 0)
58
top.addWidget(self.stack, 2)
60
layout.addWidget(widgets.Separator(self))
62
b = self.buttons = QDialogButtonBox(self)
65
| QDialogButtonBox.Cancel
66
| QDialogButtonBox.Apply
67
| QDialogButtonBox.Reset
68
| QDialogButtonBox.Help)
70
b.accepted.connect(self.accept)
71
b.rejected.connect(self.reject)
72
b.button(QDialogButtonBox.Apply).clicked.connect(self.saveSettings)
73
b.button(QDialogButtonBox.Reset).clicked.connect(self.loadSettings)
74
b.button(QDialogButtonBox.Apply).setEnabled(False)
77
self.pagelist.setIconSize(QSize(32, 32))
78
self.pagelist.setSpacing(2)
90
self.pagelist.addItem(item())
91
self.pagelist.currentItemChanged.connect(self.slotCurrentItemChanged)
93
app.translateUI(self, 100)
94
# read our size and selected page
95
util.saveDialogSize(self, "preferences/dialog/size", QSize(500, 300))
96
self.pagelist.setCurrentRow(_prefsindex)
98
def translateUI(self):
99
self.pagelist.setFixedWidth(self.pagelist.sizeHintForColumn(0) + 12)
100
self.setWindowTitle(app.caption(_("Preferences")))
102
def done(self, result):
103
if result and self.buttons.button(QDialogButtonBox.Apply).isEnabled():
105
# save our size and selected page
107
_prefsindex = self.pagelist.currentRow()
108
super(PreferencesDialog, self).done(result)
111
"""Yields the settings pages that are already instantiated."""
112
for n in range(self.stack.count()):
113
yield self.stack.widget(n)
115
def loadSettings(self):
116
"""Loads the settings on reset."""
117
for page in self.pages():
119
page.hasChanges = False
120
self.buttons.button(QDialogButtonBox.Apply).setEnabled(False)
122
def saveSettings(self):
123
"""Saves the settings and applies them."""
124
for page in self.pages():
127
page.hasChanges = False
128
self.buttons.button(QDialogButtonBox.Apply).setEnabled(False)
131
app.settingsChanged()
133
def slotCurrentItemChanged(self, item):
137
"""Call this to enable the Apply button."""
138
self.buttons.button(QDialogButtonBox.Apply).setEnabled(True)
141
class PrefsItemBase(QListWidgetItem):
143
super(PrefsItemBase, self).__init__()
145
self.setIcon(icons.get(self.iconName))
146
app.translateUI(self)
149
dlg = self.listWidget().parentWidget()
150
if self._widget is None:
151
w = self._widget = self.widget(dlg)
152
dlg.stack.addWidget(w)
154
w.changed.connect(dlg.changed)
155
w.changed.connect(w.markChanged)
156
dlg.stack.setCurrentWidget(self._widget)
159
class General(PrefsItemBase):
160
iconName = "preferences-system"
161
def translateUI(self):
162
self.setText(_("General Preferences"))
164
def widget(self, dlg):
166
return general.GeneralPrefs(dlg)
169
class LilyPond(PrefsItemBase):
170
iconName = "lilypond-run"
171
def translateUI(self):
172
self.setText(_("LilyPond Preferences"))
174
def widget(self, dlg):
176
return lilypond.LilyPondPrefs(dlg)
179
class Midi(PrefsItemBase):
180
iconName = "audio-volume-medium"
181
def translateUI(self):
182
self.setText(_("MIDI Settings"))
184
def widget(self, dlg):
186
return midi.MidiPrefs(dlg)
189
class Helpers(PrefsItemBase):
190
iconName = "applications-other"
191
def translateUI(self):
192
self.setText(_("Helper Applications"))
194
def widget(self, dlg):
196
return helpers.Helpers(dlg)
199
class Paths(PrefsItemBase):
200
iconName = "folder-open"
201
def translateUI(self):
202
self.setText(_("Paths"))
204
def widget(self, dlg):
206
return paths.Paths(dlg)
209
class Documentation(PrefsItemBase):
210
iconName = "help-contents"
211
def translateUI(self):
212
self.setText(_("LilyPond Documentation"))
214
def widget(self, dlg):
215
from . import documentation
216
return documentation.Documentation(dlg)
219
class Shortcuts(PrefsItemBase):
220
iconName = "configure-shortcuts"
221
def translateUI(self):
222
self.setText(_("Keyboard Shortcuts"))
224
def widget(self, dlg):
225
from . import shortcuts
226
return shortcuts.Shortcuts(dlg)
229
class FontsColors(PrefsItemBase):
230
iconName = "applications-graphics"
231
def translateUI(self):
232
self.setText(_("Fonts & Colors"))
234
def widget(self, dlg):
235
from . import fontscolors
236
return fontscolors.FontsColors(dlg)
239
class Tools(PrefsItemBase):
240
iconName = "preferences-other"
241
def translateUI(self):
242
self.setText(_("Tools"))
244
def widget(self, dlg):
246
return tools.Tools(dlg)
250
"""Base class for settings pages."""
251
changed = pyqtSignal()
254
def markChanged(self):
255
"""Called when something changes in the dialog."""
256
self.hasChanges = True
258
def loadSettings(self):
259
"""Should load settings from config into our widget."""
261
def saveSettings(self):
262
"""Should write settings from our widget to config."""
265
class GroupsPage(Page):
266
"""Base class for a Page with SettingsGroups.
268
The load and save methods of the SettingsGroup groups are automatically called.
271
def __init__(self, dialog):
272
super(GroupsPage, self).__init__(dialog)
275
def loadSettings(self):
276
for group in self.groups:
279
def saveSettings(self):
280
for group in self.groups:
284
class Group(QGroupBox):
285
"""This is a QGroupBox that auto-adds itself to a Page."""
286
changed = pyqtSignal()
288
def __init__(self, page):
289
super(Group, self).__init__()
290
page.groups.append(self)
291
self.changed.connect(page.changed)
293
def loadSettings(self):
294
"""Should load settings from config into our widget."""
296
def saveSettings(self):
297
"""Should write settings from our widget to config."""