[pitivi: 45/94] Fixed DuplicatePresetName error and infobar
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi: 45/94] Fixed DuplicatePresetName error and infobar
- Date: Sun, 11 Sep 2011 16:16:13 +0000 (UTC)
commit b4fd9b37d01a37755a6a6183fa20525c59c6a3ca
Author: Feroze Naina <ferozenaina gmail com>
Date: Thu Aug 4 22:46:57 2011 +0530
Fixed DuplicatePresetName error and infobar
data/ui/encodingdialog.ui | 39 +++++++++++++++++++++++++++++++++++++
pitivi/ui/encodingdialog.py | 45 ++++++++++++++++++++++++++++++++++++++++++-
pitivi/ui/preset.py | 5 +++-
3 files changed, 87 insertions(+), 2 deletions(-)
---
diff --git a/data/ui/encodingdialog.ui b/data/ui/encodingdialog.ui
index afa05e9..2ff378f 100644
--- a/data/ui/encodingdialog.ui
+++ b/data/ui/encodingdialog.ui
@@ -149,6 +149,45 @@
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkInfoBar" id="render-preset-infobar">
+ <property name="app_paintable">True</property>
+ <property name="can_focus">False</property>
+ <property name="message_type">error</property>
+ <child internal-child="content_area">
+ <object class="GtkBox" id="infobar-content_area3">
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="render-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>
+ </child>
+ <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>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+
<child>
<object class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property>
diff --git a/pitivi/ui/encodingdialog.py b/pitivi/ui/encodingdialog.py
index 14118f8..89b078d 100644
--- a/pitivi/ui/encodingdialog.py
+++ b/pitivi/ui/encodingdialog.py
@@ -45,7 +45,7 @@ from pitivi.ui.common import\
get_combo_value,\
set_combo_value
-from pitivi.ui.preset import RenderPresetManager
+from pitivi.ui.preset import RenderPresetManager, DuplicatePresetNameException
def beautify_factoryname(factory):
"""Returns a nice name for the specified gst.ElementFactory instance."""
@@ -169,6 +169,10 @@ class EncodingDialog(Renderer, Loggable):
self.render_preset_treeview, self.render_presets,
self._updateRenderPresetButtons)
+ self._infobarForPresetManager = {
+ self.render_presets: self.render_preset_infobar}
+
+
# Bind widgets to RenderPresetsManager
self.bindCombo(self.render_presets, "channels",
self.channels_combo)
@@ -323,8 +327,13 @@ class EncodingDialog(Renderer, 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, model, path, iter_, column, renderer, treeview):
"""Handle the addition of a preset to the model of the preset manager.
@@ -340,6 +349,36 @@ class EncodingDialog(Renderer, Loggable):
error_markup = _('"%s" already exists.') % new_text
self._showPresetManagerError(mgr, error_markup)
+ def _presetNameEditingStartedCb(self, renderer, editable, path, mgr):
+ """Handle the start of a preset renaming."""
+ self._hidePresetManagerError(mgr)
+
+ def _treeviewDefocusedCb(self, widget, 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()
+
@staticmethod
def _getUniquePresetName(mgr):
"""Get a unique name for a new preset for the specified PresetManager.
@@ -396,6 +435,7 @@ class EncodingDialog(Renderer, Loggable):
mgr.restorePreset(self.selected_preset)
self._displaySettings()
update_preset_buttons_func()
+ self._hidePresetManagerError(mgr)
def _setProperties(self):
self.window = self.builder.get_object("render-dialog")
@@ -422,6 +462,9 @@ class EncodingDialog(Renderer, Loggable):
"save_render_preset_button")
self.remove_render_preset_button = self.builder.get_object(
"remove_render_preset_button")
+ self.render_preset_infobar = self.builder.get_object(
+ "render-preset-infobar")
+
def _settingsChanged(self, settings):
self.updateResolution()
diff --git a/pitivi/ui/preset.py b/pitivi/ui/preset.py
index eaef2a9..87b3395 100644
--- a/pitivi/ui/preset.py
+++ b/pitivi/ui/preset.py
@@ -356,7 +356,10 @@ class RenderPresetManager(PresetManager):
fout.write(data)
def removePreset(self, name):
- os.remove(self.presets[name]["filepath"]) # Deletes json file
+ try:
+ os.remove(self.presets[name]["filepath"]) # Deletes json file if exists
+ except Exception:
+ pass
self.presets.pop(name)
for i, row in enumerate(self.ordered):
if row[0] == name:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]