[pitivi] prefs: Use ids to identify sections
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] prefs: Use ids to identify sections
- Date: Thu, 30 Jun 2016 13:50:13 +0000 (UTC)
commit eef0d444ca2bcd83516a0b89f17c86cb86e437a3
Author: Jakub Brindza <jakub brindza gmail com>
Date: Wed Jun 29 16:10:21 2016 +0100
prefs: Use ids to identify sections
Differential Revision: https://phabricator.freedesktop.org/D1145
pitivi/dialogs/prefs.py | 11 ++++++-----
pitivi/timeline/timeline.py | 6 +++---
tests/test_prefs.py | 23 +++++++++++++----------
3 files changed, 22 insertions(+), 18 deletions(-)
---
diff --git a/pitivi/dialogs/prefs.py b/pitivi/dialogs/prefs.py
index 8a1f6d6..c2109bc 100644
--- a/pitivi/dialogs/prefs.py
+++ b/pitivi/dialogs/prefs.py
@@ -47,6 +47,7 @@ class PreferencesDialog(Loggable):
prefs = {}
original_values = {}
+ section_names = {"behavior": _("Behavior")}
def __init__(self, app):
Loggable.__init__(self)
@@ -86,13 +87,13 @@ class PreferencesDialog(Loggable):
label (str): The user-visible name for this option.
description (str): The user-visible description explaining this
option. Ignored unless `label` is non-None.
- section (str): The user-visible category to which this option
- belongs. Ignored unless `label` is non-None.
+ section (str): The id of a preferences category.
+ See `PreferencesDialog.section_names` for valid ids.
widget_class (type): The class of the widget for displaying the
option.
"""
- if not section:
- section = "General"
+ if section not in cls.section_names:
+ raise Exception("%s is not a valid section id" % section)
if section not in cls.prefs:
cls.prefs[section] = {}
cls.prefs[section][attrname] = (label, description, widget_class, args)
@@ -203,7 +204,7 @@ class PreferencesDialog(Loggable):
widget.show()
revert.show()
grid.show()
- self.stack.add_titled(grid, section_id, section_id)
+ self.stack.add_titled(grid, section_id, self.section_names[section_id])
self.factory_settings.set_sensitive(self._canReset())
def _clearHistory(self):
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 65d8f18..d365abe 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -71,7 +71,7 @@ GlobalSettings.addConfigOption('edgeSnapDeadband',
notify=True)
PreferencesDialog.addNumericPreference('edgeSnapDeadband',
- section=_("Behavior"),
+ section="behavior",
label=_("Snap distance"),
description=_("Threshold (in pixels) at which two clips will snap
together "
"when dragging or trimming."),
@@ -84,7 +84,7 @@ GlobalSettings.addConfigOption('imageClipLength',
notify=True)
PreferencesDialog.addNumericPreference('imageClipLength',
- section=_("Behavior"),
+ section="behavior",
label=_("Image clip duration"),
description=_(
"Default clip length (in milliseconds) of images when inserting
on the timeline."),
@@ -97,7 +97,7 @@ GlobalSettings.addConfigOption('leftClickAlsoSeeks',
notify=True)
PreferencesDialog.addTogglePreference('leftClickAlsoSeeks',
- section=_("Behavior"),
+ section="behavior",
label=_("Left click also seeks"),
description=_(
"Whether left-clicking also seeks besides selecting and editing
clips."))
diff --git a/tests/test_prefs.py b/tests/test_prefs.py
index 8cb036d..8cc5430 100644
--- a/tests/test_prefs.py
+++ b/tests/test_prefs.py
@@ -24,42 +24,45 @@ from pitivi.dialogs.prefs import PreferencesDialog
class PreferencesDialogTest(unittest.TestCase):
def testNumeric(self):
+ section = list(PreferencesDialog.section_names.keys())[0]
PreferencesDialog.addNumericPreference('numericPreference1',
label="Open Range",
- section="Test",
+ section=section,
description="This option has no upper bound",
lower=-10)
self.assertTrue(
- 'numericPreference1' in PreferencesDialog.prefs['Test'])
+ 'numericPreference1' in PreferencesDialog.prefs[section])
PreferencesDialog.addNumericPreference('numericPreference2',
label="Closed Range",
- section="Test",
+ section=section,
description="This option has both upper and lower bounds",
lower=-10,
upper=10000)
def testText(self):
+ section = list(PreferencesDialog.section_names.keys())[0]
PreferencesDialog.addTextPreference('textPreference1',
label="Unfiltered",
- section="Test",
+ section=section,
description="Anything can go in this box")
PreferencesDialog.addTextPreference('textPreference2',
label="Numbers only",
- section="Test",
+ section=section,
description="This input validates its input with a regex",
matches=r"^-?\d+(\.\d+)?$")
def testOther(self):
+ section = list(PreferencesDialog.section_names.keys())[0]
PreferencesDialog.addPathPreference('aPathPreference',
label="Test Path",
- section="Test",
+ section=section,
description="Test the path widget")
PreferencesDialog.addChoicePreference('aChoicePreference',
label="Swallow Velocity",
- section="Test",
+ section=section,
description="What is the airspeed velocity of a coconut-laden
swallow?",
choices=(
("42 Knots", 32),
@@ -68,7 +71,7 @@ class PreferencesDialogTest(unittest.TestCase):
PreferencesDialog.addChoicePreference('aLongChoicePreference',
label="Favorite Color",
- section="Test",
+ section=section,
description="What is the color of the parrot's plumage?",
choices=(
("Mauve", "Mauve"),
@@ -80,10 +83,10 @@ class PreferencesDialogTest(unittest.TestCase):
PreferencesDialog.addTogglePreference('aTogglePreference',
label="Test Toggle",
- section="Test",
+ section=section,
description="Test the toggle widget")
PreferencesDialog.addFontPreference('aFontPreference',
label="Foo Font",
- section="Test",
+ section=section,
description="Test the font widget")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]