Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.uix.widget import Widget
- from kivy.properties import BoundedNumericProperty, ListProperty
- class SpannableWidget(Widget):
- """Widget with rowspan/colspan attributes able to span across rows/cols"""
- rowspan = BoundedNumericProperty(1, min=1)
- colspan = BoundedNumericProperty(1, min=1)
- # list of widgets, representing extention by y-axis
- _rowspan = ListProperty([])
- # list of widgets, representing extention by x-axis
- _colspan = ListProperty([])
- def on_parent(self, instance, parent):
- """Clear extention widget lists when widget is inserted/removed
- @param instance: instance, that fired the event
- @param parent: new C{self.parent} value
- """
- for _widget in self._rowspan:
- _widget.unbind(height=self.update, y=self.update)
- self._rowspan = []
- for _widget in self._colspan:
- _widget.unbind(width=self.update, x=self.update)
- self._colspan = []
- def update(self, *largs):
- """Update widget size and position
- @param largs: arguments of the property change event (not used)
- """
- _widget = None
- _height = self.parent.height
- for _widget in self._rowspan:
- _height += _widget.height
- self.height = _height
- if _widget:
- # Stretch widget vertically specifying its y (lower) bound
- self.y = _widget.y
- pass
- self.width = self.parent.width
- for _widget in self._colspan:
- # Stretch widget horizontally increasing its width
- self.width += _widget.width
- # Align widget with parent (C{Placeholder}) by x axis
- self.x = self.parent.x
- class Span(Widget):
- """Widget taking place for rowspan/colspan of other widgets"""
- pass
- class Placeholder(Widget):
- """Widget holding single child
- Represents an empty matrix cell.
- Used to fill C{terminal.layout.Grid.children} list with empty spaces,
- widgets can be inserted into those later.
- """
- def add_widget(self, widget):
- """Insert one child and stub this method"""
- if self.children:
- return
- super(Placeholder, self).add_widget(widget)
- self.bind(
- size=widget.setter("size"),
- pos=widget.setter("pos"))
Advertisement
Add Comment
Please, Sign In to add comment