[pitivi] preset: Enable saving the preset when no preset selected and a name has been entered
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] preset: Enable saving the preset when no preset selected and a name has been entered
- Date: Wed, 25 Nov 2015 09:55:58 +0000 (UTC)
commit 0e893d66c6a8c7d9cc4a61e0c71447bb0dbaeb13
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Sun Oct 11 00:18:53 2015 +0200
preset: Enable saving the preset when no preset selected and a name has been entered
Differential Revision: https://phabricator.freedesktop.org/D368
Reviewed-by: Thibault Saunier <tsaunier gnome org>
pitivi/preset.py | 41 +++++++++++++++++++++++++++--------------
pitivi/project.py | 8 ++++++--
pitivi/render.py | 7 ++++---
tests/test_preset.py | 10 ++++++----
4 files changed, 43 insertions(+), 23 deletions(-)
---
diff --git a/pitivi/preset.py b/pitivi/preset.py
index c3f9c52..f09d453 100644
--- a/pitivi/preset.py
+++ b/pitivi/preset.py
@@ -55,7 +55,7 @@ class PresetManager(Loggable):
@ivar cur_preset: The currently selected preset. Note that a preset has to
be selected before it can be changed.
@type cur_preset: str
- @ivar ordered: A list holding (name -> preset_dict) tuples.
+ @ivar ordered: A list holding (name, preset_dict) tuples.
@type ordered: Gtk.ListStore
@ivar presets: A (name -> preset_dict) map.
@type presets: dict
@@ -180,9 +180,9 @@ class PresetManager(Loggable):
# Note: This generates a "row-inserted" signal in the model.
self.ordered.append((name, values))
- def renamePreset(self, old_name, new_name):
- """Change the name of a preset."""
- assert old_name in self.presets
+ def _renameCurrentPreset(self, new_name):
+ """Change the name of the current preset."""
+ old_name = self.cur_preset
if old_name == new_name:
# Nothing to do.
return
@@ -203,7 +203,6 @@ class PresetManager(Loggable):
new_filepath = self._createUserPresetPath(new_name)
self.presets[new_name]["filepath"] = new_filepath
self.cur_preset = new_name
- self.saveCurrentPreset()
def _createUserPresetPath(self, preset_name):
return os.path.join(self.user_path, preset_name + ".json")
@@ -251,8 +250,10 @@ class PresetManager(Loggable):
finally:
self.ignore_update_requests = False
- def saveCurrentPreset(self):
+ def saveCurrentPreset(self, new_name=None):
"""Update the current preset values from the widgets and save it."""
+ if new_name:
+ self._renameCurrentPreset(new_name)
self._updatePreset()
self.savePreset(self.cur_preset)
@@ -262,11 +263,14 @@ class PresetManager(Loggable):
for field, (setter, getter) in self.widget_map.items():
values[field] = getter()
- def _isCurrentPresetChanged(self):
+ def _isCurrentPresetChanged(self, name):
"""Return whether the widgets values differ from those of the preset."""
if not self.cur_preset:
# There is no preset selected, nothing to do.
return False
+ if not name == self.cur_preset:
+ # The preset can be renamed by saving.
+ return True
values = self.presets[self.cur_preset]
return any((values[field] != getter()
for field, (setter, getter) in self.widget_map.items()))
@@ -303,13 +307,22 @@ class PresetManager(Loggable):
# Note: This generates a "row-inserted" signal in the model.
self.ordered.prepend((name, values))
- def isSaveButtonSensitive(self):
- """Whether the Save button should be enabled"""
- if not self.cur_preset:
- return False
- if "volatile" in self.presets[self.cur_preset]:
- return False
- return self._isCurrentPresetChanged()
+ def isSaveButtonSensitive(self, name):
+ """Whether the Save button should be enabled.
+
+ @param name: The new preset name.
+ @type name: str
+ """
+ if self.cur_preset:
+ if "volatile" in self.presets[self.cur_preset]:
+ return False
+ return self._isCurrentPresetChanged(name)
+
+ if name:
+ # Can be saved as new preset.
+ return True
+
+ return False
def isRemoveButtonSensitive(self):
"""Whether the Remove button should be enabled"""
diff --git a/pitivi/project.py b/pitivi/project.py
index 69d5e0b..4aaf185 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -1611,7 +1611,7 @@ class ProjectSettingsDialog():
def _updatePresetActions(self, button, combo, mgr):
entry = combo.get_child()
preset_name = entry.get_text()
- can_save = mgr.cur_preset != preset_name or mgr.isSaveButtonSensitive()
+ can_save = mgr.isSaveButtonSensitive(preset_name)
self.preset_actions[button]["save"].set_enabled(can_save)
if can_save:
entry.get_style_context().add_class("unsaved")
@@ -1730,7 +1730,11 @@ class ProjectSettingsDialog():
self._updatePresetActions(button, combo, mgr)
def _savePresetCb(self, unused_action, unused_param, mgr, button, combo):
- mgr.saveCurrentPreset()
+ entry = combo.get_child()
+ preset_name = entry.get_text()
+ if not mgr.cur_preset:
+ mgr.createPreset(preset_name)
+ mgr.saveCurrentPreset(preset_name)
self._updatePresetActions(button, combo, mgr)
def _updateAudioPresetMenuButton(self, unused_source, unused_target):
diff --git a/pitivi/render.py b/pitivi/render.py
index 385e1f5..e09b45d 100644
--- a/pitivi/render.py
+++ b/pitivi/render.py
@@ -538,8 +538,9 @@ class RenderDialog(Loggable):
"""Handle the renaming of a preset."""
from pitivi.preset import DuplicatePresetNameException
old_name = mgr.getModel()[path][0]
+ assert old_name == mgr.cur_preset
try:
- mgr.renamePreset(old_name, new_text)
+ mgr.saveCurrentPreset(new_text)
self._updateRenderPresetButtons()
except DuplicatePresetNameException:
error_markup = _('"%s" already exists.') % new_text
@@ -576,7 +577,7 @@ class RenderDialog(Loggable):
infobar.hide()
def _updateRenderSaveButton(self, unused_in, button):
- button.set_sensitive(self.render_presets.isSaveButtonSensitive())
+ button.set_sensitive(self.render_presets.isSaveButtonSensitive(self.render_presets.cur_preset))
def _addRenderPresetButtonClickedCb(self, unused_button):
preset_name = self.render_presets.getNewPresetName()
@@ -602,7 +603,7 @@ class RenderDialog(Loggable):
self.remove_render_preset_button.set_sensitive(True)
def _updateRenderPresetButtons(self):
- can_save = self.render_presets.isSaveButtonSensitive()
+ can_save = self.render_presets.isSaveButtonSensitive(self.render_presets.cur_preset)
self.save_render_preset_button.set_sensitive(can_save)
can_remove = self.render_presets.isRemoveButtonSensitive()
self.remove_render_preset_button.set_sensitive(can_remove)
diff --git a/tests/test_preset.py b/tests/test_preset.py
index 89ae476..2b5d359 100644
--- a/tests/test_preset.py
+++ b/tests/test_preset.py
@@ -85,12 +85,13 @@ class TestPresetBasics(TestCase):
self.manager.createPreset('preseT onE', {'name1': '1A'})
self.manager.createPreset('Preset Two', {'name1': '2A'})
- self.manager.renamePreset('preseT onE', 'Preset One')
+ self.manager.restorePreset('preseT onE')
+ self.manager.saveCurrentPreset('Preset One')
self.assertRaises(DuplicatePresetNameException,
- self.manager.renamePreset, 'Preset One', 'Preset TWO')
+ self.manager.saveCurrentPreset, 'Preset TWO')
self.assertRaises(DuplicatePresetNameException,
- self.manager.renamePreset, 'Preset One', 'Preset two')
+ self.manager.saveCurrentPreset, 'Preset two')
def testLoadHandlesMissingDirectory(self):
self.manager.default_path = '/pitivi/non/existing/directory/1'
@@ -203,8 +204,9 @@ class TestAudioPresetsIO(TestCase):
system_presets = list(self.manager.presets.keys())
new_name_template = "%s new"
for preset_name in system_presets:
+ self.manager.restorePreset(preset_name)
new_name = new_name_template % preset_name
- self.manager.renamePreset(preset_name, new_name)
+ self.manager.saveCurrentPreset(new_name)
# Check that the files have not been deleted or changed.
other_manager = AudioPresetManager()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]