PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/examples/kitchensink/KitchenSink.py

http://pyjamas.googlecode.com/
Python | 103 lines | 100 code | 3 blank | 0 comment | 1 complexity | 5ae93a510b434fd8f8a7cdc901e4e3f8 MD5 | raw file
  1from ui import Button, RootPanel, HTML, DockPanel, HasAlignment, Hyperlink, VerticalPanel
  2import Window
  3from SinkList import SinkList
  4from History import History
  5import Info
  6import Buttons
  7import Layouts
  8import Images
  9import Menus
 10import Lists
 11import Popups
 12import Tables
 13import Text
 14import Trees
 15import Frames
 16import Tabs
 17from Logger import Logger
 18
 19class KitchenSink:
 20
 21    def onHistoryChanged(self, token):
 22        info = self.sink_list.find(token)
 23        if info:
 24            self.show(info, False)
 25        else:
 26            self.showInfo()
 27
 28    def onModuleLoad(self):
 29        self.curInfo=''
 30        self.curSink=None
 31        self.description=HTML()
 32        self.sink_list=SinkList()
 33        self.panel=DockPanel()
 34        
 35        self.loadSinks()
 36        self.sinkContainer = DockPanel()
 37        self.sinkContainer.setStyleName("ks-Sink")
 38
 39        vp=VerticalPanel()
 40        vp.setWidth("100%")
 41        vp.add(self.description)
 42        vp.add(self.sinkContainer)
 43
 44        self.description.setStyleName("ks-Info")
 45
 46        self.panel.add(self.sink_list, DockPanel.WEST)
 47        self.panel.add(vp, DockPanel.CENTER)
 48
 49        self.panel.setCellVerticalAlignment(self.sink_list, HasAlignment.ALIGN_TOP)
 50        self.panel.setCellWidth(vp, "100%")
 51
 52        History().addHistoryListener(self)
 53        RootPanel().add(self.panel)
 54        RootPanel().add(Logger())
 55
 56        #Show the initial screen.
 57        initToken = History().getToken()
 58        if len(initToken):
 59            self.onHistoryChanged(initToken)
 60        else:
 61            self.showInfo()
 62
 63    def show(self, info, affectHistory):
 64        if info == self.curInfo: return
 65        self.curInfo = info
 66
 67        Logger.write("showing " + info.getName())
 68        if self.curSink <> None:
 69            self.curSink.onHide()
 70            Logger.write("removing " + self.curSink)
 71            self.sinkContainer.remove(self.curSink)
 72
 73        self.curSink = info.getInstance()
 74        self.sink_list.setSinkSelection(info.getName())
 75        self.description.setHTML(info.getDescription())
 76
 77        if (affectHistory):
 78            History().newItem(info.getName())
 79
 80        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
 81        self.sinkContainer.setCellWidth(self.curSink, "100%")
 82        self.sinkContainer.setCellHeight(self.curSink, "100%")
 83        self.sinkContainer.setCellVerticalAlignment(self.curSink, HasAlignment.ALIGN_TOP)
 84        self.curSink.onShow()
 85        
 86    def loadSinks(self):
 87        self.sink_list.addSink(Info.init())
 88        self.sink_list.addSink(Buttons.init())
 89        self.sink_list.addSink(Menus.init())
 90        self.sink_list.addSink(Images.init())
 91        self.sink_list.addSink(Layouts.init())
 92        self.sink_list.addSink(Lists.init())
 93        self.sink_list.addSink(Popups.init())
 94        self.sink_list.addSink(Tables.init())
 95        self.sink_list.addSink(Text.init())
 96        self.sink_list.addSink(Trees.init())
 97        self.sink_list.addSink(Frames.init())
 98        self.sink_list.addSink(Tabs.init())
 99
100    def showInfo(self):
101        self.show(self.sink_list.find("Info"), False)
102
103