PageRenderTime 132ms CodeModel.GetById 128ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/pyjs/tests/test009.py

http://pyjamas.googlecode.com/
Python | 58 lines | 36 code | 22 blank | 0 comment | 0 complexity | 4b023389d39c58e4b43632534ddc7ade MD5 | raw file
 1import DOM
 2
 3class UIObject:
 4
 5    def getElement(self):
 6        return self.element
 7
 8    def setElement(self, element):
 9        self.element = element
10
11    def setStyleName(self, style):
12        DOM.setAttribute(self.element, "className", style)
13
14
15class Widget(UIObject):
16
17    def setParent(self, parent):
18        self.parent = parent
19
20
21class Panel(Widget):
22    pass
23
24
25class ComplexPanel(Panel):
26
27    def __init__(self):
28        self.children = []
29    
30    def add(self, widget):
31        self.children.append(widget)
32        widget.setParent(self)
33        return True
34
35
36class AbsolutePanel(ComplexPanel):
37
38    def __init__(self):
39        ComplexPanel.__init__(self)
40        self.setElement(DOM.createDiv())
41        DOM.setStyleAttribute(self.getElement(), "overflow", "hidden")
42    
43    def add(self, widget):
44        ComplexPanel.add(self, widget)
45        DOM.appendChild(self.getElement(), widget.getElement())
46        return True
47
48
49class RootPanel(AbsolutePanel):
50
51        
52    def __init__(self):
53        AbsolutePanel.__init__(self)
54        element = self.getBodyElement()
55        self.setElement(element)
56
57    def getBodyElement(self):
58        JS("""    return $doc.body;""")