]> git.jsancho.org Git - kivyforms.git/blobdiff - kivyforms/formcanvas.py
Fix some bugs when exporting composition to Kv language
[kivyforms.git] / kivyforms / formcanvas.py
index a1b7058ad0141df64878494e93896615c825c98c..073587c0217f827fe3caddf9fb60717d43b1a7b1 100644 (file)
@@ -201,18 +201,19 @@ class FormCanvas(BoxLayout):
             spacing=self._canvas.spacing[0]
         )
 
-    def export_to_kv(self, widget, indent=''):
+    def export_to_kv(self):
         kv = """StackLayout:
     orientation: '{orientation}'
     padding: {padding}
     spacing: {spacing}
-""".format(orientation=self.orientation, padding=self.padding, spacing=self.spacing)
+""".format(orientation=self._canvas.orientation, padding=self._canvas.padding, spacing=self._canvas.spacing)
 
         indent = '    '
-        stack = [self]
+        stack = [self._canvas]
 
         widgets = self.walk(restrict=True)
         next(widgets)    # the first widget is the FormCanvas
+        next(widgets)    # and the second is the inner StackLayout
         for widget in widgets:
             if not isinstance(widget, Grabbable):
                 # Look for the widget position inside the tree
@@ -228,9 +229,12 @@ class FormCanvas(BoxLayout):
                 stack.append(widget)
 
                 # Widget attributes
-                kv += """{indent}height: 40
-{indent}size_hint: (1., None)
-{indent}text: '{text}'
-""".format(indent=indent*len(stack), text=widget.text)
+                for attr in ('height', 'size_hint', 'text'):
+                    if hasattr(widget, attr):
+                        kv += "{indent}{attr}: {value}\n".format(
+                            indent=indent*len(stack),
+                            attr=attr,
+                            value=getattr(widget, attr)
+                        )
 
         return kv