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
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"
# 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)
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=''):