Exemplo n.º 1
0
class DockPanelTest(UnitTest1):

    def testDockAdd(self):
        self.d = DockPanel()
        RootPanel('tests').add(self.d)
        self.write_test_output('adddockpanel')

        if not RootPanel('tests').remove(self.d):
            self.fail("DockPanel added but apparently not owned by RootPanel()")
        self.write_test_output('removedockpanel')

    def testDockAddCentre(self):
        self.d = DockPanel()
        RootPanel('tests').add(self.d)
        l = Label("Hello World (label)", StyleName='teststyle')
        self.d.add(l, DockPanel.CENTER)
        self.write_test_output('addcentrelabel')

        self.d.remove(l)
        self.write_test_output('removecentrelabel')

        l2 = Label("Hello World 2 (label)", StyleName='teststyle')

        self.d.add(l2, DockPanel.CENTER)
        self.write_test_output('addcentrelabel2')

        if not RootPanel('tests').remove(self.d):
            self.fail("DockPanel added but apparently not owned by RootPanel()")
        self.write_test_output('removedock')
Exemplo n.º 2
0
class DockPanelTest(UnitTest1):
    def testDockAdd(self):
        self.d = DockPanel()
        RootPanel('tests').add(self.d)
        self.write_test_output('adddockpanel')

        if not RootPanel('tests').remove(self.d):
            self.fail(
                "DockPanel added but apparently not owned by RootPanel()")
        self.write_test_output('removedockpanel')

    def testDockAddCentre(self):
        self.d = DockPanel()
        RootPanel('tests').add(self.d)
        l = Label("Hello World (label)", StyleName='teststyle')
        self.d.add(l, DockPanel.CENTER)
        self.write_test_output('addcentrelabel')

        self.d.remove(l)
        self.write_test_output('removecentrelabel')

        l2 = Label("Hello World 2 (label)", StyleName='teststyle')

        self.d.add(l2, DockPanel.CENTER)
        self.write_test_output('addcentrelabel2')

        if not RootPanel('tests').remove(self.d):
            self.fail(
                "DockPanel added but apparently not owned by RootPanel()")
        self.write_test_output('removedock')
Exemplo n.º 3
0
class WebApp:
    def onModuleLoad(self):

        self.remote = DataService()

        #Show the initial screen.
        initToken = History.getToken()
        if initToken and len(initToken):
            if initToken == 'admin':
                RootPanel().add(WebPageEdit(self))
                return
        else:
            initToken = 'index'

        self.dock = DockPanel()
        self.dock.setWidth("100%")
        self.pages = {}
        self.current_page = None
        RootPanel().add(self.dock)

        History.addHistoryListener(self)
        self.onHistoryChanged(initToken)

    def createPage(self, ref, html, title):
        htp = HTMLLinkPanel(html)
        htp.replaceLinks()
        htp.setWidth("100%")
        self.pages[ref] = htp

    def onHistoryChanged(self, token):
        #log.writebr("onHistoryChanged %s" % token)
        if self.pages.has_key(token):
            self.setPage(token)
            return
        self.remote.getPageByName(token, self)

    def setPage(self, ref):

        htp = self.pages[ref]
        if htp == self.current_page:
            return
        Window.setTitle(htp.title)
        if self.current_page:
            self.dock.remove(self.current_page)
        self.dock.add(htp, DockPanel.CENTER)
        self.current_page = htp

    def onRemoteResponse(self, response, request_info):
        if (request_info.method == 'getPageByName'
                or request_info.method == 'getPage'):
            item = response[0]
            html = item['fields']['text']
            token = item['fields']['name']
            self.createPage(token, html, token)
            self.setPage(token)

    def onRemoteError(self, code, message, request_info):
        RootPanel().add(
            HTML("Server Error or Invalid Response: ERROR " + str(code) +
                 " - " + str(message)))
Exemplo n.º 4
0
Arquivo: WebPage.py Projeto: Afey/pyjs
class WebApp:
    def onModuleLoad(self):

        self.remote = DataService()

        #Show the initial screen.
        initToken = History.getToken()
        if initToken and len(initToken):
            if initToken == 'admin':
                RootPanel().add(WebPageEdit(self))
                return
        else:
            initToken = 'index'

        self.dock = DockPanel()
        self.dock.setWidth("100%")
        self.pages = {}
        self.current_page = None
        RootPanel().add(self.dock)

        History.addHistoryListener(self)
        self.onHistoryChanged(initToken)

    def createPage(self, ref, html, title):
        htp = HTMLLinkPanel(html)
        htp.replaceLinks()
        htp.setWidth("100%")
        self.pages[ref] = htp

    def onHistoryChanged(self, token):
        #log.debug("onHistoryChanged %s" % token)
        if self.pages.has_key(token):
            self.setPage(token)
            return
        self.remote.getPageByName(token, self)

    def setPage(self, ref):

        htp = self.pages[ref]
        if htp == self.current_page:
            return
        Window.setTitle(htp.title)
        if self.current_page:
            self.dock.remove(self.current_page)
        self.dock.add(htp, DockPanel.CENTER)
        self.current_page = htp

    def onRemoteResponse(self, response, request_info):
        if (request_info.method == 'getPageByName' or
           request_info.method == 'getPage'):
            item = response[0]
            html = item['fields']['text']
            token = item['fields']['name']
            self.createPage(token, html, token)
            self.setPage(token)

    def onRemoteError(self, code, message, request_info):
        RootPanel().add(HTML("Server Error or Invalid Response: ERROR " + str(code) + " - " + str(message)))
Exemplo n.º 5
0
class gmTopLevelLayer:
    
    def onModuleLoad(self):

        GMWevents.init_events()
        GMWevents.events.addLoginListener(self) # want to receive onLogin

        self.TEXT_ERROR = "Server Error"
        self.loginpanel = cLoginPanel() # fires logged out on UI load
        self.afterloginpanel = cMainPanel()

        self.maindisplay = DockPanel(
                          HorizontalAlignment=HasAlignment.ALIGN_CENTER,
                          VerticalAlignment=HasAlignment.ALIGN_MIDDLE,
                          BorderWidth=1,
                          Padding=8,
                          Width="100%") 

        RootPanel().add(self.maindisplay)

    def onLogin(self, sender, username, logged_in):
        if logged_in:
            self.logged_in(username)
        else:
            self.logged_out()

    def logged_out(self):
        self.login_username = None
        self.loginpanel.setStatus("") # reset status display
        if self.maindisplay.center is not None:
            self.maindisplay.remove(self.afterloginpanel.getPanel())
        self.maindisplay.add(self.loginpanel.getPanel(), DockPanel.CENTER)

    def logged_in(self, username):
        self.login_username = username
        if self.maindisplay.center is not None:
            self.maindisplay.remove(self.loginpanel.getPanel())
        self.maindisplay.add(self.afterloginpanel.getPanel(), DockPanel.CENTER)
