changeset ecd2b9613a66 in tryton:default
details: https://hg.tryton.org/tryton?cmd=changeset;node=ecd2b9613a66
description:
        Align CENTER instead of FILL when the widget is not expanded

        issue8889
        review264881002
diffstat:

 tryton/common/common.py                  |   7 +++++--
 tryton/gui/window/view_form/view/form.py |  26 +++++++++++++++++++-------
 2 files changed, 24 insertions(+), 9 deletions(-)

diffs (74 lines):

diff -r 3f473b25b5d5 -r ecd2b9613a66 tryton/common/common.py
--- a/tryton/common/common.py   Sat Dec 07 16:03:36 2019 +0100
+++ b/tryton/common/common.py   Wed Dec 11 18:37:15 2019 +0100
@@ -1232,13 +1232,16 @@
     return string[:length - len(ellipsis)] + ellipsis
 
 
-def get_align(float_):
+def get_align(float_, expand=True):
     "Convert float align into Gtk.Align"
     value = float(float_)
     if value < 0.5:
         return Gtk.Align.START
     elif value == 0.5:
-        return Gtk.Align.FILL
+        if expand:
+            return Gtk.Align.FILL
+        else:
+            return Gtk.Align.CENTER
     else:
         return Gtk.Align.END
 
diff -r 3f473b25b5d5 -r ecd2b9613a66 tryton/gui/window/view_form/view/form.py
--- a/tryton/gui/window/view_form/view/form.py  Sat Dec 07 16:03:36 2019 +0100
+++ b/tryton/gui/window/view_form/view/form.py  Wed Dec 11 18:37:15 2019 +0100
@@ -222,8 +222,12 @@
                 int(attributes.get('width', -1)),
                 int(attributes.get('height', -1)))
 
-        widget.widget.set_halign(get_align(attributes.get('xalign', 0.5)))
-        widget.widget.set_valign(get_align(attributes.get('yalign', 0.5)))
+        widget.widget.set_halign(get_align(
+                attributes.get('xalign', 0.5),
+                bool(attributes.get('xexpand', True))))
+        widget.widget.set_valign(get_align(
+                attributes.get('yalign', 0.5),
+                bool(attributes.get('yexpand'))))
         self.container.add(widget.widget, attributes)
 
         if name in self._mnemonics and widget.mnemonic_widget:
@@ -247,8 +251,12 @@
         vbox = VBox(attrs=attributes)
         if attributes.get('string'):
             label = Label(label=attributes['string'], attrs=attributes)
-            label.set_halign(get_align(attributes.get('xalign', 0.0)))
-            label.set_valign(get_align(attributes.get('yalign', 0.5)))
+            label.set_halign(get_align(
+                    attributes.get('xalign', 0.0),
+                    bool(attributes.get('xexpand', True))))
+            label.set_valign(get_align(
+                    attributes.get('yalign', 0.5),
+                    bool(attributes.get('yexpand', False))))
             vbox.pack_start(label, expand=True, fill=True, padding=0)
             self.view.state_widgets.append(label)
         vbox.pack_start(Gtk.HSeparator(), expand=True, fill=True, padding=0)
@@ -263,11 +271,15 @@
         if CONFIG['client.modepda']:
             attributes['xalign'] = 0.0
 
+        attributes.setdefault('xexpand', 0)
         label = Label(label=attributes.get('string', ''), attrs=attributes)
-        label.set_halign(get_align(attributes.get('xalign', 1.0)))
-        label.set_valign(get_align(attributes.get('yalign', 0.5)))
+        label.set_halign(get_align(
+                attributes.get('xalign', 1.0),
+                bool(attributes.get('xexpand'))))
+        label.set_valign(get_align(
+                attributes.get('yalign', 0.5),
+                bool(attributes.get('yexpand'))))
         label.set_angle(int(attributes.get('angle', 0)))
-        attributes.setdefault('xexpand', 0)
         self.view.state_widgets.append(label)
         self.container.add(label, attributes)
         if name:

Reply via email to