~timo-jyrinki/ubuntu/trusty/pitivi/backport_utopic_fixes

« back to all changes in this revision

Viewing changes to pitivi/dialogs/prefs.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2014-03-29 15:22:50 UTC
  • mto: (3.1.23 experimental)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20140329152250-flg9onx416bqf3e3
Tags: upstream-0.93
Import upstream version 0.93

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Pitivi video editor
2
2
#
3
 
#       ui/prefs.py
 
3
#       pitivi/dialogs/prefs.py
4
4
#
5
5
# Copyright (c) 2005, Edward Hervey <bilboed@bilboed.com>
6
6
#
46
46
    default=400)
47
47
 
48
48
 
49
 
class PreferencesDialog():
50
 
 
 
49
class PreferencesDialog(object):
 
50
    """
 
51
    This dialog displays preferences for pitivi.
 
52
    """
51
53
    prefs = {}
52
54
    original_values = {}
53
55
 
56
58
        self.widgets = {}
57
59
        self.resets = {}
58
60
        self._current = None
59
 
        self._createUi()
60
 
        self._fillContents()
61
 
        req = self.contents.size_request()
62
 
        min_width = req.width
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)
68
 
 
69
 
    def run(self):
70
 
        self.dialog.run()
71
 
 
72
 
    def _createUi(self):
 
61
 
 
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)
76
 
 
77
 
        # widgets we'll need
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")
85
73
 
 
74
        self.sections = {}
 
75
        self.__fillContents()
 
76
        req = self.contents.size_request()
 
77
        min_width = req.width
 
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)
 
83
 
 
84
    def run(self):
 
85
        """Run the internal dialog"""
 
86
        self.dialog.run()
 
87
 
86
88
## Public API
87
89
 
88
90
    @classmethod
89
91
    def addPreference(cls, attrname, label, description, section=None,
90
 
                    widget_klass=None, **args):
 
92
                    widget_class=None, **args):
91
93
        """
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
95
97
 
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)
100
 
        @type desc: C{str}
 
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}
106
108
        """
107
109
        if not section:
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)
112
114
 
113
115
    @classmethod
114
116
    def addPathPreference(cls, attrname, label, description, section=None):
118
120
 
119
121
        @param label: user-visible name for this option
120
122
        @type label: C{str}
121
 
        @param desc: a user-visible description documenting this option
 
123
        @param description: a user-visible description documenting this option
122
124
        (ignored unless prefs_label is non-null)
123
 
        @type desc: C{str}
 
125
        @type description: C{str}
124
126
        @param section: user-visible category to which this option
125
127
        belongs (ignored unless prefs_label is non-null)
126
128
        @type section: C{str}
138
140
 
139
141
        @param label: user-visible name for this option
140
142
        @type label: C{str}
141
 
        @param desc: a user-visible description documenting this option
 
143
        @param description: a user-visible description documenting this option
142
144
        (ignored unless prefs_label is non-null)
143
 
        @type desc: C{str}
 
145
        @type description: C{str}
144
146
        @param section: user-visible category to which this option
145
147
        belongs (ignored unless prefs_label is non-null)
146
148
        @type section: C{str}
161
163
 
162
164
        @param label: user-visible name for this option
163
165
        @type label: C{str}
164
 
        @param desc: a user-visible description documenting this option
 
166
        @param description: a user-visible description documenting this option
165
167
        (ignored unless prefs_label is non-null)
166
 
        @type desc: C{str}
 
168
        @type description: C{str}
167
169
        @param section: user-visible category to which this option
168
170
        belongs (ignored unless prefs_label is non-null)
169
171
        @type section: C{str}
180
182
 
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)
185
 
        @type desc: C{str}
 
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
200
202
 
201
203
        @param label: user-visible name for this option
202
204
        @type label: C{str}
203
 
        @param desc: a user-visible description documenting this option
 
205
        @param description: a user-visible description documenting this option
204
206
        (ignored unless prefs_label is non-null)
205
 
        @type desc: C{str}
 
207
        @type description: C{str}
206
208
        @param section: user-visible category to which this option
207
209
        belongs (ignored unless prefs_label is non-null)
208
210
        @type section: C{str}
220
222
 
221
223
        @param label: user-visible name for this option
222
224
        @type label: C{str}
223
 
        @param desc: a user-visible description documenting this option
 
225
        @param description: a user-visible description documenting this option
224
226
        (ignored unless prefs_label is non-null)
225
 
        @type desc: C{str}
 
227
        @type description: C{str}
226
228
        @param section: user-visible category to which this option
227
229
        belongs (ignored unless prefs_label is non-null)
228
230
        @type section: C{str}
238
240
 
239
241
        @param label: user-visible name for this option
240
242
        @type label: C{str}
241
 
        @param desc: a user-visible description documenting this option
 
