ARGH
[matches/honours.git] / research / transmission_spectroscopy / simulator / pgu-0.18 / pgu / gui / document.py
1 """
2 """
3 import pygame
4
5 from . import container
6 from . import layout
7
8 class _document_widget:
9     def __init__(self,w,align=None):
10         #w.rect.w,w.rect.h = w.resize()
11         #self.rect = w.rect
12         self.widget = w
13         if align != None: self.align = align
14
15 class Document(container.Container):
16     """A document is a container that structures widgets in a left-to-right flow."""
17
18     def __init__(self,**params):
19         params.setdefault('cls','document')
20         container.Container.__init__(self,**params)
21         self.layout =  layout.Layout(pygame.Rect(0,0,self.rect.w,self.rect.h))
22     
23     def add(self,e,align=None):
24         """Add a widget to the document flow.
25
26         Arguments:
27             e -- widget
28             align -- alignment (None,-1,0,1)
29
30         """
31         dw = _document_widget(e,align)
32         self.layout.add(dw)
33         e.container = self
34         e._c_dw = dw
35         self.widgets.append(e)
36         self.chsize()
37         
38     def remove(self,e):
39         self.layout._widgets.remove(e._c_dw)
40         self.widgets.remove(e)
41         self.chsize()
42         
43     
44     def block(self,align):
45         """Start a new block given the alignment (-1, 0, 1)"""
46         self.layout.add(align)
47     
48     def space(self, size):
49         """Add a spacer given the size."""
50         self.layout.add(size)
51     
52     def br(self,height):
53         """Add a line break, given the height."""
54         self.layout.add((0, height))
55     
56     def resize(self,width=None,height=None):
57         if self.style.width: width = self.style.width
58         if self.style.height: height = self.style.height
59         
60         for w in self.widgets:
61             w.rect.w,w.rect.h = w.resize()
62             
63             if (width != None and w.rect.w > width) or (height != None and w.rect.h > height):
64                 w.rect.w,w.rect.h = w.resize(width,height)
65             
66             dw = w._c_dw
67             dw.rect = pygame.Rect(0,0,w.rect.w,w.rect.h)
68         
69         if width == None: width = 65535
70         self.layout.rect = pygame.Rect(0,0,width,0)
71         self.layout.resize()
72         
73         _max_w = 0
74         
75         for w in self.widgets:
76             #xt,xl,xb,xr = w.getspacing()
77             dw = w._c_dw
78             w.style.x,w.style.y,w.rect.w,w.rect.h = dw.rect.x,dw.rect.y,dw.rect.w,dw.rect.h
79             #w.resize()
80             w.rect.x,w.rect.y = w.style.x,w.style.y
81             _max_w = max(_max_w,w.rect.right)
82         
83         #self.rect.w = _max_w #self.layout.rect.w
84         #self.rect.h = self.layout.rect.h
85         #print 'document',_max_w,self.layout.rect.h
86         return _max_w,self.layout.rect.h
87

UCC git Repository :: git.ucc.asn.au