[pitivi] render: Use a TextWidget for preset name widget



commit 30c7450354bc37431b8f7d8784f9841fb9670194
Author: Thibault Saunier <thibault saunier osg samsung com>
Date:   Thu Jan 5 21:22:09 2017 -0300

    render: Use a TextWidget for preset name widget
    
    Instead of having a Gtk.Box that contains the preset widgets, use a
    Gtk.Grid, allowig higher control when packing the TextWidget in code.
    
    This will be useful so that the preset name can be properly verified
    to be valid (when we will use GstEncodingTarget for the serialization
    format).
    
    Also allow using a standard GtkComboBox for the TextWidget as this is
    what we need for that case.
    
    Reviewed-by: Alex Băluț <alexandru balut gmail com>
    Differential Revision: https://phabricator.freedesktop.org/D1590

 data/ui/renderingdialog.ui |   62 +++++++++++++++----------------------------
 pitivi/render.py           |    8 +++++-
 pitivi/utils/widgets.py    |   10 +++++-
 3 files changed, 37 insertions(+), 43 deletions(-)
---
diff --git a/data/ui/renderingdialog.ui b/data/ui/renderingdialog.ui
index ad93953..5a100f2 100644
--- a/data/ui/renderingdialog.ui
+++ b/data/ui/renderingdialog.ui
@@ -199,46 +199,10 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkBox" id="preset_box">
+                  <object class="GtkGrid" id="preset_table">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="halign">end</property>
-                    <property name="margin_top">12</property>
-                    <property name="margin_bottom">12</property>
-                    <property name="spacing">6</property>
-                    <child>
-                      <object class="GtkLabel" id="label6">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="halign">start</property>
-                        <property name="label" translatable="yes">Preset:</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkComboBox" id="presets_combo">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="has_entry">True</property>
-                        <child internal-child="entry">
-                          <object class="GtkEntry" id="combobox-entry">
-                            <property name="can_focus">True</property>
-                          </object>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
                     <child>
                       <object class="GtkMenuButton" id="preset_menubutton">
                         <property name="visible">True</property>
@@ -254,11 +218,29 @@
                         </child>
                       </object>
                       <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">2</property>
+                        <property name="left_attach">2</property>
+                        <property name="top_attach">0</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkLabel" id="label6">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="halign">start</property>
+                        <property name="xpad">10</property>
+                        <property name="label" translatable="yes">Preset:</property>
+                        <attributes>
+                          <attribute name="weight" value="bold"/>
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
diff --git a/pitivi/render.py b/pitivi/render.py
index b35368b..6f9d6bf 100644
--- a/pitivi/render.py
+++ b/pitivi/render.py
@@ -42,6 +42,7 @@ from pitivi.utils.ui import frame_rates
 from pitivi.utils.ui import get_combo_value
 from pitivi.utils.ui import set_combo_value
 from pitivi.utils.widgets import GstElementSettingsDialog
+from pitivi.utils.widgets import TextWidget
 
 
 class Encoders(Loggable):
@@ -560,9 +561,14 @@ class RenderDialog(Loggable):
         self.filebutton = builder.get_object("filebutton")
         self.fileentry = builder.get_object("fileentry")
         self.resolution_label = builder.get_object("resolution_label")
-        self.presets_combo = builder.get_object("presets_combo")
         self.preset_menubutton = builder.get_object("preset_menubutton")
 
+        text_widget = TextWidget(matches=r'^[a-z][a-z-0-9-]+$', combobox=True)
+        self.presets_combo = text_widget.combo
+        preset_table = builder.get_object("preset_table")
+        preset_table.attach(text_widget, 1, 0, 1, 1)
+        text_widget.show()
+
         self.video_output_checkbutton.props.active = self.project.video_profile.is_enabled()
         self.audio_output_checkbutton.props.active = self.project.audio_profile.is_enabled()
 
diff --git a/pitivi/utils/widgets.py b/pitivi/utils/widgets.py
index 1c3df19..acca35e 100644
--- a/pitivi/utils/widgets.py
+++ b/pitivi/utils/widgets.py
@@ -46,10 +46,11 @@ from pitivi.utils.ui import unpack_color
 ZOOM_SLIDER_PADDING = SPACING * 4 / 5
 
 
-class DynamicWidget(object):
+class DynamicWidget(Loggable):
     """Abstract widget providing a way to get, set and observe properties."""
 
     def __init__(self, default):
+        super().__init__()
         self.default = default
 
     def connectValueChanged(self, callback, *args):
@@ -107,7 +108,7 @@ class TextWidget(Gtk.Box, DynamicWidget):
         "activate": (GObject.SignalFlags.RUN_LAST, None, (),)
     }
 
-    def __init__(self, matches=None, choices=None, default=None):
+    def __init__(self, matches=None, choices=None, default=None, combobox=False):
         if not default:
             # In the case of text widgets, a blank default is an empty string
             default = ""
@@ -126,6 +127,11 @@ class TextWidget(Gtk.Box, DynamicWidget):
             self.pack_start(self.combo, expand=False, fill=False, padding=0)
             for choice in choices:
                 self.combo.append_text(choice)
+        elif combobox:
+            self.combo = Gtk.ComboBox.new_with_entry()
+            self.text = self.combo.get_child()
+            self.combo.show()
+            self.pack_start(self.combo, expand=False, fill=False, padding=0)
         else:
             self.text = Gtk.Entry()
             self.text.show()


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