Add Pager.
--- a/.hgignore Mon Sep 12 13:30:31 2011 +0200
+++ b/.hgignore Sun Oct 02 23:32:35 2011 +0200
@@ -1,3 +1,4 @@
.*~
tuikit/.*\.pyc
docs/_build
+tuikit\.log
--- a/tuikit/__init__.py Mon Sep 12 13:30:31 2011 +0200
+++ b/tuikit/__init__.py Sun Oct 02 23:32:35 2011 +0200
@@ -11,6 +11,7 @@
from tuikit.layout import VerticalLayout, HorizontalLayout, GridLayout
from tuikit.menu import Menu
from tuikit.menubar import MenuBar
+from tuikit.pager import Pager
from tuikit.scrollbar import VScrollbar
from tuikit.textedit import TextEdit
from tuikit.treeview import TreeNode, TreeModel, TreeView
--- a/tuikit/application.py Mon Sep 12 13:30:31 2011 +0200
+++ b/tuikit/application.py Sun Oct 02 23:32:35 2011 +0200
@@ -89,10 +89,10 @@
self.log = logging.getLogger('tuikit')
self.log.setLevel(logging.DEBUG)
handler = logging.FileHandler('./tuikit.log')
- format = logging.Formatter('%(asctime)s %(levelname)-5s %(message)s', '%y-%m-%d %H:%M:%S')
- handler.setFormatter(format)
+ formatter = logging.Formatter('%(asctime)s %(levelname)-5s %(message)s', '%y-%m-%d %H:%M:%S')
+ handler.setFormatter(formatter)
self.log.addHandler(handler)
- self.log.info('start')
+ self.log.info('=== start ===')
def start(self):
--- a/tuikit/container.py Mon Sep 12 13:30:31 2011 +0200
+++ b/tuikit/container.py Sun Oct 02 23:32:35 2011 +0200
@@ -21,6 +21,8 @@
#: Child widgets are placed within borders.
self.borders = (0, 0, 0, 0)
+ self._layout = None
+
self.widthrequest = (None, None)
self.heightrequest = (None, None)
@@ -34,12 +36,12 @@
self.children.append(widget)
widget.parent = self
widget.settop(self.top)
- widget.layouthints.update(kw)
+ widget.hints.update(kw)
def layout(self, layout):
'''Set layout manager for placing child widgets.'''
- self.layout = layout
+ self._layout = layout
layout.container = self
self.connect('resize', layout.resize)
--- a/tuikit/layout.py Mon Sep 12 13:30:31 2011 +0200
+++ b/tuikit/layout.py Sun Oct 02 23:32:35 2011 +0200
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
+import logging
+
from .common import Rect
+
class Layout:
def _getchildren(self):
- return [child for child in self.container.children if child.allowlayout]
-
+ return [child for child in self.container.children
+ if child.allowlayout and not child.hidden]
def _getregion(self):
c = self.container
@@ -13,22 +16,25 @@
return Rect(bl, bt, c.width - bl - br, c.height - bt - bb)
-class VerticalLayout:
+class VerticalLayout(Layout):
def resize(self):
+ log = logging.getLogger('tuikit')
+ log.debug('VerticalLayout: resize %d children', len(self._getchildren()))
+
v = 0
c = self.container
bl, bt, br, bb = c.borders
last = None
- for child in c.children:
- if not child.allowlayout:
- continue
+ for child in self._getchildren():
child.x = bl
child.width = c.width - bl - br
child.y = bt + v
v += child.height
child.handle('resize')
last = child
+
+ log.debug('VerticalLayout: child %r to y=%d', child, child.y)
if last and v < c.height - bt - bb:
last.height += c.height - bt - bb - v
@@ -36,21 +42,27 @@
c.redraw()
-class HorizontalLayout:
+class HorizontalLayout(Layout):
def resize(self):
+ log = logging.getLogger('tuikit')
+ log.debug('HorizontalLayout: resize')
+
v = 0
c = self.container
bl, bt, br, bb = c.borders
- for child in c.children:
- if not child.allowlayout:
- continue
+ last = None
+ for child in self._getchildren():
child.y = bt
child.height = c.height - bt - bb
child.x = bl + v
v += child.width
child.handle('resize')
-
+ last = child
+
+ if last and v < c.width - bl - br:
+ last.width += c.width - bl - br - v
+
c.redraw()
@@ -71,8 +83,8 @@
row.append({'widget': None, 'colspan': 0, 'rowspan': 0})
colspan = 1
- if 'colspan' in child.layouthints:
- colspan = child.layouthints['colspan']
+ if 'colspan' in child.hints:
+ colspan = child.hints['colspan']
colspan = min(colspan, self.numcols - coln + 1)
row[coln]['widget'] = child
@@ -189,3 +201,4 @@
coly += rowh
cont.redraw()
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tuikit/pager.py Sun Oct 02 23:32:35 2011 +0200
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+
+import logging
+
+from .container import Container
+from .layout import VerticalLayout, HorizontalLayout
+from .button import Button
+
+
+class Pager(Container):
+ '''Only one of children is visible at the time.'''
+ def __init__(self, width=20, height=20):
+ Container.__init__(self, width, height)
+
+ # selected child (only one visible)
+ self.selected = None
+
+ vert = VerticalLayout()
+ self.layout(vert)
+
+ self.buttons = Container(20, 1)
+ Container.add(self, self.buttons)
+ horz = HorizontalLayout()
+ self.buttons.layout(horz)
+
+ def add(self, widget, **kw):
+ Container.add(self, widget, **kw)
+
+ if self.selected is None:
+ self.selected = widget
+ widget.hidden = False
+ else:
+ widget.hidden = True
+
+ btn = Button(kw['title'])
+ btn.connect('click', lambda: self.select(widget))
+ self.buttons.add(btn)
+
+ def select(self, child):
+ log = logging.getLogger('tuikit')
+ log.debug('Pager: select %r', child)
+
+ self.selected.hidden = True
+ child.hidden = False
+ self.selected = child
+
+ self.resize()
+
--- a/tuikit/widget.py Mon Sep 12 13:30:31 2011 +0200
+++ b/tuikit/widget.py Sun Oct 02 23:32:35 2011 +0200
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
+import logging
+
from .eventsource import EventSource
@@ -41,8 +43,8 @@
#: When false, the widget is not considered in layout.
self.allowlayout = True
- #: Dictionary containing optional parameters for layout managers.
- self.layouthints = {}
+ #: Dictionary containing optional parameters for layout managers etc.
+ self.hints = {}
#: Hidden widget does not affect layout.
self.hidden = False
@@ -93,6 +95,8 @@
def resize(self):
+ log = logging.getLogger('tuikit')
+ log.debug('%r: resize', self)
self.handle('resize')