Package muntjac :: Package addon :: Package csstools :: Module test_application
[hide private]
[frames] | no frames]

Source Code for Module muntjac.addon.csstools.test_application

 1   
 2  from muntjac.api \ 
 3      import Application, Window, Label, NativeSelect, Button, GridLayout 
 4   
 5  from muntjac.ui.themes.reindeer \ 
 6      import Reindeer 
 7   
 8  from muntjac.ui.button \ 
 9      import IClickListener 
10   
11  from muntjac.addon.csstools.render_info \ 
12      import RenderInfo, ICallback 
13   
14  from muntjac.addon.csstools.client.v_render_info_fetcher \ 
15      import CssProperty 
16   
17   
18 -class CssToolsTestApplication(Application):
19
20 - def __init__(self):
21 Application.__init__(self) 22 23 self._props = dict()
24 25
26 - def init(self):
27 main = Window('CSS Tools Add-on Test') 28 self.setMainWindow(main) 29 30 testWindow = Window('Normal Window') 31 testWindow.addComponent(Label( 32 "<p>This window is used as the component to measure.</p>", 33 Label.CONTENT_XHTML)) 34 main.addWindow(testWindow) 35 testWindow.center() 36 37 title = Label('CSS Properties to Retrieve') 38 title.addStyleName(Reindeer.LABEL_H2) 39 main.addComponent(title) 40 41 target = NativeSelect('Target Component') 42 main.addComponent(target) 43 44 get = Button('Refresh Properties', GetClickListener(self, target)) 45 main.addComponent(get) 46 47 main.addComponent(self.buildLabels()) 48 49 target.addItem(main.getContent()) 50 target.setItemCaption(main.getContent(), 'Root layout') 51 target.addItem(testWindow) 52 target.setItemCaption(testWindow, 'Sub window') 53 target.addItem(get) 54 target.setItemCaption(get, 'The \'' + get.getCaption() + '\' Button') 55 target.setNullSelectionAllowed(False) 56 target.select(testWindow)
57 58
59 - def buildLabels(self):
60 grid = GridLayout() 61 grid.setSpacing(True) 62 grid.setWidth('100%') 63 grid.setColumns(6) 64 for prop in CssProperty.values(): 65 l = Label('-') 66 l.setSizeUndefined() 67 l.setCaption(str(prop)) 68 self._props[prop] = l 69 grid.addComponent(l) 70 return grid
71 72
73 -class GetClickListener(IClickListener):
74
75 - def __init__(self, app, target):
76 self._app = app 77 self._target = target
78
79 - def buttonClick(self, event):
80 RenderInfo.get(self._target.getValue(), GetCallback(self._app))
81 82
83 -class GetCallback(ICallback):
84
85 - def __init__(self, app):
86 self._app = app
87
88 - def infoReceived(self, info):
89 for prop in CssProperty.values(): 90 self._app._props[prop].setValue(str(info.getProperty(prop)))
91 92 93 if __name__ == '__main__': 94 from muntjac.main import muntjac 95 muntjac(CssToolsTestApplication, nogui=True, forever=True, debug=True, 96 widgetset='org.vaadin.csstools.CssToolsWidgetset') 97