Exemplo n.º 6
0
class AddonsGallery:
    def onHistoryChanged(self, token):
        info = self.sink_list.find(token)
        if info:
            self.show(info, False)
        else:
            self.showIntro()

    def onModuleLoad(self):
        self.curInfo = ''
        self.curSink = None
        self.description = HTML()
        self.sink_list = SinkList()
        self.panel = DockPanel()

        self.loadSinks()
        self.sinkContainer = DockPanel()
        self.sinkContainer.setStyleName("ks-Sink")

        vp = VerticalPanel()
        vp.setWidth("100%")
        vp.add(self.description)
        vp.add(self.sinkContainer)

        self.description.setStyleName("ks-Info")

        self.panel.add(self.sink_list, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.sink_list,
                                            HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")

        History.addHistoryListener(self)
        RootPanel().add(self.panel)

        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showIntro()

    def show(self, info, affectHistory=None):
        if info == self.curInfo: return
        self.curInfo = info

        if self.curSink <> None:
            self.curSink.onHide()
            self.sinkContainer.remove(self.curSink)

        self.curSink = info.getInstance()
        self.sink_list.setSinkSelection(info.getName())
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History.newItem(info.getName())

        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
        self.sinkContainer.setCellWidth(self.curSink, "100%")
        self.sinkContainer.setCellHeight(self.curSink, "100%")
        self.sinkContainer.setCellVerticalAlignment(self.curSink,
                                                    HasAlignment.ALIGN_TOP)
        self.curSink.onShow()

    def loadSinks(self):
        self.sink_list.addSink(IntroTab.init())
        self.sink_list.addSink(TooltipTab.init())
        self.sink_list.addSink(AutoCompleteTab.init())
        self.sink_list.addSink(CanvasTab.init())

    def showIntro(self):
        self.show(self.sink_list.find("Intro"))
Exemplo n.º 7
0
class MLAlgorithms:
    def onHistoryChanged(self, token):
        log.writebr("onHistoryChanged: %s" % token)
        info = self.Algorithm_list.find(token)
        if info is not None:
            self.show(info, False)
        else:
            self.showInfo()

    def onModuleLoad(self):
        self.curInfo = ''
        self.curAlgorithm = None
        self.description = HTML()
        self.Algorithm_list = AlgorithmList()
        self.panel = DockPanel()

        self.loadAlgorithms()
        self.AlgorithmContainer = DockPanel()
        self.AlgorithmContainer.setStyleName("ks-Algorithm")

        vp = VerticalPanel()
        vp.setWidth("100%")
        vp.add(self.description)
        vp.add(self.AlgorithmContainer)

        self.description.setStyleName("ks-Info")

        self.panel.add(self.Algorithm_list, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.Algorithm_list,
                                            HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")

        History.addHistoryListener(self)
        RootPanel().add(self.panel)
        RootPanel().add(Logger())

        #Show the initial screen.
        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showInfo()

    def show(self, info, affectHistory):
        if info == self.curInfo: return
        self.curInfo = info

        log.writebr("showing " + info.getName())
        if self.curAlgorithm is not None:
            log.writebr("removing " + str(self.curAlgorithm))
            self.curAlgorithm.onHide()
            self.AlgorithmContainer.remove(self.curAlgorithm)

        self.curAlgorithm = info.getInstance()
        self.Algorithm_list.setAlgorithmSelection(info.getName())
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History.newItem(info.getName())

        self.AlgorithmContainer.add(self.curAlgorithm, DockPanel.CENTER)
        self.AlgorithmContainer.setCellWidth(self.curAlgorithm, "100%")
        self.AlgorithmContainer.setCellHeight(self.curAlgorithm, "100%")
        self.AlgorithmContainer.setCellVerticalAlignment(
            self.curAlgorithm, HasAlignment.ALIGN_TOP)
        self.curAlgorithm.onShow()

    def loadAlgorithms(self):
        self.Algorithm_list.addAlgorithm(Info.init())
        self.Algorithm_list.addAlgorithm(kMeans.init())

    def showInfo(self):
        self.show(self.Algorithm_list.find("Info"), False)
Exemplo n.º 8
0
class Bookreader:
    def onHistoryChanged(self, token):
        info = self.sink_list.find(token)
        if info:
            self.show(info, False)
        else:
            self.showInfo()

    def onModuleLoad(self):
        section = Window.getLocation().getSearchVar("section")
        if not section:
            self.loadChapters()
        else:
            loadSection(section)

    def loadChapters(self):

        self.curInfo = ''
        self.curSink = None
        self.description = HTML()
        self.sink_list = SinkList()
        self.panel = DockPanel()

        self.loadSinks()
        self.sinkContainer = DockPanel()
        self.sinkContainer.setStyleName("ks-Sink")

        #self.nf = NamedFrame("section")
        #self.nf.setWidth("100%")
        #self.nf.setHeight("10000")

        height = Window.getClientHeight()

        self.sp = ScrollPanel(self.sinkContainer)
        #self.sp = VerticalSplitPanel()
        self.sp.setWidth("100%")
        self.sp.setHeight("%dpx" % (height - 110))

        #self.sp.setTopWidget(self.sinkContainer)
        #self.sp.setBottomWidget(self.nf)
        #self.sp.setSplitPosition(10000) # deliberately high - max out.

        vp = VerticalPanel()
        vp.setWidth("100%")
        vp.setHeight("100%")
        vp.add(self.description)
        vp.add(self.sp)

        self.description.setStyleName("ks-Intro")

        self.panel.add(self.sink_list, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.sink_list,
                                            HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")
        self.panel.setCellHeight(vp, "100%")

        Window.addWindowResizeListener(self)

        History.addHistoryListener(self)
        RootPanel().add(self.panel)

    def onWindowResized(self, width, height):
        self.sink_list.resize(width, height)
        self.sp.setHeight("%dpx" % (height - 110))

    def show(self, info, affectHistory):
        if info == self.curInfo:
            return
        self.curInfo = info

        #Logger.write("showing " + info.getName())
        if self.curSink is not None:
            self.curSink.onHide()
            #Logger.write("removing " + self.curSink)
            self.sinkContainer.remove(self.curSink)

        self.curSink = info.getInstance()
        self.sink_list.setSinkSelection(info.getName())
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History().newItem(info.getName())

        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
        self.sinkContainer.setCellWidth(self.curSink, "100%")
        self.sinkContainer.setCellHeight(self.curSink, "100%")
        self.sinkContainer.setCellVerticalAlignment(self.curSink,
                                                    HasAlignment.ALIGN_TOP)
        self.curSink.onShow()

    def loadSinks(self):
        HTTPRequest().asyncGet("contents.txt", ChapterListLoader(self))

    def setChapters(self, chapters):
        for l in chapters:
            name = l[0]
            desc = l[1]
            self.sink_list.addSink(Chapter.init(name, desc))

        #Show the initial screen.
        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showInfo()

    def showInfo(self):
        self.show(self.sink_list.sinks[0], False)
Exemplo n.º 9
0
class MLAlgorithms:
    def onHistoryChanged(self, token):
        log.writebr("onHistoryChanged: %s" % token)
        info = self.Algorithm_list.find(token)
        if info is not None:
            self.show(info, False)
        else:
            self.showInfo()

    def onModuleLoad(self):
        self.curInfo=''
        self.curAlgorithm=None
        self.description=HTML()
        self.Algorithm_list=AlgorithmList()
        self.panel=DockPanel()
        
        self.loadAlgorithms()
        self.AlgorithmContainer = DockPanel()
        self.AlgorithmContainer.setStyleName("ks-Algorithm")

        vp=VerticalPanel()
        vp.setWidth("100%")
        vp.add(self.description)
        vp.add(self.AlgorithmContainer)

        self.description.setStyleName("ks-Info")

        self.panel.add(self.Algorithm_list, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.Algorithm_list, HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")

        History.addHistoryListener(self)
        RootPanel().add(self.panel)
        RootPanel().add(Logger())

        #Show the initial screen.
        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showInfo()

    def show(self, info, affectHistory):
        if info == self.curInfo: return
        self.curInfo = info

        log.writebr("showing " + info.getName())
        if self.curAlgorithm is not None:
            log.writebr("removing " + str(self.curAlgorithm))
            self.curAlgorithm.onHide()
            self.AlgorithmContainer.remove(self.curAlgorithm)

        self.curAlgorithm = info.getInstance()
        self.Algorithm_list.setAlgorithmSelection(info.getName())
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History.newItem(info.getName())

        self.AlgorithmContainer.add(self.curAlgorithm, DockPanel.CENTER)
        self.AlgorithmContainer.setCellWidth(self.curAlgorithm, "100%")
        self.AlgorithmContainer.setCellHeight(self.curAlgorithm, "100%")
        self.AlgorithmContainer.setCellVerticalAlignment(self.curAlgorithm, HasAlignment.ALIGN_TOP)
        self.curAlgorithm.onShow()
        
    def loadAlgorithms(self):
        self.Algorithm_list.addAlgorithm(Info.init())
        self.Algorithm_list.addAlgorithm(kMeans.init())

    def showInfo(self):
        self.show(self.Algorithm_list.find("Info"), False)
Exemplo n.º 10
0
class Client:
    def onModuleLoad(self):
        # Window.setTitle("CBC Test Stand")
        StyleSheetCssFile("styleSheet.css")

        self.TEXT_WAITING = "Waiting for response..."
        self.TEXT_ERROR = "Server Error"

        self.status = Label()

        # This is the remote service
        self.I2CPanel = I2CPanel()
        self.SCurveRunPanel = SCurveRunPanel()
        self.OccupancyCheckPanel = OccupancyCheckPanel()
        self.CalibrateChannelTrimsPanel = CalibrateChannelTrimsPanel()

        # mainPanel will have all of the working stuff in it
        self.mainPanel = DockPanel()
        # self.mainPanel.setSpacing(10)
        titleBar = HorizontalPanel()
        titleBar.add(HTML(r"CBC Test Stand (v1.1)", StyleName="titleStyle"))
        self.stopTakingDataButton = Button("Stop taking data")
        self.stopTakingDataButton.addClickListener(self)
        self.dataTakingPercentage = HTML("0%")
        self.dataTakingStatus = HTML("Initiating...")
        titleBar.add(self.dataTakingPercentage)
        titleBar.add(self.dataTakingStatus)
        titleBar.add(self.stopTakingDataButton)
        titleBar.setCellHorizontalAlignment(self.dataTakingStatus, HasHorizontalAlignment.ALIGN_RIGHT)
        titleBar.setCellHorizontalAlignment(self.dataTakingPercentage, HasHorizontalAlignment.ALIGN_RIGHT)
        titleBar.setCellHorizontalAlignment(self.stopTakingDataButton, HasHorizontalAlignment.ALIGN_RIGHT)
        titleBar.setWidth("100%")
        self.mainPanel.add(titleBar, DockPanel.NORTH)
        selectionPanel = VerticalPanel()

        # Register to get updates about the status of data taking, so that
        # I can update the information in the title bar
        self.dataRunManager = DataRunManager.instance()
        self.dataRunManager.registerEventHandler(self)

        self.activePanelButton = None
        self.activePanel = None

        self.registersButton = Label("I2C Registers", StyleName="areaStyle")
        self.occupanciesButton = Label("Test Occupancies", StyleName="areaStyle")
        self.scurveButton = Label("S-Curve Run", StyleName="areaStyle")
        self.calibrateTrimsButton = Label("Calibrate Trims", StyleName="areaStyle")

        self.registersButton.addClickListener(self)
        self.occupanciesButton.addClickListener(self)
        self.scurveButton.addClickListener(self)
        self.calibrateTrimsButton.addClickListener(self)

        selectionPanel.add(self.registersButton)
        selectionPanel.add(self.occupanciesButton)
        selectionPanel.add(self.scurveButton)
        selectionPanel.add(self.calibrateTrimsButton)

        self.mainPanel.add(selectionPanel, DockPanel.WEST)

        self.mainPanel.add(self.status, DockPanel.SOUTH)
        RootPanel().add(self.mainPanel)

        self.setNewMainPanel(self.registersButton)

    def onDataTakingEvent(self, eventCode, details):
        """
		Method that receives updates from DataRunManager
		"""
        if eventCode == DataRunManager.DataTakingStartedEvent:
            self.stopTakingDataButton.setEnabled(True)
            self.dataTakingPercentage.setText("0%")
            self.dataTakingStatus.setText("Starting run...")
        elif eventCode == DataRunManager.DataTakingFinishedEvent:
            self.stopTakingDataButton.setEnabled(False)
            self.dataTakingPercentage.setText("")
            self.dataTakingStatus.setText("Not taking data")
        elif eventCode == DataRunManager.DataTakingStatusEvent:
            self.stopTakingDataButton.setEnabled(True)
            self.dataTakingPercentage.setText("%3d%%" % int(details["fractionComplete"] * 100 + 0.5))
            self.dataTakingStatus.setText(details["statusString"])

    def onClick(self, sender):
        # (data, response_class): if the latter is 'self', then
        # the response is handled by the self.onRemoteResponse() method
        try:
            if sender == self.stopTakingDataButton:
                self.dataRunManager.stopTakingData()
            else:
                # I don't have any other buttons so it must be a panel change
                self.setNewMainPanel(sender)

        except Exception as error:
            self.status.setText("Client exception was thrown: '" + str(error.__class__) + "'='" + str(error) + "'")

    def setNewMainPanel(self, panelButton):
        if panelButton == self.activePanelButton:
            return  # already the active panel so no need to do anything

        # Remove the "selected" style from the current button
        if self.activePanelButton != None:
            self.activePanelButton.setStyleName("areaStyle")

        # Set the "selected" style on the new one
        self.activePanelButton = panelButton
        self.activePanelButton.setStyleName("selectedAreaStyle")

        # Clear the main panel
        if self.activePanel != None:
            self.mainPanel.remove(self.activePanel.getPanel())

            # Figure out what the new main panel should be
        if panelButton == self.registersButton:
            self.activePanel = self.I2CPanel
        elif panelButton == self.scurveButton:
            self.activePanel = self.SCurveRunPanel
        elif panelButton == self.occupanciesButton:
            self.activePanel = self.OccupancyCheckPanel
        elif panelButton == self.calibrateTrimsButton:
            self.activePanel = self.CalibrateChannelTrimsPanel

        # Set the new main panel
        self.activePanel.getPanel().setStyleName("selectedAreaStyle")
        self.activePanel.getPanel().setWidth("100%")
        self.mainPanel.add(self.activePanel.getPanel(), DockPanel.CENTER)

    def onRemoteResponse(self, response, request_info):
        self.status.setText(response)

    def onRemoteError(self, code, message, request_info):
        ErrorMessage("Unable to contact server")
Exemplo n.º 11
0
class Slideshow:
    def onHistoryChanged(self, token):
        info = self.sink_list.find(token)
        if info:
            self.show(info, False)
        else:
            self.showInfo()

    def onModuleLoad(self):
        self.curInfo = ''
        self.curSink = None
        self.description = HTML()
        self.sink_list = SinkList()
        self.panel = DockPanel()
        self.b = Button("load", self)

        self.sinkContainer = DockPanel()
        self.sinkContainer.setStyleName("ks-Sink")

        height = Window.getClientHeight()

        self.sp = ScrollPanel(self.sinkContainer)
        self.sp.setWidth("100%")
        self.sp.setHeight("%dpx" % (height - 110))

        vp = VerticalPanel()
        vp.setWidth("100%")
        vp.setHeight("100%")
        vp.add(self.description)
        vp.add(self.sp)

        self.description.setStyleName("ks-Intro")

        self.panel.add(self.sink_list, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.sink_list,
                                            HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")
        self.panel.setCellHeight(vp, "100%")

        Window.addWindowResizeListener(self)

        History.addHistoryListener(self)
        RootPanel().add(self.panel)
        RootPanel().add(self.b)

        self.loadSinks()

    def onClick(self, sender):
        self.loadSinks()

    def onTimer(self, tid):
        self.loadSinks()

    def onWindowResized(self, width, height):
        self.sink_list.resize(width, height)
        self.sp.setHeight("%dpx" % (height - 110))

    def show(self, info, affectHistory):
        if info == self.curInfo: return
        self.curInfo = info

        #Logger.write("showing " + info.getName())
        if self.curSink <> None:
            self.curSink.onHide()
            #Logger.write("removing " + self.curSink)
            self.sinkContainer.remove(self.curSink)

        self.curSink = info.getInstance()
        self.sink_list.setSinkSelection(info.getName())
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History.newItem(info.getName())

        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
        self.sinkContainer.setCellWidth(self.curSink, "100%")
        self.sinkContainer.setCellHeight(self.curSink, "100%")
        self.sinkContainer.setCellVerticalAlignment(self.curSink,
                                                    HasAlignment.ALIGN_TOP)
        self.curSink.onShow()

    def loadSinks(self):
        HTTPRequest().asyncGet("slides.txt", SlideListLoader(self))

    def setSlides(self, slides):
        for l in slides:
            name = l[0]
            desc = l[1]
            self.sink_list.addSink(Slide.init(name, desc))

        #Show the initial screen.
        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showInfo()

    def showInfo(self):
        self.show(self.sink_list.sinks[0], False)
Exemplo n.º 12
0
class WebApp:
    def onFormLoad(self):
        self.fetch = Button("Retrieve", self)
        self.search = TextBox()
        self.submit = Button("Submit", self)
        self.formsvc = FormService()
        self.wanted = WantedService()
        d = {'price': 20, 'name': 'a good car'}
        self.form = Form(getattr(self.formsvc, "itemform"),
                         data=d,
                         listener=self)
        #self.describe(['name', 'description'])
        RootPanel().add(self.form)
        RootPanel().add(self.search)
        RootPanel().add(self.fetch)

    def onRetrieveDone(self, form):
        log.debug("onRetrieveDone: %s" % repr(form))

    def onDescribeDone(self, form):
        form.add_widget("Submit", self.submit)

    def onClick(self, sender):
        if sender == self.fetch:
            key = self.search.getText()
            if not key:
                log.debug("Please enter id")
                return
            key = int(key)
            log.debug("id %d" % key)
            #self.wanted.getItem(key, self)
            self.form.get(id=key)

        if sender == self.submit:
            v = self.form.getValue()
            log.debug("onClick %s" % repr(v))
            if v.get('id', None):
                self.form.update(v)
            else:
                self.form.save(v)

    def onErrors(self, form, response):
        log.debug("onErrors %s" % repr(response))

    def onSaveDone(self, form, response):
        log.debug("onSave %s" % repr(response))

    def onModuleLoad(self):

        self.pages = DataService()

        #Show the initial screen.
        initToken = History().getToken()
        if initToken and len(initToken):
            if initToken == 'admin':
                RootPanel().add(WebPageEdit(self))
                return
        else:
            initToken = 'index'

        self.dock = DockPanel()
        self.dock.setWidth("100%")
        self.pages = {}
        self.current_page = None
        RootPanel().add(self.dock)

        History.addHistoryListener(self)
        self.onHistoryChanged(initToken)

    def createPage(self, ref, html, title):
        htp = HTMLLinkPanel(self, html, title)
        htp.replaceLinks()
        htp.setWidth("100%")
        self.pages[ref] = htp

    def onHistoryChanged(self, token):
        #log.debug("onHistoryChanged %s" % token)
        if self.pages.has_key(token):
            self.setPage(token)
            return
        self.pages.getPageByName(token, self)

    def setPage(self, ref):

        htp = self.pages[ref]
        if htp == self.current_page:
            return
        Window.setTitle(htp.title)
        if self.current_page:
            self.dock.remove(self.current_page)
        self.dock.add(htp, DockPanel.CENTER)
        self.current_page = htp

    def onRemoteResponse(self, response, request_info):
        #if (request_info.method == 'getItem'):
        #    data = {'id': response['pk']}
        #    log.debug(repr(response))
        #    self.form.update_values(response)

        if (request_info.method == 'getPageByName'
                or request_info.method == 'getPage'):
            item = response[0]
            html = item['fields']['text']
            token = item['fields']['name']
            self.createPage(token, html, token)
            self.setPage(token)

    def onRemoteError(self, code, message, request_info):
        RootPanel().add(
            HTML("Server Error or Invalid Response: ERROR " + str(code) +
                 " - " + str(message)))
Exemplo n.º 13
0
class KitchenSink:
    def onHistoryChanged(self, token):
        log.debug("onHistoryChanged: %s", token)
        info = self.sink_list.find(token)
        if info is not None:
            self.show(info, False)
        else:
            self.showInfo()

    def onModuleLoad(self):
        self.curInfo = ''
        self.curSink = None
        self.description = HTML()
        self.sink_list = SinkList()
        self.panel = DockPanel()

        self.loadSinks()
        self.sinkContainer = DockPanel()
        self.sinkContainer.setStyleName("ks-Sink")

        vp = VerticalPanel()
        vp.setWidth("100%")
        vp.add(self.description)
        vp.add(self.sinkContainer)

        self.description.setStyleName("ks-Info")

        self.panel.add(self.sink_list, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.sink_list,
                                            HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")

        History.addHistoryListener(self)
        RootPanel().add(self.panel)
        RootPanel().add(Logger())

        #Show the initial screen.
        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showInfo()

    def show(self, info, affectHistory):
        if info == self.curInfo: return
        self.curInfo = info

        #log.debug("showing " + info.getName())
        if self.curSink is not None:
            #log.debug("removing " + str(self.curSink))
            self.curSink.onHide()
            self.sinkContainer.remove(self.curSink)

        self.curSink = info.getInstance()
        self.sink_list.setSinkSelection(info.getName())
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History.newItem(info.getName())

        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
        self.sinkContainer.setCellWidth(self.curSink, "100%")
        self.sinkContainer.setCellHeight(self.curSink, "100%")
        self.sinkContainer.setCellVerticalAlignment(self.curSink,
                                                    HasAlignment.ALIGN_TOP)
        self.curSink.onShow()

    def loadSinks(self):
        self.sink_list.add(Info.init())
        self.sink_list.add(Buttons.init())
        self.sink_list.add(Menus.init())
        self.sink_list.add(Images.init())
        self.sink_list.add(Layouts.init())
        self.sink_list.add(Lists.init())
        self.sink_list.add(Popups.init())
        self.sink_list.add(Tables.init())
        self.sink_list.add(Text.init())
        self.sink_list.add(Trees.init())
        self.sink_list.add(Frames.init())
        self.sink_list.add(Tabs.init())

    def showInfo(self):
        self.show(self.sink_list.find("Info"), False)
Exemplo n.º 14
0
class Bookreader:

    def onHistoryChanged(self, token):
        info = self.sink_list.find(token)
        if info:
            self.show(info, False)
        else:
            self.showInfo()

    def onModuleLoad(self):
        section = Window.getLocation().getSearchVar("section")
        if not section:
            self.loadChapters()
        else:
            loadSection(section)

    def loadChapters(self):

        self.curInfo = ''
        self.curSink = None
        self.description = HTML()
        self.sink_list = SinkList()
        self.panel = DockPanel()
        
        self.loadSinks()
        self.sinkContainer = DockPanel()
        self.sinkContainer.setStyleName("ks-Sink")

        #self.nf = NamedFrame("section")
        #self.nf.setWidth("100%")
        #self.nf.setHeight("10000")

        height = Window.getClientHeight()

        self.sp = ScrollPanel(self.sinkContainer)
        #self.sp = VerticalSplitPanel()
        self.sp.setWidth("100%")
        self.sp.setHeight("%dpx" % (height-110))

        #self.sp.setTopWidget(self.sinkContainer)
        #self.sp.setBottomWidget(self.nf)
        #self.sp.setSplitPosition(10000) # deliberately high - max out.

        vp = VerticalPanel()
        vp.setWidth("100%")
        vp.setHeight("100%")
        vp.add(self.description)
        vp.add(self.sp)

        self.description.setStyleName("ks-Intro")

        self.panel.add(self.sink_list, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.sink_list,
                                            HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")
        self.panel.setCellHeight(vp, "100%")

        Window.addWindowResizeListener(self)

        History.addHistoryListener(self)
        RootPanel().add(self.panel)


    def onWindowResized(self, width, height):
        self.sink_list.resize(width, height)
        self.sp.setHeight("%dpx" % (height-110))

    def show(self, info, affectHistory):
        if info == self.curInfo:
            return
        self.curInfo = info

        #Logger.write("showing " + info.getName())
        if self.curSink is not None:
            self.curSink.onHide()
            #Logger.write("removing " + self.curSink)
            self.sinkContainer.remove(self.curSink)

        self.curSink = info.getInstance()
        self.sink_list.setSinkSelection(info.getName())
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History().newItem(info.getName())

        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
        self.sinkContainer.setCellWidth(self.curSink, "100%")
        self.sinkContainer.setCellHeight(self.curSink, "100%")
        self.sinkContainer.setCellVerticalAlignment(self.curSink,
                                                    HasAlignment.ALIGN_TOP)
        self.curSink.onShow()
        
    def loadSinks(self):
        HTTPRequest().asyncGet("contents.txt", ChapterListLoader(self))

    def setChapters(self, chapters):
        for l in chapters:
            name = l[0]
            desc = l[1]
            self.sink_list.addSink(Chapter.init(name, desc))

        #Show the initial screen.
        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showInfo()


    def showInfo(self):
        self.show(self.sink_list.sinks[0], False)
Exemplo n.º 15
0
class IntroPage:
	DiceInstance = 0
	VarTempScore = 0 #Temporary Score Variable
	VarTotScore = [] #Total Score Variable
	CountTurn = 1 #Count to display player number in Temporary Score Board
	def __init__(self):
		self.DPanel = DockPanel(HorizontalAlignment = HasAlignment.ALIGN_CENTER,
						Spacing=10) # Creates the Docker Panel Instance
		self.VPanel = VerticalPanel() # Creates the Vertical Panel Instance
		self.VPanel1 = VerticalPanel() # Creates the Vertical Panel Instance
		self.HPanel = HorizontalPanel() # Creates a Horizontal Panel Instance
		self.HPanel1 = HorizontalPanel()# Creates a Horizontal Panel Instance


		self.image=Image()#Creates the Image instance to embed the images of dice
		self.DummyUrl = self.image.getUrl() 
		self.timer = Timer(notify=self.StillImage)#Timer for display of gif animation
		self.timerRButton =  Timer(notify=self.OneAlert)#Timer for controlling states of Roll button 
													#whenever the output of the dice is 1

		self.RollButton = Button("Roll", getattr(self, "RollButtonPressed")) #Initially Disabled 
		self.RollButton.setEnabled(False)
		self.BankButton = Button("Bank", getattr(self, "BankButtonPressed")) #Initially Disabled 
		self.BankButton.setEnabled(False)
		#The start button controls both the number players as well the winning score
		self.StartButton = Button("Start", getattr(self, "StartButtonPressed")) #Intially Enabled
		self.StartButton.setEnabled(True)


		self.PlayerNum = TextBox() #Enter the Number of Players
		self.WinScore = TextBox() #Enter the Target Score
		self.PlayerNum.setText("0")
		self.WinScore.setText("0")
		# self.OK = Button("OK", getattr(self, "okButtonPressed"))

		self.NameScore = FlexTable() #main score board
		self.NameScore.setStyleName("NameScore")
		self.TempBoard = FlexTable() #Temporary score board
		self.TempBoard.setStyleName("TempBoard")

		

		self.TxtInstructions = HTML()

	def StartButtonPressed(self):	   
		self.CountTurn = 1
		if int(self.PlayerNum.getText()) >= 2 and int(self.PlayerNum.getText()) <= 6 and int(self.WinScore.getText()) >= 10 and int(self.WinScore.getText()) <= 100:	        
			self.DPanel.remove(self.TxtInstructions, DockPanel.CENTER)
			self.BankButton.setVisible(True)
			self.RollButton.setVisible(True)
			# self.image.setVisible(True)
			self.TempBoard.setVisible(True)
			self.NameScore.setVisible(True)
			self.image = Image( self.DummyUrl + "images/0.png")
			self.image.setSize("200px", "300px")
			self.DPanel.add(self.image, DockPanel.CENTER)
			RootPanel().add(self.DPanel)
			self.StartButton.setEnabled(False)
			self.PlayerNum.setEnabled(False)
			self.WinScore.setEnabled(False)
			self.RollButton.setEnabled(True)
			self.TempBoard.setText(1,0,"Player"+str(1))
			self.TempBoard.setText(1, 1, "0")
			self.NameScore.getRowFormatter().addStyleName(self.CountTurn,"Rows")
		else:
			Window.alert("Please Enter Correct Parameters " ) #Command for alert window
			return 0
		VarPlayer = ["Player" + str(i) for i in xrange(1,int(self.PlayerNum.getText())+1)]
		i = 0
		while i < int(self.PlayerNum.getText()):
			self.NameScore.setText(i+1, 0, VarPlayer[i])
			self.NameScore.setText(i+1, 1, "0")
			self.VarTotScore.append(0) #m*1 vector of zeros indicating the initial scores 
			i += 1
	def OneAlert(self):
		AlrtTxt = " Sorry, your turn is over"
		Window.alert(AlrtTxt)
		self.timerRButton.cancel()
		self.RollButton.setEnabled(True)
	def StillImage(self):
		self.DPanel.remove(self.image, DockPanel.CENTER)
		self.image = Image( self.DummyUrl + "images/" +str(self.DiceInstance)+".png")
		self.image.setSize("300px", "300px")
		self.DPanel.add(self.image, DockPanel.CENTER)
		self.DPanel.setCellHeight(self.image, "300px")
		self.DPanel.setCellWidth(self.image, "600px")
		RootPanel().add(self.DPanel)
		self.timer.cancel()
		if self.DiceInstance != 1: 
			self.TempBoard.setText(1, 1, self.DiceInstance + int(self.TempBoard.getText(1, 1))) 
			self.BankButton.setEnabled(True)
			self.RollButton.setEnabled(True)
		else:
			self.NameScore.getRowFormatter().removeStyleName(self.CountTurn,"Rows")
			self.RollButton.setEnabled(False)
			self.timerRButton.schedule(1500)
			self.CountTurn += 1
			if self.CountTurn % int(self.PlayerNum.getText()) == 1:
				self.CountTurn = 1
				self.TempBoard.setText(1,0,"Player"+str(self.CountTurn))
				self.TempBoard.setText(1, 1, "0")
				self.NameScore.getRowFormatter().addStyleName(self.CountTurn,"Rows");
			else:
				self.TempBoard.setText(1,0,"Player"+str(self.CountTurn))
				self.TempBoard.setText(1, 1, "0")
				self.NameScore.getRowFormatter().addStyleName(self.CountTurn,"Rows");
		

	def RollButtonPressed(self):
		self.DiceInstance = random.randint(1, 6) # value turned after rolling the dice
		self.DPanel.remove(self.image, DockPanel.CENTER)
		self.image = Image("http://www.animatedimages.org/data/media/710/animated-dice-image-0064.gif")
		self.image.setSize("100px", "200px")
		self.DPanel.add(self.image, DockPanel.CENTER)
		self.DPanel.setCellHeight(self.image, "300px")
		self.DPanel.setCellWidth(self.image, "600px")
		RootPanel().add(self.DPanel)
		self.BankButton.setEnabled(False)
		self.RollButton.setEnabled(False)
		self.timer.schedule(3000)
   
	def BankButtonPressed(self):
		self.BankButton.setEnabled(False)
		self.NameScore.setText(self.CountTurn, 1,
			int(self.NameScore.getText(self.CountTurn, 1)) + int(self.TempBoard.getText(1,1)))
		if int(self.NameScore.getText(self.CountTurn, 1)) >= int(self.WinScore.getText()):
			AlrtTxt = "Congratulation!!! Player"+ str(self.CountTurn)  + " wins !!!!"
			Window.alert(AlrtTxt)

			self.DPanel.remove(self.image, DockPanel.CENTER)
			self.DPanel.add(self.TxtInstructions, DockPanel.CENTER)
			self.BankButton.setVisible(False)
			self.RollButton.setVisible(False)
			# self.image.setVisible(False)
			self.TempBoard.setVisible(False)
			self.NameScore.setVisible(False)

			i = int(self.PlayerNum.getText())
			while i > 0:
				self.NameScore. removeRow(i)
				i -= 1


			self.TempBoard.setText(1,0,"X")
			self.TempBoard.setText(1, 1, "0")
			self.StartButton.setEnabled(True)
			# self.OK.setEnabled(True)
			self.PlayerNum.setEnabled(True)
			self.WinScore.setEnabled(True)
			self.RollButton.setEnabled(False)
			self.BankButton.setEnabled(False)
			self.NameScore.getRowFormatter().removeStyleName(self.CountTurn,"Rows");




			self.DPanel.remove(self.image, DockPanel.CENTER)
			self.image = Image( self.DummyUrl + "images/0.png")
			self.image.setSize("200px", "300px")
			self.DPanel.add(self.image, DockPanel.CENTER)
			self.DPanel.setCellHeight(self.image, "200px")    
			self.DPanel.setCellWidth(self.image, "400px")




			RootPanel().add(self.DPanel)

		else:
			self.NameScore.getRowFormatter().removeStyleName(self.CountTurn,"Rows");
			self.CountTurn += 1
			if self.CountTurn % int(self.PlayerNum.getText()) == 1:
				self.CountTurn = 1
				self.TempBoard.setText(1,0,"Player"+str(self.CountTurn))
				self.TempBoard.setText(1, 1, "0")
				self.NameScore.getRowFormatter().addStyleName(self.CountTurn,"Rows");
			else:
				self.TempBoard.setText(1,0,"Player"+str(self.CountTurn))
				self.TempBoard.setText(1, 1, "0")
				self.NameScore.getRowFormatter().addStyleName(self.CountTurn,"Rows");

	def OnGameLoad(self):
		self.NameScore.setText(0, 0, "Player ID")
		self.NameScore.setText(0, 1, "Score")

		self.NameScore.setCellSpacing(10)       
		self.NameScore.setCellPadding(10)
		self.NameScore.setBorderWidth(2)
		self.NameScore.setVisible(False)

		self.TempBoard.setText(0, 0, "Player's Turn")
		self.TempBoard.setText(0, 1, "Temporary Score")
		self.TempBoard.setText(1, 0, "X")
		self.TempBoard.setText(1, 1, "0") 

		self.TempBoard.setCellSpacing(10)       
		self.TempBoard.setCellPadding(10)
		self.TempBoard.setBorderWidth(2)
		self.TempBoard.setVisible(False)	
		#Adding StartButton to Dock panel
		self.DPanel.add(self.StartButton, DockPanel.EAST)
		self.DPanel.setCellHeight(self.StartButton, "200px")    
		self.DPanel.setCellWidth(self.StartButton, "20px") 
		Txt = HTML("<center><b>Enter Number of Players (between 2 & 6)</b><center>")#Adding playernumber and winscore textbox to Horizontal Panel
		Txt1 = HTML("<left><b>Enter Target Score (between 10 & 100)</b><left>")
		self.HPanel1.add(Txt)
		self.HPanel1.add(self.PlayerNum)
		self.HPanel1.add(Txt1)
		self.HPanel1.add(self.WinScore)
		self.HPanel1.add(self.StartButton)
		self.HPanel1.setSpacing(20)	
		#Adding Horizontal panel containing playernumber and winscore textbox to Dock Panel
		self.DPanel.add(self.HPanel1, DockPanel.NORTH)
		self.DPanel.setCellHeight(self.HPanel1, "30px")    
		self.DPanel.setCellWidth(self.HPanel1, "2000px")
		self.TxtInstructions = HTML("<b><u><center>Instructions</center></u><ul><li>Pig is game for 2 to 6 Players.</li><li>Players take turns rolling a dice as many times as they like. </li><li>If a roll is 2, 3, 4, 5 or 6, the player adds that many points to their score for the turn. </li><li>A player may choose to end their turn at any time and 'bank' their points.</li><li>If a player rolls a 1, they lose all their unbanked points and their turn is over.</li><li>The first player to score the target or more wins.</li></ul></b>")
		self.TxtInstructions.setStyleName("TxtInstructions")
		self.DPanel.add(self.TxtInstructions, DockPanel.CENTER)
		self.DPanel.add(self.NameScore, DockPanel.WEST)		#Adding main scoreboard to Dock Panel
		self.DPanel.setCellHeight(self.NameScore, "300px")    
		self.DPanel.setCellWidth(self.NameScore, "100px")
		self.DPanel.setSpacing(10)
		self.DPanel.setPadding(2)
		#Adding Tempboard and BankButton to Horizontal Panel
		self.HPanel.add(self.TempBoard)	
		#Adding BankButton and RollButton to vertical panel	
		self.VPanel.add(self.RollButton) 		
		self.RollButton.setVisible(False)
		self.VPanel.add(self.BankButton) 
		self.BankButton.setVisible(False)    
		self.VPanel.setSpacing(10)
		#Adding Vertical panel containing BankButton and RollButton to Horizontal Panel
		self.HPanel.add(self.VPanel) 		
		self.HPanel.setSpacing(40)
		#Adding Horizontal panel containing Tempboard and vertical panel containing BankButton and RollButton to Dock Panel
		self.DPanel.add(self.HPanel, DockPanel.SOUTH)		
		self.DPanel.setCellHeight(self.HPanel, "20px")    
		self.DPanel.setCellWidth(self.HPanel, "2000px")
		RootPanel().add(self.DPanel)
Exemplo n.º 16
0
class AddonsGallery:

    def onHistoryChanged(self, token):
        info = self.sink_list.find(token)
        if info:
            self.show(info, False)
        else:
            self.showIntro()

    def onModuleLoad(self):
        self.curInfo=''
        self.curSink=None
        self.description=HTML()
        self.sink_list=SinkList()
        self.panel=DockPanel()
        
        self.loadSinks()
        self.sinkContainer = DockPanel()
        self.sinkContainer.setStyleName("ks-Sink")

        vp=VerticalPanel()
        vp.setWidth("100%")
        vp.add(self.description)
        vp.add(self.sinkContainer)

        self.description.setStyleName("ks-Info")

        self.panel.add(self.sink_list, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.sink_list, HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")

        History.addHistoryListener(self)
        RootPanel().add(self.panel)

        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showIntro()
    
    def show(self, info, affectHistory=None):
        if info == self.curInfo: return
        self.curInfo = info

        if self.curSink <> None:
            self.curSink.onHide()
            self.sinkContainer.remove(self.curSink)

        self.curSink = info.getInstance()
        self.sink_list.setSinkSelection(info.getName())
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History.newItem(info.getName())

        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
        self.sinkContainer.setCellWidth(self.curSink, "100%")
        self.sinkContainer.setCellHeight(self.curSink, "100%")
        self.sinkContainer.setCellVerticalAlignment(self.curSink, HasAlignment.ALIGN_TOP)
        self.curSink.onShow()
        
    def loadSinks(self):
        self.sink_list.add(IntroTab.init())
        self.sink_list.add(TooltipTab.init())
        self.sink_list.add(AutoCompleteTab.init())
        self.sink_list.add(Canvas2DTab.init())
        self.sink_list.add(CanvasTab.init())

    def showIntro(self):
        self.show(self.sink_list.find("Intro"))
Exemplo n.º 17
0
class Slideshow:

    def onHistoryChanged(self, token):
        info = self.sink_list.find(token)
        if info:
            self.show(info, False)
        else:
            self.showInfo()

    def onModuleLoad(self):
        self.curInfo=''
        self.curSink=None
        self.description=HTML()
        self.sink_list=SinkList()
        self.panel=DockPanel()
        self.b=Button("load", self)
        
        self.sinkContainer = DockPanel()
        self.sinkContainer.setStyleName("ks-Sink")

        height = Window.getClientHeight()

        self.sp = ScrollPanel(self.sinkContainer)
        self.sp.setWidth("100%")
        self.sp.setHeight("%dpx" % (height-110))

        vp=VerticalPanel()
        vp.setWidth("100%")
        vp.setHeight("100%")
        vp.add(self.description)
        vp.add(self.sp)

        self.description.setStyleName("ks-Intro")

        self.panel.add(self.sink_list, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.sink_list, HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")
        self.panel.setCellHeight(vp, "100%")

        Window.addWindowResizeListener(self)

        History.addHistoryListener(self)
        RootPanel().add(self.panel)
        #RootPanel().add(self.b)

        self.loadSinks()

    def onClick(self, sender):
        self.loadSinks()

    def onTimer(self, tid):
        self.loadSinks()

    def onWindowResized(self, width, height):
        #self.sink_list.resize(width, height)
        self.sp.setHeight("%dpx" % (height-110))

    def show(self, info, affectHistory):
        if info == self.curInfo: return
        self.curInfo = info

        #Logger.write("showing " + info.getName())
        if self.curSink <> None:
            self.curSink.onHide()
            #Logger.write("removing " + self.curSink)
            self.sinkContainer.remove(self.curSink)

        self.curSink = info.getInstance()
        self.sink_list.setSinkSelection(info.getName())
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History.newItem(info.getName())

        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
        self.sinkContainer.setCellWidth(self.curSink, "100%")
        self.sinkContainer.setCellHeight(self.curSink, "100%")
        self.sinkContainer.setCellVerticalAlignment(self.curSink, HasAlignment.ALIGN_TOP)
        self.curSink.onShow()
        
    def loadSinks(self):
        HTTPRequest().asyncGet("slides.txt", SlideListLoader(self))


    def setSlides(self, slides):
        for l in slides:
            name = l[0]
            desc = l[1]
            self.sink_list.add(Slide.init(name, desc))

        #Show the initial screen.
        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showInfo()


    def showInfo(self):
        self.show(self.sink_list.sinks[0], False)
Exemplo n.º 18
0
class KitchenSink:

    def onHistoryChanged(self, token):
        log.debug("onHistoryChanged: %s", token)
        info = self.sink_list.find(token)
        if info is not None:
            self.show(info, False)
        else:
            self.showInfo()

    def onModuleLoad(self):
        self.curInfo=''
        self.curSink=None
        self.description=HTML()
        self.sink_list=SinkList()
        self.panel=DockPanel()

        self.loadSinks()
        self.sinkContainer = DockPanel()
        self.sinkContainer.setStyleName("ks-Sink")

        vp=VerticalPanel()
        vp.setWidth("100%")
        vp.add(self.description)
        vp.add(self.sinkContainer)

        self.description.setStyleName("ks-Info")

        self.panel.add(self.sink_list, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.sink_list, HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")

        History.addHistoryListener(self)
        RootPanel().add(self.panel)
        RootPanel().add(Logger())

        #Show the initial screen.
        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showInfo()

    def show(self, info, affectHistory):
        if info == self.curInfo: return
        self.curInfo = info

        #log.debug("showing " + info.getName())
        if self.curSink is not None:
            #log.debug("removing " + str(self.curSink))
            self.curSink.onHide()
            self.sinkContainer.remove(self.curSink)

        self.curSink = info.getInstance()
        self.sink_list.setSinkSelection(info.getName())
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History.newItem(info.getName())

        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
        self.sinkContainer.setCellWidth(self.curSink, "100%")
        self.sinkContainer.setCellHeight(self.curSink, "100%")
        self.sinkContainer.setCellVerticalAlignment(self.curSink, HasAlignment.ALIGN_TOP)
        self.curSink.onShow()

    def loadSinks(self):
        self.sink_list.add(Info.init())
        self.sink_list.add(Buttons.init())
        self.sink_list.add(Menus.init())
        self.sink_list.add(Images.init())
        self.sink_list.add(Layouts.init())
        self.sink_list.add(Lists.init())
        self.sink_list.add(Popups.init())
        self.sink_list.add(Tables.init())
        self.sink_list.add(Text.init())
        self.sink_list.add(Trees.init())
        self.sink_list.add(Frames.init())
        self.sink_list.add(Tabs.init())

    def showInfo(self):
        self.show(self.sink_list.find("Info"), False)
Exemplo n.º 19
0
class Bookreader:

    def onHistoryChanged(self, token):
        info = self.sink_list.find(token)
        if info:
            self.show(info, False)
        else:
            self.showInfo()

    def onModuleLoad(self):
        section = Window.getLocation().getSearchVar("section")
        if not section:
            self.loadChapters()
        else:
            loadSection(section)

    def loadChapters(self):

        self.curInfo = ''
        self.curSink = None
        self.description = HTML()
        self.sink_list = SinkList()
        self.panel = DockPanel()

        self.loadSinks()
        self.sinkContainer = DockPanel()
        self.sinkContainer.setStyleName("ks-Sink")

        #self.nf = NamedFrame("section")
        #self.nf.setWidth("100%")
        #self.nf.setHeight("10000")

        self.sp = ScrollPanel(self.sinkContainer)
        #self.sp = VerticalSplitPanel()
        self.sp.setWidth("100%")
        self.sp.setHeight("100%")

        #self.sp.setTopWidget(self.sinkContainer)
        #self.sp.setBottomWidget(self.nf)
        #self.sp.setSplitPosition(10000) # deliberately high - max out.

        vp = VerticalPanel()
        vp.setWidth("99%")
        vp.setHeight("100%")
        vp.add(self.description)
        vp.add(self.sp)

        authors = [
            ("2008, 2009", "Kenneth Casson Leighton", "*****@*****.**")
        ]
        for years, name, email in authors:
            authors_html = \
            '&copy; %s <a href="mailto:%s">%s</a><br />' %\
            (years, email, name)
        authors_panel = HTML()
        authors_panel.setStyleName("ks-Authors")
        authors_panel.setHTML(authors_html[:-6])

        left_panel = DockPanel(Height="100%")
        left_panel.add(self.sink_list, DockPanel.NORTH)
        left_panel.add(authors_panel, DockPanel.SOUTH)

        self.description.setStyleName("ks-Intro")

        self.panel.add(left_panel, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.sink_list,
                                            HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")
        self.panel.setCellHeight(vp, "100%")

        Window.addWindowResizeListener(self)

        History.addHistoryListener(self)
        RootPanel().add(self.panel)

        self.onWindowResized(Window.getClientWidth(), Window.getClientHeight())

    def onWindowResized(self, width, height):
        self.panel.setWidth(width-20)
        self.sink_list.resize(width-20, height-130)
        self.sp.setHeight("%dpx" % (height-130))

    def show(self, info, affectHistory):
        if info == self.curInfo:
            return
        self.curInfo = info

        #Logger.write("showing " + info.getName())
        if self.curSink is not None:
            self.curSink.onHide()
            #Logger.write("removing " + self.curSink)
            self.sinkContainer.remove(self.curSink)

        self.curSink = info.getInstance()
        self.sink_list.setSinkSelection(info.getName())
        self.sink_list.sp.setScrollPosition(0)
        self.sink_list.sp.setHorizontalScrollPosition(0)
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History().newItem(info.getName())

        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
        self.sinkContainer.setCellWidth(self.curSink, "100%")
        self.sinkContainer.setCellHeight(self.curSink, "100%")
        self.sinkContainer.setCellVerticalAlignment(self.curSink,
                                                    HasAlignment.ALIGN_TOP)
        self.curSink.onShow()

    def loadSinks(self):
        HTTPRequest().asyncGet("contents.txt", ChapterListLoader(self))

    def setChapters(self, chapters):
        for l in chapters:
            name = l[0]
            desc = l[1]
            self.sink_list.addSink(Chapter.init(name, desc))

        #Show the initial screen.
        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showInfo()


    def showInfo(self):
        self.show(self.sink_list.sinks[0], False)
Exemplo n.º 20
0
class KitchenSink:

    filexml = None

    def onHistoryChanged(self, token):
        log.writebr("onHistoryChanged: %s" % token)
        info = self.sink_list.find(token)
        if info:
            self.show(info, False)
        else:
            self.showInfo()

    def onModuleLoad(self):
        self.curInfo=''
        self.curSink=None
        self.description=HTML()
        self.sink_list=SinkList()
        self.panel=DockPanel()
        
        self.loadSinks()
        self.sinkContainer = DockPanel()
        self.sinkContainer.setStyleName("ks-Sink")

        vp=VerticalPanel()
        vp.setWidth("100%")
        vp.add(self.description)
        vp.add(self.sinkContainer)

        self.description.setStyleName("ks-Info")

        self.panel.add(self.sink_list, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.sink_list, HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")

        History.addHistoryListener(self)
        RootPanel().add(self.panel)
        RootPanel().add(Logger())

        #Show the initial screen.
        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showInfo()
            
    def getHeight(self):
        return rccutil.getHeight()
        
    def show(self, info, affectHistory):
        if info == self.curInfo: return
        self.curInfo = info

        #Logger.write("showing " + info.getName())
        if self.curSink <> None:
            self.curSink.onHide()
            #Logger.write("removing " + self.curSink)
            self.sinkContainer.remove(self.curSink)

        self.curSink = info.getInstance()
        self.sink_list.setSinkSelection(info.getName())
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History.newItem(info.getName())

        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
        self.sinkContainer.setCellWidth(self.curSink, "100%")
        self.sinkContainer.setCellHeight(self.curSink, "100%")
        self.sinkContainer.setCellVerticalAlignment(self.curSink, HasAlignment.ALIGN_TOP)
        self.curSink.onShow()
        
    def loadSinks(self):
        #self.sink_list.addSink(DataTree.init())
        #self.sink_list.addSink(RecipeSystemIFACE.init())
        self.sink_list.addSink(ADViewerIFACE.init())
        self.sink_list.addSink(RecipeViewer.init())
        self.sink_list.addSink(FITSStoreFACE.init())
        self.sink_list.addSink(DisplayIFACE.init())
        self.sink_list.addSink(Info.init())
        if False:
            self.sink_list.addSink(Buttons.init())
            self.sink_list.addSink(Menus.init())
            self.sink_list.addSink(Images.init())
            self.sink_list.addSink(Layouts.init())
            self.sink_list.addSink(Lists.init())
            self.sink_list.addSink(Popups.init())
            self.sink_list.addSink(Tables.init())
            self.sink_list.addSink(Text.init())
        if False: #preserving originaly order
            self.sink_list.addSink(Frames.init())
            self.sink_list.addSink(Tabs.init())

    def showInfo(self):
        self.show(self.sink_list.find("AstroData Viewer"), False)
Exemplo n.º 21
0
class Bookreader:
    def onHistoryChanged(self, token):
        info = self.sink_list.find(token)
        if info:
            self.show(info, False)
        else:
            self.showInfo()

    def onModuleLoad(self):
        section = Window.getLocation().getSearchVar("section")
        if not section:
            self.loadChapters()
        else:
            loadSection(section)

    def loadChapters(self):

        self.curInfo = ''
        self.curSink = None
        self.description = HTML()
        self.sink_list = SinkList()
        self.panel = DockPanel()

        self.loadSinks()
        self.sinkContainer = DockPanel()
        self.sinkContainer.setStyleName("ks-Sink")

        #self.nf = NamedFrame("section")
        #self.nf.setWidth("100%")
        #self.nf.setHeight("10000")

        self.sp = ScrollPanel(self.sinkContainer)
        #self.sp = VerticalSplitPanel()
        self.sp.setWidth("100%")
        self.sp.setHeight("100%")

        #self.sp.setTopWidget(self.sinkContainer)
        #self.sp.setBottomWidget(self.nf)
        #self.sp.setSplitPosition(10000) # deliberately high - max out.

        vp = VerticalPanel()
        vp.setWidth("99%")
        vp.setHeight("100%")
        vp.add(self.description)
        vp.add(self.sp)

        authors = [("2008, 2009", "Kenneth Casson Leighton", "*****@*****.**")]
        for years, name, email in authors:
            authors_html = \
            '&copy; %s <a href="mailto:%s">%s</a><br />' %\
            (years, email, name)
        authors_panel = HTML()
        authors_panel.setStyleName("ks-Authors")
        authors_panel.setHTML(authors_html[:-6])

        left_panel = DockPanel(Height="100%")
        left_panel.add(self.sink_list, DockPanel.NORTH)
        left_panel.add(authors_panel, DockPanel.SOUTH)

        self.description.setStyleName("ks-Intro")

        self.panel.add(left_panel, DockPanel.WEST)
        self.panel.add(vp, DockPanel.CENTER)

        self.panel.setCellVerticalAlignment(self.sink_list,
                                            HasAlignment.ALIGN_TOP)
        self.panel.setCellWidth(vp, "100%")
        self.panel.setCellHeight(vp, "100%")

        Window.addWindowResizeListener(self)

        History.addHistoryListener(self)
        RootPanel().add(self.panel)

        self.onWindowResized(Window.getClientWidth(), Window.getClientHeight())

    def onWindowResized(self, width, height):
        self.panel.setWidth(width - 20)
        self.sink_list.resize(width - 20, height - 130)
        self.sp.setHeight("%dpx" % (height - 130))

    def show(self, info, affectHistory):
        if info == self.curInfo:
            return
        self.curInfo = info

        #Logger.write("showing " + info.getName())
        if self.curSink is not None:
            self.curSink.onHide()
            #Logger.write("removing " + self.curSink)
            self.sinkContainer.remove(self.curSink)

        self.curSink = info.getInstance()
        self.sink_list.setSinkSelection(info.getName())
        self.sink_list.sp.setScrollPosition(0)
        self.sink_list.sp.setHorizontalScrollPosition(0)
        self.description.setHTML(info.getDescription())

        if (affectHistory):
            History().newItem(info.getName())

        self.sinkContainer.add(self.curSink, DockPanel.CENTER)
        self.sinkContainer.setCellWidth(self.curSink, "100%")
        self.sinkContainer.setCellHeight(self.curSink, "100%")
        self.sinkContainer.setCellVerticalAlignment(self.curSink,
                                                    HasAlignment.ALIGN_TOP)
        self.curSink.onShow()

    def loadSinks(self):
        HTTPRequest().asyncGet("contents.txt", ChapterListLoader(self))

    def setChapters(self, chapters):
        for l in chapters:
            name = l[0]
            desc = l[1]
            self.sink_list.addSink(Chapter.init(name, desc))

        #Show the initial screen.
        initToken = History.getToken()
        if len(initToken):
            self.onHistoryChanged(initToken)
        else:
            self.showInfo()

    def showInfo(self):
        self.show(self.sink_list.sinks[0], False)
Exemplo n.º 22
0
class WebApp:
    def onFormLoad(self):
        self.fetch = Button("Retrieve", self)
        self.search = TextBox()
        self.submit = Button("Submit", self)
        self.formsvc = FormService()
        self.wanted = WantedService()
        d = {'price': 20, 'name': 'a good car'}
        self.form = Form(getattr(self.formsvc, "itemform"), data=d,
                         listener=self)
        #self.describe(['name', 'description'])
        RootPanel().add(self.form)
        RootPanel().add(self.search)
        RootPanel().add(self.fetch)

    def onRetrieveDone(self, form):
        log.debug("onRetrieveDone: %s" % repr(form))

    def onDescribeDone(self, form):
        form.add_widget("Submit", self.submit)

    def onClick(self, sender):
        if sender == self.fetch:
            key = self.search.getText()
            if not key:
                log.debug("Please enter id")
                return
            key = int(key)
            log.debug("id %d" % key)
            #self.wanted.getItem(key, self)
            self.form.get(id=key)

        if sender == self.submit:
            v = self.form.getValue()
            log.debug("onClick %s" % repr(v))
            if v.get('id', None):
                self.form.update(v)
            else:
                self.form.save(v)
 
    def onErrors(self, form, response):
        log.debug("onErrors %s" % repr(response))
        
    def onSaveDone(self, form, response):
        log.debug("onSave %s" % repr(response))
        
    def onModuleLoad(self):

        self.pages = DataService()

        #Show the initial screen.
        initToken = History().getToken()
        if initToken and len(initToken):
            if initToken == 'admin':
                RootPanel().add(WebPageEdit(self))
                return
        else:
            initToken = 'index'

        self.dock = DockPanel()
        self.dock.setWidth("100%")
        self.pages = {}
        self.current_page = None
        RootPanel().add(self.dock)

        History.addHistoryListener(self)
        self.onHistoryChanged(initToken)

    def createPage(self, ref, html, title):
        htp = HTMLLinkPanel(self, html, title)
        htp.replaceLinks()
        htp.setWidth("100%")
        self.pages[ref] = htp

    def onHistoryChanged(self, token):
        #log.debug("onHistoryChanged %s" % token)
        if self.pages.has_key(token):
            self.setPage(token)
            return
        self.pages.getPageByName(token, self)

    def setPage(self, ref):
        
        htp = self.pages[ref]
        if htp == self.current_page:
            return
        Window.setTitle(htp.title)
        if self.current_page:
            self.dock.remove(self.current_page)
        self.dock.add(htp, DockPanel.CENTER)
        self.current_page = htp

    def onRemoteResponse(self, response, request_info):
        #if (request_info.method == 'getItem'):
        #    data = {'id': response['pk']}
        #    log.debug(repr(response))
        #    self.form.update_values(response)

        if (request_info.method == 'getPageByName' or
           request_info.method == 'getPage'):
            item = response[0]
            html = item['fields']['text']
            token = item['fields']['name']
            self.createPage(token, html, token)
            self.setPage(token)

    def onRemoteError(self, code, message, request_info):
        RootPanel().add(HTML("Server Error or Invalid Response: ERROR " + str(code) + " - " + str(message)))