Package muntjac :: Package addon :: Package weelayout :: Module wee_layout_application
[hide private]
[frames] | no frames]

Source Code for Module muntjac.addon.weelayout.wee_layout_application

  1   
  2  from muntjac.api \ 
  3      import Application, Window, VerticalLayout, HorizontalLayout, \ 
  4      NativeButton, TextField, Alignment, Label 
  5   
  6  from muntjac.ui.button \ 
  7      import IClickListener 
  8   
  9  from muntjac.addon.weelayout.wee_layout \ 
 10      import WeeLayout, Direction 
 11   
 12   
13 -class WeelayoutApplication(Application):
14
15 - def __init__(self):
16 super(WeelayoutApplication, self).__init__() 17 18 self._core = False 19 self._vertical = False
20 21
22 - def init(self):
23 mainWindow = Window('Weelayout Application') 24 self.setMainWindow(mainWindow) 25 26 # mainWindow.setContent(self.splitRecursive(2)) 27 # mainWindow.setContent(self.undefinedWithRelativeSizes()) 28 # mainWindow.setContent(self.splitView()) 29 # mainWindow.setContent(self.createVertical(2)) 30 # mainWindow.setContent(self.createCoreVertical(2)) 31 # mainWindow.setContent(self.createHorizontal(2)) 32 mainWindow.setContent(self.createCoreHorizontal(2)) 33 34 self.setTheme('test')
35 36
37 - def splitRecursive(self, deep):
38 l = None 39 if self._core: 40 l = VerticalLayout() if self._vertical else HorizontalLayout() 41 else: 42 if self._vertical: 43 l = WeeLayout(Direction.VERTICAL) 44 else: 45 l = WeeLayout(Direction.HORIZONTAL) 46 47 l.setSizeFull() 48 if self._core: 49 c = l 50 b = NativeButton('One') 51 b.setSizeFull() 52 c.addComponent(b) 53 c.setExpandRatio(b, 1) 54 if deep > 0: 55 deep -= 1 56 c2 = self.splitRecursive(deep) 57 c.addComponent(c2) 58 c.setExpandRatio(c2, 9) 59 else: 60 wl = l 61 wl.setClipping(True) 62 b = NativeButton('Button') 63 b.setSizeFull() 64 if self._vertical: 65 b.setHeight('10%') 66 else: 67 b.setWidth('10%') 68 69 l.addComponent(b) 70 if deep > 0: 71 deep -= 1 72 w = self.splitRecursive(deep) 73 if self._vertical: 74 w.setHeight('90%') 75 else: 76 w.setWidth('90%') 77 78 l.addComponent(w) 79 else: 80 b.setSizeFull() 81 82 return l
83 84
86 wl = WeeLayout(Direction.VERTICAL) 87 wl.setHeight('100%') 88 89 wlong = NativeButton('With long caption', LongClickListener()) 90 wl.addComponent(wlong, '100%', '30px', Alignment.TOP_LEFT) 91 92 b = NativeButton('Two') 93 b.addStyleName('test') 94 wl.addComponent(b, '100%', '100%', Alignment.TOP_LEFT) 95 wl.setSmartRelativeSizes(True) 96 return wl
97 98
99 - def splitView(self):
100 wl = WeeLayout(Direction.HORIZONTAL) 101 wl.setSizeFull() 102 103 one = NativeButton('One', OneClickListener()) 104 wl.addComponent(one, '100px', '30px', Alignment.TOP_RIGHT) 105 106 wl.addComponent(Label(''), '14px', '14px', Alignment.TOP_CENTER) 107 wl.addComponent(NativeButton('Two'), '100%', '100%', 108 Alignment.TOP_CENTER) 109 # wl.setClipping(true) 110 111 return wl
112 113
114 - def createVertical(self, recurse):
115 wl = WeeLayout(Direction.VERTICAL) 116 wl.setSizeFull() 117 # wl.setWidth("100%") 118 # wl.setHeight("50%") 119 wl.addComponent(TextField('Left'), Alignment.TOP_LEFT) 120 wl.addComponent(TextField('Center'), Alignment.TOP_CENTER) 121 tf = TextField('Right') 122 tf.setWidth('50%') 123 wl.addComponent(tf, Alignment.TOP_RIGHT) 124 if recurse > 0: 125 recurse -= 1 126 wl.addComponent(self.createHorizontal(recurse)) 127 return wl
128 129
130 - def createHorizontal(self, recurse):
131 wl = WeeLayout(Direction.HORIZONTAL) 132 wl.setSizeFull() 133 # wl.setHeight("100%"); 134 wl.addComponent(TextField('Top'), Alignment.TOP_LEFT) 135 wl.addComponent(TextField('Middle'), Alignment.MIDDLE_LEFT) 136 tf = TextField('Bottom') 137 tf.setHeight('50%') 138 wl.addComponent(tf, Alignment.BOTTOM_LEFT) 139 if recurse > 0: 140 recurse -= 1 141 wl.addComponent(self.createVertical(recurse)) 142 return wl
143 144
145 - def createCoreVertical(self, recurse):
146 """Same with core layouts""" 147 l = VerticalLayout() 148 l.setSizeFull() 149 tf = TextField('Left') 150 l.addComponent(tf) 151 l.setComponentAlignment(tf, Alignment.TOP_LEFT) 152 tf = TextField('Center') 153 l.addComponent(tf) 154 l.setComponentAlignment(tf, Alignment.TOP_CENTER) 155 tf = TextField('Right') 156 l.addComponent(tf) 157 tf.setWidth('50%') 158 l.setComponentAlignment(tf, Alignment.TOP_RIGHT) 159 if recurse > 0: 160 recurse -= 1 161 createCoreHorizontal = self.createCoreHorizontal(recurse) 162 l.addComponent(createCoreHorizontal) 163 l.setExpandRatio(createCoreHorizontal, 1) 164 return l
165 166
167 - def createCoreHorizontal(self, recurse):
168 l = HorizontalLayout() 169 l.setSizeFull() 170 tf = TextField('Top') 171 l.addComponent(tf) 172 l.setComponentAlignment(tf, Alignment.TOP_LEFT) 173 tf = TextField('Middle') 174 l.addComponent(tf) 175 l.setComponentAlignment(tf, Alignment.MIDDLE_LEFT) 176 tf = TextField('Bottom') 177 l.addComponent(tf) 178 tf.setWidth('50%') 179 l.setComponentAlignment(tf, Alignment.BOTTOM_LEFT) 180 if recurse > 0: 181 recurse -= 1 182 createCoreVertical = self.createCoreVertical(recurse) 183 l.addComponent(createCoreVertical) 184 l.setExpandRatio(createCoreVertical, 1) 185 return l
186 187
188 -class LongClickListener(IClickListener):
189
190 - def buttonClick(self, event):
191 if event.getButton().getCaption() is None: 192 event.getButton().setCaption('Long caption') 193 else: 194 event.getButton().setCaption(None)
195 196
197 -class OneClickListener(IClickListener):
198
199 - def buttonClick(self, event):
200 event.getButton().setWidth('300px')
201 202 203 if __name__ == '__main__': 204 from muntjac.main import muntjac 205 muntjac(WeelayoutApplication, nogui=True, forever=True, debug=True) 206