More complete example editor
authorJavier Sancho <jsf@jsancho.org>
Wed, 25 Jul 2018 17:00:51 +0000 (19:00 +0200)
committerJavier Sancho <jsf@jsancho.org>
Wed, 25 Jul 2018 17:00:51 +0000 (19:00 +0200)
examples/designer.py

index 5ccdb50..17551ed 100644 (file)
@@ -1,9 +1,42 @@
 from kivy.app import App
+from kivy.lang import Builder
+from kivy.uix.button import Button
+from kivy.uix.label import Label
 from kivyforms import FormCanvas
 
+screen = Builder.load_string('''
+BoxLayout:
+    orientation: 'horizontal'
+    FormCanvas:
+        id: form_canvas
+    BoxLayout:
+        size_hint: 0.2, 1
+        orientation: 'vertical'
+        Button:
+            text: 'Add button'
+            on_press: app.add_button()
+        Button:
+            text: 'Add label'
+            on_press: app.add_label()
+''')
+
 class DesignerApp(App):
+    button_id = 0
+    label_id = 0
+
+    def on_start(self):
+        self.form_canvas = self.root.ids.form_canvas
+
+    def add_button(self):
+        self.button_id += 1
+        self.form_canvas.add_widget(Button(text='Button ' + str(self.button_id)))
+
+    def add_label(self):
+        self.label_id += 1
+        self.form_canvas.add_widget(Label(text='Label ' + str(self.label_id)))
+
     def build(self):
-        return FormCanvas()
+        return screen
 
 if __name__ == '__main__':
     app = DesignerApp()