From 16f45009ac508f8fa3440f394e16e30f1f186552 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Wed, 25 Jul 2018 19:32:50 +0200 Subject: [PATCH] Fix some bugs when exporting composition to Kv language --- kivyforms/formcanvas.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/kivyforms/formcanvas.py b/kivyforms/formcanvas.py index a1b7058..073587c 100644 --- a/kivyforms/formcanvas.py +++ b/kivyforms/formcanvas.py @@ -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 -- 2.39.5