58
60
self._current = None
61
req = self.contents.size_request()
63
min_height = req.height
64
width = max(min_width, self.settings.prefsDialogWidth)
65
height = max(min_height, self.settings.prefsDialogHeight)
66
self.dialog.set_transient_for(instance.gui)
67
self.dialog.set_default_size(width, height)
62
# Identify the widgets we'll need
73
63
builder = Gtk.Builder()
74
64
builder.add_from_file(os.path.join(get_ui_dir(), "preferences.ui"))
75
65
builder.connect_signals(self)
78
66
self.dialog = builder.get_object("dialog1")
79
67
self.model = builder.get_object("liststore1")
80
68
self.treeview = builder.get_object("treeview1")
83
71
self.factory_settings = builder.get_object("resetButton")
84
72
self.restart_warning = builder.get_object("restartWarning")
76
req = self.contents.size_request()
78
min_height = req.height
79
width = max(min_width, self.settings.prefsDialogWidth)
80
height = max(min_height, self.settings.prefsDialogHeight)
81
self.dialog.set_transient_for(instance.gui)
82
self.dialog.set_default_size(width, height)
85
"""Run the internal dialog"""
89
91
def addPreference(cls, attrname, label, description, section=None,
90
widget_klass=None, **args):
92
widget_class=None, **args):
92
94
Add a user preference. The preferences dialog will try
93
95
to guess the appropriate widget to use based on the type of the
96
98
@param label: user-visible name for this option
97
99
@type label: C{str}
98
@param desc: a user-visible description documenting this option
100
@param description: a user-visible description documenting this option
99
101
(ignored unless prefs_label is non-null)
102
@type description: C{str}
101
103
@param : user-visible category to which this option
102
104
belongs (ignored unless prefs_label is non-null)
103
105
@type section: C{str}
104
@param widget_klass: overrides auto-detected widget
105
@type widget_klass: C{class}
106
@param widget_class: overrides auto-detected widget
107
@type widget_class: C{class}
108
110
section = "General"
109
111
if not section in cls.prefs:
110
112
cls.prefs[section] = {}
111
cls.prefs[section][attrname] = (label, description, widget_klass, args)
113
cls.prefs[section][attrname] = (label, description, widget_class, args)
114
116
def addPathPreference(cls, attrname, label, description, section=None):
181
183
@param label: user-visible name for this option
182
184
@type label: C{str}
183
@param desc: a user-visible description documenting this option
185
@param description: a user-visible description documenting this option
184
186
(ignored unless prefs_label is non-null)
187
@type description: C{str}
186
188
@param choices: a sequence of (<label>, <value>) pairs
187
189
@type choices: C{[(str, pyobject), ...]}
188
190
@param section: user-visible category to which this option
264
265
for attrname in options:
265
label, description, klass, args = options[attrname]
266
widget = klass(**args)
266
label, description, widget_class, args = options[attrname]
267
widget = widget_class(**args)
267
268
widget.setWidgetValue(getattr(self.settings, attrname))
268
269
widget.connectValueChanged(self._valueChanged, widget, attrname)
269
270
self.widgets[attrname] = widget
354
358
self.factory_settings.set_sensitive(self._canReset())
356
360
def _acceptButtonCb(self, unused_button):
361
# Disable missing docstring
362
#pylint: disable=C0111
357
363
self._clearHistory()
358
364
self.dialog.hide()
360
def _valueChanged(self, fake_widget, real_widget, attrname):
366
def _valueChanged(self, unused_fake_widget, real_widget, attrname):
367
# Disable missing docstring
368
#pylint: disable=C0111
361
369
value = getattr(self.settings, attrname)
362
370
if attrname not in self.original_values:
363
371
self.original_values[attrname] = value
375
383
self.factory_settings.set_sensitive(True)
377
385
def _configureCb(self, unused_widget, event):
386
# Disable missing docstring
387
#pylint: disable=C0111
378
388
self.settings.prefsDialogWidth = event.width
379
389
self.settings.prefsDialogHeight = event.height
381
391
def _canReset(self):
392
# Disable missing docstring
393
#pylint: disable=C0111
382
394
for section in self.prefs.itervalues():
383
395
for attrname in section:
384
396
if not self.settings.isDefault(attrname):
388
## Preference Test Cases
392
from pitivi.settings import GlobalSettings
395
('numericPreference1', 10),
396
('numericPreference2', 2.4),
397
('textPreference1', "banana"),
398
('textPreference2', "42"),
399
('aPathPreference', "file:///etc/"),
400
('aChoicePreference', 42),
401
('aLongChoicePreference', "Mauve"),
402
('aTogglePreference', True),
403
('aFontPreference', "Sans 9"),
406
for attrname, default in options:
407
GlobalSettings.addConfigOption(attrname, default=default)
411
PreferencesDialog.addNumericPreference('numericPreference1',
414
description="This option has no upper bound",
417
PreferencesDialog.addNumericPreference('numericPreference2',
418
label="Closed Range",
420
description="This option has both upper and lower bounds",
426
PreferencesDialog.addTextPreference('textPreference1',
429
description="Anything can go in this box")
431
PreferencesDialog.addTextPreference('textPreference2',
432
label="Numbers only",
434
description="This input validates its input with a regex",
435
matches="^-?\d+(\.\d+)?$")
438
PreferencesDialog.addPathPreference('aPathPreference',
441
description="Test the path widget")
443
PreferencesDialog.addChoicePreference('aChoicePreference',
444
label="Swallow Velocity",
446
description="What is the airspeed velocity of a coconut-laden swallow?",
449
("9 furlongs per fortnight", 42),
450
("I don't know that!", None)))
452
PreferencesDialog.addChoicePreference('aLongChoicePreference',
453
label="Favorite Color",
455
description="What is the color of the parrot's plumage?",
458
("Chartreuse", "Chartreuse"),
459
("Magenta", "Magenta"),
461
("Norwegian Blue", "Norwegian Blue"),
462
("Yellow Ochre", "Yellow Ochre")))
464
PreferencesDialog.addTogglePreference('aTogglePreference',
467
description="Test the toggle widget")
469
PreferencesDialog.addFontPreference('aFontPreference',
472
description="Test the font widget")