How To Overlay Controls

From Dabo Wiki
Jump to: navigation, search

A small example of using dPageFrameNoTabs to allow overlaying textboxes on a form. Written by Larry Long and John Fabiani (the suggestion of using dPageFrameNoTabs came from Ed Leafe)

import dabo
dabo.ui.loadUI("wx")
import dabo.dEvents as dEvents


class KiloPanel(dabo.ui.dPanel):
    def afterInit(self):
        self.Sizer = hs = dabo.ui.dSizer("h")
        hs.append(dabo.ui.dTextBox(self),proportion=3,alignment='right')
        hs.append(dabo.ui.dLabel(self,Caption=' Kg'))


class LbsPanel(dabo.ui.dPanel):
    def afterInit(self):
        self.Sizer = hs = dabo.ui.dSizer("h")
        hs.append(dabo.ui.dTextBox(self),proportion=3,alignment='right')
        hs.append(dabo.ui.dLabel(self,Caption=' Lbs  '))
        hs.append(dabo.ui.dTextBox(self),proportion=1,alignment='right')
        hs.append(dabo.ui.dLabel(self,Caption=' Oz'))


class Wtpgf(dabo.ui.dPanel):
    def afterInit(self):
        self.Sizer = hs = dabo.ui.dSizer("h")
        #hs.append(dabo.ui.dLabel(self,Caption='hellow worl;d'))
        pageFrame = pgf = dabo.ui.dPageFrameNoTabs(self,DynamicSelectedPageNumber=self.GetDisplayMode,RegID='WtPgf')
        pgf.appendPage(pgCls=KiloPanel)
        pgf.appendPage(pgCls=LbsPanel)
        hs.append(pgf, 1,"x") 
    def GetDisplayMode(self):
        return(self.Form.WtDisplayMode) 


class TestForm(dabo.ui.dForm):
    def afterInit(self):
        self.WtDisplayMode=1
        self.Sizer = dabo.ui.dSizer("vertical")
        self.Sizer.append1x(Wtpgf(self))
        self.Sizer.append(dabo.ui.dButton(self,Caption='Click me',OnHit=self.clickme))
        self.layout()
    def clickme(self,evt):
        if self.WtDisplayMode:
            self.WtDisplayMode=0
        else:
            self.WtDisplayMode=1
        self.update()       
        evt.stop()  


def main():
   app = dabo.dApp()
   app.MainFormClass = TestForm
   app.start()


if __name__ == '__main__':
   main()