From: Javier Sancho Date: Wed, 25 Jul 2018 17:00:00 +0000 (+0200) Subject: Prepare FormCanvas to be used from other widgets X-Git-Url: https://git.jsancho.org/?p=kivyforms.git;a=commitdiff_plain;h=d435373e9e5b0a41b2a3a1a89c3ebd5653b0c6e1 Prepare FormCanvas to be used from other widgets --- diff --git a/kivyforms/formcanvas.py b/kivyforms/formcanvas.py index 8013ef6..a1b7058 100644 --- a/kivyforms/formcanvas.py +++ b/kivyforms/formcanvas.py @@ -1,5 +1,4 @@ from kivy.graphics import Color, Line -from kivy.uix.behaviors import ButtonBehavior from kivy.uix.boxlayout import BoxLayout from kivy.uix.button import Button from kivy.uix.label import Label @@ -110,26 +109,27 @@ class Grabbable(BoxLayout): self.attach(touch) -class FormCanvas(ButtonBehavior, StackLayout): +class FormCanvas(BoxLayout): def __init__(self, *args, **kwargs): super(FormCanvas, self).__init__(*args, **kwargs) - self.n = 0 - self.orientation = 'lr-tb' - self.padding = [10, 10, 10, 10] - self.spacing = [10, 10] + + self._canvas = StackLayout( + orientation='lr-tb', + padding=[10, 10, 10, 10], + spacing=[10, 10] + ) + super(FormCanvas, self).add_widget(self._canvas) self.widgets_height = 40 self.widgets_size_hint = (1, None) - def on_press(self, *args): - self.n += 1 + def add_widget(self, widget): g = Grabbable( height=self.widgets_height, size_hint=self.widgets_size_hint ) - g.add_widget(Button(text=str(self.n))) - self.add_widget(g) - #print(self.export_to_kv(self)) + g.add_widget(widget) + self._canvas.add_widget(g) def detach_widget(self, widget): "Detach grabbable widget from canvas and show widget destination" @@ -162,7 +162,7 @@ class FormCanvas(ButtonBehavior, StackLayout): # Put destination in the right place if zone in ('left', 'right') and widget.parent.orientation != 'horizontal': parent = widget.parent - box = parent.create_box() + box = self.create_box() parent.add_widget(box, index=widget_idx) parent.remove_widget(widget) box.add_widget(widget) @@ -198,7 +198,7 @@ class FormCanvas(ButtonBehavior, StackLayout): orientation='horizontal', height=self.widgets_height, size_hint=self.widgets_size_hint, - spacing=self.spacing[0] + spacing=self._canvas.spacing[0] ) def export_to_kv(self, widget, indent=''):