Make Container.layout a property.
--- a/demo_checkbox.py Sat Dec 29 12:16:06 2012 +0100
+++ b/demo_checkbox.py Sun Dec 30 13:03:29 2012 +0100
@@ -12,8 +12,7 @@
Application.__init__(self)
self.top.connect('keypress', self.on_top_keypress)
- vert = VerticalLayout(homogeneous=False)
- self.top.layout(vert)
+ self.top.layout = VerticalLayout(homogeneous=False)
combo = ComboBox(items=['abc', 'xyz'])
self.top.add(combo)
--- a/demo_layout.py Sat Dec 29 12:16:06 2012 +0100
+++ b/demo_layout.py Sun Dec 30 13:03:29 2012 +0100
@@ -14,8 +14,7 @@
#self.top.borders = (1,1,1,1)
- vert = VerticalLayout(homogeneous=False)
- self.top.layout(vert)
+ self.top.layout = VerticalLayout(homogeneous=False)
self.buildrow()
self.buildrow(expand=True)
@@ -26,10 +25,9 @@
self.buildrow(homogeneous=True, fill=True, spacing=2)
def buildrow(self, homogeneous=False, spacing=0, expand=False, fill=False):
- horz = HorizontalLayout(homogeneous=homogeneous, spacing=spacing)
hbox1 = Container()
hbox1.sizereq.h = 2
- hbox1.layout(horz)
+ hbox1.layout = HorizontalLayout(homogeneous=homogeneous, spacing=spacing)
self.top.add(hbox1)
for i in range(5):
btn = Button('Btn' + str(i) * i * i)
--- a/demo_menu.py Sat Dec 29 12:16:06 2012 +0100
+++ b/demo_menu.py Sun Dec 30 13:03:29 2012 +0100
@@ -4,7 +4,7 @@
import locale
locale.setlocale(locale.LC_ALL, '')
-from tuikit import *
+from tuikit import Application, MenuBar, Menu, Window, VerticalLayout
class MyApplication(Application):
@@ -48,8 +48,7 @@
('Help', helpmenu),
])
- vert = VerticalLayout()
- self.top.layout(vert)
+ self.top.layout = VerticalLayout()
#button = Button('click!')
--- a/demo_tableview.py Sat Dec 29 12:16:06 2012 +0100
+++ b/demo_tableview.py Sun Dec 30 13:03:29 2012 +0100
@@ -29,8 +29,7 @@
self.top.add(view, expand=True, fill=True)
- vert = VerticalLayout()
- self.top.layout(vert)
+ self.top.layout = VerticalLayout()
def on_top_keypress(self, ev):
if ev.keyname == 'escape':
--- a/demo_treeview.py Sat Dec 29 12:16:06 2012 +0100
+++ b/demo_treeview.py Sun Dec 30 13:03:29 2012 +0100
@@ -4,7 +4,7 @@
import locale
locale.setlocale(locale.LC_ALL, '')
-from tuikit import *
+from tuikit import Application, TreeView, TreeModel, ScrollView, VerticalLayout
class MyApplication(Application):
@@ -29,8 +29,7 @@
scroll.add(view)
self.top.add(scroll, expand=True, fill=True)
- vert = VerticalLayout()
- self.top.layout(vert)
+ self.top.layout = VerticalLayout()
def on_top_keypress(self, ev):
if ev.keyname == 'escape':
--- a/tuikit/container.py Sat Dec 29 12:16:06 2012 +0100
+++ b/tuikit/container.py Sun Dec 30 13:03:29 2012 +0100
@@ -3,8 +3,6 @@
from tuikit.widget import Widget
from tuikit.common import Borders, Coords
-import logging
-
class Container(Widget):
@@ -48,11 +46,15 @@
if self.focuschild is None and widget.can_focus():
self.focuschild = widget
+ @property
+ def layout(self):
+ return self._layout
- def layout(self, layout):
- '''Set layout manager for placing child widgets.'''
- self._layout = layout
- layout.container = self
+ @layout.setter
+ def layout(self, value):
+ """Layout manager for placing child widgets."""
+ self._layout = value
+ self._layout.container = self
def _set_top(self, value):
@@ -91,21 +93,6 @@
return self.trap_focus or not cycled
idx_new += 1
- def _handle_keypress(self, ev):
- super()._handle_keypress(ev)
- if self.focuschild is not None:
- handled = self.focuschild.emit('keypress', ev)
- if handled:
- return True
- if ev.keyname == 'tab':
- return self.focus_next()
-
- def _handle_resize(self, ev):
- super()._handle_resize(ev)
- for child in self.children:
- child.emit('resize')
-
-
def draw(self, driver, x, y):
"""Draw the container and its children.
@@ -139,6 +126,19 @@
driver.popcolorprefix()
driver.clipstack.pop()
+ def _handle_resize(self, ev):
+ super()._handle_resize(ev)
+ for child in self.children:
+ child.emit('resize')
+
+ def _handle_keypress(self, ev):
+ super()._handle_keypress(ev)
+ if self.focuschild is not None:
+ handled = self.focuschild.emit('keypress', ev)
+ if handled:
+ return True
+ if ev.keyname == 'tab':
+ return self.focus_next()
def _handle_mousedown(self, ev):
super()._handle_mousedown(ev)
--- a/tuikit/pager.py Sat Dec 29 12:16:06 2012 +0100
+++ b/tuikit/pager.py Sun Dec 30 13:03:29 2012 +0100
@@ -24,17 +24,15 @@
# selected child (only one visible)
self.selected = None
- vert = VerticalLayout()
- self.layout(vert)
+ self.layout = VerticalLayout()
self.buttons = Container(20, 1)
self.buttons.sizereq.h = 1
- Container.add(self, self.buttons)
- horz = HorizontalLayout(homogeneous=True, spacing=1)
- self.buttons.layout(horz)
+ self.buttons.layout = HorizontalLayout(homogeneous=True, spacing=1)
+ super().add(self.buttons)
def add(self, widget, **kw):
- Container.add(self, widget, expand=True, fill=True)
+ super().add(widget, expand=True, fill=True)
if self.selected is None:
self.selected = widget