PageRenderTime 62ms CodeModel.GetById 52ms app.highlight 8ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/addonsgallery/AddonsGallery.py

http://pyjamas.googlecode.com/
Python | 82 lines | 79 code | 3 blank | 0 comment | 1 complexity | c2f95fe56bcb339b7c876f0688706691 MD5 | raw file
 1from ui import Button, RootPanel, HTML, DockPanel, HasAlignment, Hyperlink, VerticalPanel
 2import Window
 3from SinkList import SinkList
 4from History import History
 5import IntroTab
 6import TooltipTab
 7import AutoCompleteTab
 8import CanvasTab
 9
10class AddonsGallery:
11
12    def onHistoryChanged(self, token):
13        info = self.sink_list.find(token)
14        if info:
15            self.show(info, False)
16        else:
17            self.showIntro()
18
19    def onModuleLoad(self):
20        self.curInfo=''
21        self.curSink=None
22        self.description=HTML()
23        self.sink_list=SinkList()
24        self.panel=DockPanel()
25        
26        self.loadSinks()
27        self.sinkContainer = DockPanel()
28        self.sinkContainer.setStyleName("ks-Sink")
29
30        vp=VerticalPanel()
31        vp.setWidth("100%")
32        vp.add(self.description)
33        vp.add(self.sinkContainer)
34
35        self.description.setStyleName("ks-Info")
36
37        self.panel.add(self.sink_list, DockPanel.WEST)
38        self.panel.add(vp, DockPanel.CENTER)
39
40        self.panel.setCellVerticalAlignment(self.sink_list, HasAlignment.ALIGN_TOP)
41        self.panel.setCellWidth(vp, "100%")
42
43        History().addHistoryListener(self)
44        RootPanel().add(self.panel)
45
46        initToken = History().getToken()
47        if len(initToken):
48            self.onHistoryChanged(initToken)
49        else:
50            self.showIntro()
51    
52    def show(self, info, affectHistory):
53        if info == self.curInfo: return
54        self.curInfo = info
55
56        if self.curSink <> None:
57            self.curSink.onHide()
58            self.sinkContainer.remove(self.curSink)
59
60        self.curSink = info.getInstance()
61        self.sink_list.setSinkSelection(info.getName())
62        self.description.setHTML(info.getDescription())
63
64        if (affectHistory):
65            History().newItem(info.getName())
66
67        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
68        self.sinkContainer.setCellWidth(self.curSink, "100%")
69        self.sinkContainer.setCellHeight(self.curSink, "100%")
70        self.sinkContainer.setCellVerticalAlignment(self.curSink, HasAlignment.ALIGN_TOP)
71        self.curSink.onShow()
72        
73    def loadSinks(self):
74        self.sink_list.addSink(IntroTab.init())
75        self.sink_list.addSink(TooltipTab.init())
76        self.sink_list.addSink(AutoCompleteTab.init())
77        self.sink_list.addSink(CanvasTab.init())
78
79    def showIntro(self):
80        self.show(self.sink_list.find("Intro"))
81
82