This installment will bring back sizers again.  No fears!  All we are going to 
do is use what we already know.  You may recall when we started this tutorial 
that I started with a vertical sizer to demo the expand flag.  I then 
switched to a horizontal sizer to demo the proportional settings using 
buttons.  What I did not show you was how sizers work together to layout your 
display.  It may have been obvious to some how it works but an example never 
hurts.  Also Adrian asked for a “dropdown” list control.  Sorry Adrian I'm 
going to cheat for now and use a very simple form of the Dabo available list 
boxes – dabo.ui.dDropdownList.  

OK, vertical sizers expand in the horizontal and horizontal sizers expand in 
the vertical.  So which should you start with - a vertical sizer or a  
horizontal sizer?  That depends.  You knew that was coming didn't you!  

Considering our form, I want the controls to line up from left to right and 
the next row to do the same.  I do that by starting with a vertical sizer and 
adding horizontal sizers for each row to the vertical sizer. Some thing like 
the following: 

#first I start with a vertical sizer
self.Sizer =vs= dabo.ui.dSizer("v")

#now create a horizontal sizer 
hs1= dabo.ui.dSizer("h")

# just add our controls
hs1.append(.......)

# Last but not least add the horizontal sizer to the vertical sizer
vs.append(hs1,0,'x')

That works for our form but most forms are not that simple.  Of course you 
should be able to do a lot of the layout just using vertical and horizontal 
sizers (and I did not show you the grid sizer).  But I also use another 
control – I use panels.  Recall I said that Dabo panels have a client area.  
That means you can add sizers to panels and of course controls.  After 
setting up the display within a panel just append the panel to a form sizer. 
If you can't setup your display with all this flexibility you may have to 
reconsider what you are trying to display.  Check out 
http://leafe.com/screencasts/realworlddabo.html for a few different layouts 
more complex than our form.

So todays code has a panel that contains a dabo.ui.dDropdownList (which I hard 
coded the choices and bound an event) and a panel.  So I have a panel within 
a panel and I add it all to a form sizer.  At this point I have answered all 
of Adrian's questions.  But I did not touched on the best feature of Dabo – 
bizObjects.  So this tutorial will end and a new one will start soon that 
will cover using bizObjects.


#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import dabo
import dabo.dEvents as dEvents
import dabo.dException as dException
dabo.ui.loadUI('wx')

class TheListPanel(dabo.ui.dPanel):
        def afterInit(self):
                self.Sizer =hs= dabo.ui.dSizer("h")
                ourList=dabo.ui.dDropdownList(self,RegID='StopLightID',
                Choices=("Red", "Yellow", "Green"),PositionValue=2)
                ourList.bindEvent(dEvents.ValueChanged, self.Form._changeLight)
                hs.append(ourList,0)
                

class MainForm(dabo.ui.dForm):
        
        def afterInit(self):
                self.Caption = "File Tutorial"
                self.Sizer =vs= dabo.ui.dSizer("v")
                
                hs1= dabo.ui.dSizer("h")
                hs1.append(dabo.ui.dLabel(self, Caption= "Select a file"),0)
                hs1.append(dabo.ui.dTextBox(self,RegID = "filename"),1)
                ourButton=dabo.ui.dButton(self,RegID="selectButton",Caption= 
"...")
                ourButton.bindEvent(dEvents.Hit, self._openDialog)
                hs1.append(ourButton,0)
                vs.append(hs1,0,'x')
                
                hs2= dabo.ui.dSizer("h")
                lp=TheListPanel(self)
                hs2.append(lp,0,"x")
                
hs2.append(dabo.ui.dPanel(self,RegID="lightID",BackColor="Green"),1,'x')
                vs.append(hs2,0,'x')
                
                self.layout()
                
        
        def _openDialog(self,evt):
                # need to receive the evt (in this case a click or Hit)
                theDialog=dabo.ui.dFileDialog(self)
                theDialog.show()
                if sys.platform == 'win32':
                        myseperator = "\\"  # some should post why I needed two 
slashes
                else:
                        myseperator = "/"
                
                myReturnFileValue= theDialog.FileName
                myReturnDirectory = theDialog.Directory
                
                self.filename.Value= myReturnDirectory + myseperator + 
myReturnFileValue
                
        def _changeLight(self,evt):
                if self.StopLightID.PositionValue == 2:
                        self.lightID.BackColor="Green"
                elif self.StopLightID.PositionValue == 0:
                        self.lightID.BackColor="Red"
                else:
                        self.lightID.BackColor="Yellow"
                        

if __name__ == "__main__":
        app = dabo.dApp()
        
        app.BasePrefKey = "fileTutor"
        app.setAppInfo("appName", "File Tutorial ")
        
        app.MainFormClass = MainForm
        
        app.start()



-- 
John Fabiani


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]

Reply via email to