[pitivi] preset: Remove the infobars used to show errors
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] preset: Remove the infobars used to show errors
- Date: Wed, 25 Nov 2015 09:56:28 +0000 (UTC)
commit 1a5e3bd2726a7b54ccef0fe7798da61f44520ba8
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Thu Oct 22 12:50:00 2015 +0200
preset: Remove the infobars used to show errors
The intention is to allow overwriting presets. There will not be much
lost if this happens by mistake.
Differential Revision: https://phabricator.freedesktop.org/D374
Reviewed-by: Thibault Saunier <tsaunier gnome org>
data/ui/projectsettings.ui | 106 +------------------------------------------
pitivi/preset.py | 36 ++++-----------
pitivi/project.py | 40 +---------------
pitivi/render.py | 48 +-------------------
tests/test_preset.py | 25 +++++++----
5 files changed, 34 insertions(+), 221 deletions(-)
---
diff --git a/data/ui/projectsettings.ui b/data/ui/projectsettings.ui
index 5d1a2ac..9f4851e 100644
--- a/data/ui/projectsettings.ui
+++ b/data/ui/projectsettings.ui
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.1 -->
+<!-- Generated with glade 3.19.0 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkAdjustment" id="adjustment1">
@@ -187,57 +187,6 @@
</packing>
</child>
<child>
- <object class="GtkInfoBar" id="video-preset-infobar">
- <property name="app_paintable">True</property>
- <property name="can_focus">False</property>
- <property name="message_type">error</property>
- <child internal-child="action_area">
- <object class="GtkButtonBox" id="infobar-action_area2">
- <property name="can_focus">False</property>
- <property name="orientation">vertical</property>
- <property name="layout_style">center</property>
- <child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child internal-child="content_area">
- <object class="GtkBox" id="infobar-content_area2">
- <property name="can_focus">False</property>
- <child>
- <object class="GtkLabel" id="video-preset-error-label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
<object class="GtkBox" id="video_details">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -518,7 +467,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">2</property>
+ <property name="position">1</property>
</packing>
</child>
</object>
@@ -622,55 +571,6 @@
</packing>
</child>
<child>
- <object class="GtkInfoBar" id="audio-preset-infobar">
- <property name="app_paintable">True</property>
- <property name="can_focus">False</property>
- <property name="message_type">error</property>
- <child internal-child="action_area">
- <object class="GtkButtonBox" id="infobar-action_area3">
- <property name="can_focus">False</property>
- <property name="orientation">vertical</property>
- <property name="layout_style">center</property>
- <child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child internal-child="content_area">
- <object class="GtkBox" id="infobar-content_area3">
- <property name="can_focus">False</property>
- <child>
- <object class="GtkLabel" id="audio-preset-error-label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="opacity">0.99000000022351742</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -748,7 +648,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">2</property>
+ <property name="position">1</property>
</packing>
</child>
</object>
diff --git a/pitivi/preset.py b/pitivi/preset.py
index 51a8ec1..a3e4fa3 100644
--- a/pitivi/preset.py
+++ b/pitivi/preset.py
@@ -33,12 +33,6 @@ from pitivi.utils import system
from pitivi.utils.loggable import Loggable
-class DuplicatePresetNameException(Exception):
-
- """Raised when an operation would result in a duplicated preset name."""
- pass
-
-
class DeserializeException(Exception):
pass
@@ -147,17 +141,15 @@ class PresetManager(Loggable):
return self.getUniqueName(_("New preset"), _("New preset %d"))
def createPreset(self, name, values=None, volatile=False):
- """Create a new preset.
+ """Create a preset, overwriting the preset with the same name if any.
- @param name: The name of the new preset, must be unique.
+ @param name: The name of the new preset.
@type name: str
@param values: The values of the new preset.
@type values: dict
@param volatile: Whether the preset should not be saveable.
@type volatile: bool
"""
- if self.hasPreset(name):
- raise DuplicatePresetNameException(name)
if not values:
values = {}
self._updatePresetValues(values)
@@ -167,19 +159,7 @@ class PresetManager(Loggable):
self.cur_preset = name
def _addPreset(self, name, values):
- """Add a preset, overwriting the preset with the same name if it exists.
-
- @param name: The name of the new preset.
- @type name: str
- @param values: The values of the new preset.
- @type values: dict
- """
- if self.hasPreset(name):
- for i, row in enumerate(self.ordered):
- if row[0] == name:
- del self.presets[row[1]["name"]]
- del self.ordered[i]
- break
+ self._forgetPreset(name)
self.presets[name] = values
# Note: This generates a "row-inserted" signal in the model.
self.ordered.append((name, values))
@@ -190,8 +170,8 @@ class PresetManager(Loggable):
if old_name == new_name:
# Nothing to do.
return
- if old_name.lower() != new_name.lower() and self.hasPreset(new_name):
- raise DuplicatePresetNameException()
+ # If there is one already with this name, make way for this one.
+ self._forgetPreset(new_name)
for i, row in enumerate(self.ordered):
if row[0] == old_name:
row[0] = new_name
@@ -292,7 +272,11 @@ class PresetManager(Loggable):
self._forgetPreset(name)
def _forgetPreset(self, name):
- self.presets.pop(name)
+ try:
+ self.presets.pop(name)
+ except KeyError:
+ # Nothing to forget.
+ return
for i, row in enumerate(self.ordered):
if row[0] == name:
del self.ordered[i]
diff --git a/pitivi/project.py b/pitivi/project.py
index f522fc4..1b98f27 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -51,8 +51,7 @@ from pitivi.utils.ripple_update_group import RippleUpdateGroup
from pitivi.utils.ui import frame_rates, audio_rates,\
audio_channels, beautify_time_delta, get_combo_value, set_combo_value,\
pixel_aspect_ratios, display_aspect_ratios, SPACING
-from pitivi.preset import AudioPresetManager, DuplicatePresetNameException,\
- VideoPresetManager
+from pitivi.preset import AudioPresetManager, VideoPresetManager
from pitivi.render import CachedEncoderList
@@ -1400,8 +1399,6 @@ class ProjectSettingsDialog():
self.select_par_radiobutton = getObj("select_par_radiobutton")
self.constrain_sar_button = getObj("constrain_sar_button")
self.select_dar_radiobutton = getObj("select_dar_radiobutton")
- self.video_preset_infobar = getObj("video-preset-infobar")
- self.audio_preset_infobar = getObj("audio-preset-infobar")
self.title_entry = getObj("title_entry")
self.author_entry = getObj("author_entry")
self.year_spinbutton = getObj("year_spinbutton")
@@ -1529,12 +1526,6 @@ class ProjectSettingsDialog():
self.video_presets_combo,
self.video_preset_menubutton)
- # A map which tells which infobar should be used when displaying
- # an error for a preset manager.
- self._infobarForPresetManager = {
- self.audio_presets: self.audio_preset_infobar,
- self.video_presets: self.video_preset_infobar}
-
# Bind the widgets in the Video tab to the Video Presets Manager.
self.bindSpinbutton(self.video_presets, "width", self.width_spinbutton)
self.bindSpinbutton(
@@ -1649,38 +1640,13 @@ class ProjectSettingsDialog():
def _presetChangedCb(self, combo, mgr, button):
"""Handle the selection of a preset."""
+ # Check whether the user selected a preset or editing the preset name.
preset_name = combo.get_active_id()
if preset_name:
# The user selected a preset.
mgr.restorePreset(preset_name)
self._updateSar()
- self._updatePresetActions(button, combo, mgr)
- self._hidePresetManagerError(mgr)
- else:
- # The user is editing the preset name.
- self._updatePresetActions(button, combo, mgr)
-
- def _showPresetManagerError(self, mgr, error_markup):
- """Show the specified error on the infobar associated with the manager.
-
- @param mgr: The preset manager for which to show the error.
- @type mgr: PresetManager
- """
- infobar = self._infobarForPresetManager[mgr]
- # The infobar must contain exactly one object in the content area:
- # a label for displaying the error.
- label = infobar.get_content_area().children()[0]
- label.set_markup(error_markup)
- infobar.show()
-
- def _hidePresetManagerError(self, mgr):
- """Hide the error infobar associated with the manager.
-
- @param mgr: The preset manager for which to hide the error infobar.
- @type mgr: PresetManager
- """
- infobar = self._infobarForPresetManager[mgr]
- infobar.hide()
+ self._updatePresetActions(button, combo, mgr)
def widthHeightLinked(self):
return self.constrain_sar_button.props.active and not self.video_presets.ignore_update_requests
diff --git a/pitivi/render.py b/pitivi/render.py
index 79474e3..54d3bb1 100644
--- a/pitivi/render.py
+++ b/pitivi/render.py
@@ -406,9 +406,6 @@ class RenderDialog(Loggable):
self.wg.addEdge(self.channels_combo, self.save_render_preset_button)
self.wg.addEdge(self.sample_rate_combo, self.save_render_preset_button)
- self._infobarForPresetManager = {
- self.render_presets: self.render_preset_infobar}
-
# Bind widgets to RenderPresetsManager
self.render_presets.bindWidget(
"container",
@@ -522,11 +519,8 @@ class RenderDialog(Loggable):
model.connect(
"row-inserted", self._newPresetCb, column, renderer, treeview)
renderer.connect("edited", self._presetNameEditedCb, mgr)
- renderer.connect(
- "editing-started", self._presetNameEditingStartedCb, mgr)
treeview.get_selection().connect("changed", self._presetChangedCb,
mgr, update_buttons_func)
- treeview.connect("focus-out-event", self._treeviewDefocusedCb, mgr)
def _newPresetCb(self, unused_model, path, unused_iter_, column, renderer, treeview):
"""Handle the addition of a preset to the model of the preset manager.
@@ -536,45 +530,10 @@ class RenderDialog(Loggable):
def _presetNameEditedCb(self, unused_renderer, path, new_text, mgr):
"""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.saveCurrentPreset(new_text)
- self._updateRenderPresetButtons()
- except DuplicatePresetNameException:
- error_markup = _('"%s" already exists.') % new_text
- self._showPresetManagerError(mgr, error_markup)
-
- def _presetNameEditingStartedCb(self, unused_renderer, unused_editable, unused_path, mgr):
- """Handle the start of a preset renaming."""
- self._hidePresetManagerError(mgr)
-
- def _treeviewDefocusedCb(self, unused_widget, unused_event, mgr):
- """Handle the treeview loosing the focus."""
- self._hidePresetManagerError(mgr)
-
- def _showPresetManagerError(self, mgr, error_markup):
- """Show the specified error on the infobar associated with the manager.
-
- @param mgr: The preset manager for which to show the error.
- @type mgr: PresetManager
- """
- infobar = self._infobarForPresetManager[mgr]
- # The infobar must contain exactly one object in the content area:
- # a label for displaying the error.
- label = infobar.get_content_area().children()[0]
- label.set_markup(error_markup)
- infobar.show()
-
- def _hidePresetManagerError(self, mgr):
- """Hide the error infobar associated with the manager.
-
- @param mgr: The preset manager for which to hide the error infobar.
- @type mgr: PresetManager
- """
- infobar = self._infobarForPresetManager[mgr]
- infobar.hide()
+ mgr.saveCurrentPreset(new_text)
+ self._updateRenderPresetButtons()
def _updateRenderSaveButton(self, unused_in, button):
button.set_sensitive(self.render_presets.isSaveButtonSensitive(self.render_presets.cur_preset))
@@ -622,7 +581,6 @@ class RenderDialog(Loggable):
mgr.restorePreset(self.selected_preset)
self._displaySettings()
update_preset_buttons_func()
- self._hidePresetManagerError(mgr)
def _createUi(self):
builder = Gtk.Builder()
@@ -657,8 +615,6 @@ class RenderDialog(Loggable):
"save_render_preset_button")
self.remove_render_preset_button = builder.get_object(
"remove_render_preset_button")
- self.render_preset_infobar = builder.get_object(
- "render-preset-infobar")
icon = os.path.join(configure.get_pixmap_dir(), "pitivi-render-16.png")
self.window.set_icon_from_file(icon)
diff --git a/tests/test_preset.py b/tests/test_preset.py
index 843f488..2e78766 100644
--- a/tests/test_preset.py
+++ b/tests/test_preset.py
@@ -28,8 +28,7 @@ import shutil
import tempfile
from unittest import TestCase
-from pitivi.preset import DuplicatePresetNameException, \
- PresetManager, \
+from pitivi.preset import PresetManager, \
AudioPresetManager
@@ -73,8 +72,8 @@ class TestPresetBasics(TestCase):
def testAddPreset(self):
self.manager.createPreset('preseT onE', {'name1': '1A'})
- self.assertRaises(DuplicatePresetNameException,
- self.manager.createPreset, 'Preset One', {'name1': '2A'})
+ self.manager.createPreset('Preset One', {'name1': '2A'})
+ self.assertEqual(2, len(self.manager.presets))
def testAddPresetWithNonAsciiName(self):
unicode_name = "ソリッド・スネーク"
@@ -84,14 +83,22 @@ class TestPresetBasics(TestCase):
def testRenamePreset(self):
self.manager.createPreset('preseT onE', {'name1': '1A'})
self.manager.createPreset('Preset Two', {'name1': '2A'})
+ self.assertEqual(2, len(self.manager.presets))
self.manager.restorePreset('preseT onE')
self.manager.saveCurrentPreset('Preset One')
-
- self.assertRaises(DuplicatePresetNameException,
- self.manager.saveCurrentPreset, 'Preset TWO')
- self.assertRaises(DuplicatePresetNameException,
- self.manager.saveCurrentPreset, 'Preset two')
+ self.assertEqual(2, len(self.manager.presets))
+ self.manager.saveCurrentPreset('Preset TWO')
+ self.assertEqual(2, len(self.manager.presets))
+ self.manager.saveCurrentPreset('Preset two')
+ self.assertEqual(2, len(self.manager.presets))
+
+ self.manager.saveCurrentPreset('Preset Two')
+ self.assertEqual(1, len(self.manager.presets))
+ self.manager.saveCurrentPreset('Preset Two')
+ self.assertEqual(1, len(self.manager.presets))
+ self.manager.saveCurrentPreset('preseT onE')
+ self.assertEqual(1, len(self.manager.presets))
def testLoadHandlesMissingDirectory(self):
self.manager.default_path = '/pitivi/non/existing/directory/1'
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]