243
        @param description: a user-visible description documenting this option
242
244
        (ignored unless prefs_label is non-null)
243
 
        @type desc: C{str}
 
245
        @type description: C{str}
244
246
        @param section: user-visible category to which this option
245
247
        belongs (ignored unless prefs_label is non-null)
246
248
        @type section: C{str}
249
251
            ptvWidgets.FontWidget)
250
252
 
251
253
## Implementation
252
 
    def _fillContents(self):
253
 
        self.sections = {}
 
254
    def __fillContents(self):
254
255
        for section in sorted(self.prefs):
255
256
            options = self.prefs[section]
256
257
            self.model.append((_(section), section))
262
263
 
263
264
            prefs = {}
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
312
313
        self.factory_settings.set_sensitive(self._canReset())
313
314
 
314
315
    def _treeSelectionChangedCb(self, selection):
315
 
        model, iter = selection.get_selected()
316
 
        new = self.sections[model[iter][1]]
 
316
        """ Update current when selection changed"""
 
317
        model, _iter = selection.get_selected()
 
318
        new = self.sections[model[_iter][1]]
317
319
        if self._current != new:
318
320
            if self._current:
319
321
                self._current.hide()
321
323
            self._current = new
322
324
 
323
325
    def _clearHistory(self):
 
326
        # Disable missing docstring
 
327
        #pylint: disable=C0111
324
328
        self.original_values = {}
325
329
        self.revert_button.set_sensitive(False)
326
330
 
354
358
        self.factory_settings.set_sensitive(self._canReset())
355
359
 
356
360
    def _acceptButtonCb(self, unused_button):
 
361
        # Disable missing docstring
 
362
        #pylint: disable=C0111
357
363
        self._clearHistory()
358
364
        self.dialog.hide()
359
365
 
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)
376
384
 
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
380
390
 
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):
385
397
                    return True
386
398
        return False
387
 
 
388
 
## Preference Test Cases
389
 
 
390
 
if False:
391
 
 
392
 
    from pitivi.settings import GlobalSettings
393
 
 
394
 
    options = (
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"),
404
 
    )
405
 
 
406
 
    for attrname, default in options:
407
 
        GlobalSettings.addConfigOption(attrname, default=default)
408
 
 
409
 
## Numeric
410
 
 
411
 
    PreferencesDialog.addNumericPreference('numericPreference1',
412
 
        label="Open Range",
413
 
        section="Test",
414
 
        description="This option has no upper bound",
415
 
        lower=-10)
416
 
 
417
 
    PreferencesDialog.addNumericPreference('numericPreference2',
418
 
        label="Closed Range",
419
 
        section="Test",
420
 
        description="This option has both upper and lower bounds",
421
 
        lower=-10,
422
 
        upper=10000)
423
 
 
424
 
## Text
425
 
 
426
 
    PreferencesDialog.addTextPreference('textPreference1',
427
 
        label="Unfiltered",
428
 
        section="Test",
429
 
        description="Anything can go in this box")
430
 
 
431
 
    PreferencesDialog.addTextPreference('textPreference2',
432
 
        label="Numbers only",
433
 
        section="Test",
434
 
        description="This input validates its input with a regex",
435
 
        matches="^-?\d+(\.\d+)?$")
436
 
 
437
 
## other
438
 
    PreferencesDialog.addPathPreference('aPathPreference',
439
 
        label="Test Path",
440
 
        section="Test",
441
 
        description="Test the path widget")
442
 
 
443
 
    PreferencesDialog.addChoicePreference('aChoicePreference',
444
 
        label="Swallow Velocity",
445
 
        section="Test",
446
 
        description="What is the airspeed velocity of a coconut-laden swallow?",
447
 
        choices=(
448
 
            ("42 Knots", 32),
449
 
            ("9 furlongs per fortnight", 42),
450
 
            ("I don't know that!", None)))
451
 
 
452
 
    PreferencesDialog.addChoicePreference('aLongChoicePreference',
453
 
        label="Favorite Color",
454
 
        section="Test",
455
 
        description="What is the color of the parrot's plumage?",
456
 
        choices=(
457
 
            ("Mauve", "Mauve"),
458
 
            ("Chartreuse", "Chartreuse"),
459
 
            ("Magenta", "Magenta"),
460
 
            ("Pink", "Pink"),
461
 
            ("Norwegian Blue", "Norwegian Blue"),
462
 
            ("Yellow Ochre", "Yellow Ochre")))
463
 
 
464
 
    PreferencesDialog.addTogglePreference('aTogglePreference',
465
 
        label="Test Toggle",
466
 
        section="Test",
467
 
        description="Test the toggle widget")
468
 
 
469
 
    PreferencesDialog.addFontPreference('aFontPreference',
470
 
        label="Foo Font",
471
 
        section="Test",
472
 
        description="Test the font widget")