[pitivi: 52/94] Created Separate function for Save and Remove button + PEP8 compliant



commit 30d4983d0d909927129b4dd23ac05a9a40fb4b75
Author: Feroze Naina <ferozenaina gmail com>
Date:   Thu Aug 18 21:50:21 2011 +0530

    Created Separate function for Save and Remove button + PEP8 compliant

 pitivi/ui/encodingdialog.py |   17 +++++++----------
 pitivi/ui/preset.py         |   24 ++++++++++++++++++++++--
 2 files changed, 29 insertions(+), 12 deletions(-)
---
diff --git a/pitivi/ui/encodingdialog.py b/pitivi/ui/encodingdialog.py
index 56983b4..51e00be 100644
--- a/pitivi/ui/encodingdialog.py
+++ b/pitivi/ui/encodingdialog.py
@@ -48,6 +48,7 @@ from pitivi.ui.common import\
 
 from pitivi.ui.preset import RenderPresetManager, DuplicatePresetNameException
 
+
 def beautify_factoryname(factory):
     """Returns a nice name for the specified gst.ElementFactory instance."""
     # only replace lowercase versions of "format", "video", "audio"
@@ -231,8 +232,7 @@ class EncodingDialog(Renderer, Loggable):
             "frame-rate": gst.Fraction(int(get_combo_value(self.frame_rate_combo).num),
                                         int(get_combo_value(self.frame_rate_combo).denom)),
             "height": self.getDimension("height"),
-            "width": self.getDimension("width")
-        })
+            "width": self.getDimension("width")})
 
     def bindCombo(self, mgr, name, widget):
         if name == "container":
@@ -403,9 +403,8 @@ class EncodingDialog(Renderer, Loggable):
         infobar = self._infobarForPresetManager[mgr]
         infobar.hide()
 
-
     def _updateRenderSaveButton(self, unused_in, button):
-        button.set_sensitive(self.render_presets.isCurrentPresetChanged())
+        button.set_sensitive(self.render_presets.isSaveButtonSensitive())
 
     @staticmethod
     def _getUniquePresetName(mgr):
@@ -431,8 +430,8 @@ class EncodingDialog(Renderer, Loggable):
             "frame-rate": gst.Fraction(int(get_combo_value(self.frame_rate_combo).num),
                                         int(get_combo_value(self.frame_rate_combo).denom)),
             "height": self.getDimension("height"),
-            "width": self.getDimension("width")
-        })
+            "width": self.getDimension("width")})
+
         self.render_presets.restorePreset(preset_name)
         self._updateRenderPresetButtons()
 
@@ -447,11 +446,9 @@ class EncodingDialog(Renderer, Loggable):
         self.render_presets.save()
 
     def _updateRenderPresetButtons(self):
-        preset_changed = self.render_presets.isCurrentPresetChanged()
+        preset_changed = self.render_presets.isSaveButtonSensitive()
         self.save_render_preset_button.set_sensitive(preset_changed)
-        preset_selected = bool(self.render_presets.cur_preset)
-        if self.render_presets.cur_preset == "No Preset":
-            preset_selected = 0 #  Disable "Remove" if "No Preset" is selected
+        preset_selected = self.render_presets.isRemoveButtonSensitive()
         self.remove_render_preset_button.set_sensitive(preset_selected)
 
     def _removeRenderPresetButtonClickedCb(self, button):
diff --git a/pitivi/ui/preset.py b/pitivi/ui/preset.py
index a33fa93..8b6322a 100644
--- a/pitivi/ui/preset.py
+++ b/pitivi/ui/preset.py
@@ -35,6 +35,7 @@ class DuplicatePresetNameException(Exception):
     """Raised when an operation would result in a duplicated preset name."""
     pass
 
+
 class PresetManager(object):
     """Abstract class for storing a list of presets.
 
@@ -230,6 +231,7 @@ class PresetManager(object):
         return any((values[field] != getter()
                     for field, (setter, getter) in self.widget_map.iteritems()))
 
+
 class VideoPresetManager(PresetManager):
 
     filename = "video_presets"
@@ -265,6 +267,7 @@ class VideoPresetManager(PresetManager):
         parser.set(section, "par-denom",
             str(int(values["par"].denom)))
 
+
 class AudioPresetManager(PresetManager):
 
     filename = "audio_presets"
@@ -285,6 +288,7 @@ class AudioPresetManager(PresetManager):
         parser.set(section, "depth", str(values["depth"]))
         parser.set(section, "sample-rate", str(values["sample-rate"]))
 
+
 class RenderPresetManager(PresetManager):
     """ load() and save() are rewritten to save widget values to json """
 
@@ -333,7 +337,7 @@ class RenderPresetManager(PresetManager):
             except:
                 filename = name + ".json"
                 filepath = os.path.join(self.path, filename)
-            
+
             if not name == "No Preset":
                 fout = open(filepath, "w")
                 self.saveSection(fout, name)
@@ -350,7 +354,7 @@ class RenderPresetManager(PresetManager):
             "framerate-num": values["frame-rate"].num,
             "framerate-denom": values["frame-rate"].denom,
             "channels": values["channels"],
-            "depth":  int(values["depth"]),
+            "depth": int(values["depth"]),
             "sample-rate": int(values["sample-rate"]),
         }, indent=4)
         fout.write(data)
@@ -373,3 +377,19 @@ class RenderPresetManager(PresetManager):
         # Note: This generates a "row-inserted" signal in the model.
         self.ordered.prepend((name, values))
 
+    def isSaveButtonSensitive(self):
+        """Check if Save buttons should be sensitive"""
+        if self.cur_preset == "No Preset" or not self.cur_preset:
+            # There is no preset selected, nothing to do.
+            return False
+
+        values = self.presets[self.cur_preset]
+        return any((values[field] != getter()
+                    for field, (setter, getter) in self.widget_map.iteritems()))
+
+    def isRemoveButtonSensitive(self):
+        if self.cur_preset == "No Preset" or not self.cur_preset:
+            # There is no preset selected, nothing to do.
+            return False
+        else:
+            return True



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]