Hopefully, everyone completely understands sizers - LOL.  I laugh because I 
sometimes get confused using sizers.  But rest assured that you will get the 
hang of it and most of the time it's easy.  Just play with them until get 
what you want.  It also helps to draw a little picture of what you want the 
form to look like before starting and you'll get there.  You may have noticed 
I did not explain the use of a “grid sizer”.   I didn't because it really 
does not fit into this tutorial.  But I use the grid sizer often.  It helps 
maintain “control/object” alignment on the form.  Maybe later I (or someone 
else) can provide a demo using a grid sizer.

In the Visual Fox Pro world (windows) Adrian's request of a demo to “browse 
directories” would have taken but a short time to develop and deliver.   I 
would create a form, add a label, add a textbox, and a button to activate the 
open file dialog.  Maybe all of ten minutes.  Well I just timed it and it 
took 12 minutes in Dabo (mostly because I can't type – you'd think after 
twenty years I learn how to type).  Anyway, my point is Dabo's framework ( 
and everything Dabo is built on wxPython, Python) is just as powerful as VFP, 
VB and all the other languages.  And in my mind it is more powerful because 
it's cross platform and one of the easiest languages to read and understand.  
But I guess I'm singing to the choir since those that are reading this are at 
least considering moving to Dabo for those very reasons.

 Sorry got off topic!  

Like all modern day languages the Dabo framework has events.  When the user 
clicks on a button with the mouse an event occurs.  With Dabo you have 
to “bind” the event to some action (function, method).     Most languages do 
the same thing.  In java they are called event listeners, in C++ they are 
called callbacks.  Some languages sort of hide the events methods as in VFP 
where the event method is on a property page.  But you can bet it is there 
somewhere.

The first thing we need to do with Dabo is to import the list of events.  I'm 
taking a minor short cut here.  I am naming 'dabo.dEvents' as 'dEvents' just 
to save a little typing.  You should see the line near the top of the 
program.

import dabo.dEvents as dEvents  

So now we have a list of available Dabo events and we need explain how to use 
them.  I'll show you the long way of binding an event.  I think it better 
explains what is happening.  Maybe someone would like to post the easy way to 
bind an event – all on one line of code.

The next line of code assigns a variable “ourButton” for a Dabo button.  
Notice that I have added a new attribute “RegID”.  Every control/object 
within the Dabo framework can have a “RegID” (or a name?).  It should be 
unique and if you don't assign a “RegID” the framework will assign one.  This 
is cool because it allows us (the programmers) to later reference the object.  
Knowing the “RegID” I can later assign a value or change a value or property 
of the object.  

ourButton=dabo.ui.dButton(self,RegID="selectButton",Caption= "...")

Now that I have a button I want something to happen when I click on the 
button.  With VFP I would find the “click” method of the object and type in 
the name of a function I want executed when the object was clicked.  It' 
similar in Dabo.  I first tell the object what event I want to control and 
what method/function I want to execute.  As follows:

ourButton = the name of the object (our variable).

bindEvent = what I doing  - the method – I'm binding an event.

dEvents.Hit = (recall my little short cut) which of the many events I want 
bound.

self._openDialog = the method/function I want executed when the event occurs.

ourButton.bindEvent(dEvents.Hit, self._openDialog)

Yes you're right – the event names don't match windows event names.  But a 
rose smells just as sweet no matter what it's called (or something close to 
that – you know what I mean).  The point is the event names are descriptive 
enough for you to guess what they do.

Now let's open a file dialog.
def _openDialog(self,evt):
                # need to pass the evt (in this case a click or Hit)
                evt.stop()
                theDialog=dabo.ui.dFileDialog(self)
                theDialog.show()

First you must pass the event (in this case “evt”) otherwise the program will 
complain.  The “evt” variable is very powerful. Using evt.EventObject 
provides the calling objects “ID” for example – there are many other 
attributes.  I have only scratched the surface with binds and events.  But 
that's all that is needed for our tutorial.  And I bet you'll not need much 
more for your future programs.  The next two lines are a demonstration of the 
what is already built in to Dabo.  I didn't have to write a line of code.

I have not used the Dabo textbox in this example.  Maybe someone might try and 
retrieve the filename picked and display it in the textbox.  Post your code.


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

class MainForm(dabo.ui.dForm):

        def afterInit(self):
                self.Caption = "File Tutorial"
                self.Sizer =hs= dabo.ui.dSizer("h")
                
                hs.append(dabo.ui.dLabel(self, Caption= "Select a file"),0)
                hs.append(dabo.ui.dTextBox(self,RegID = "filename"),1)
                ourButton=dabo.ui.dButton(self,RegID="selectButton",Caption= 
"...")
                ourButton.bindEvent(dEvents.Hit, self._openDialog)
                hs.append(ourButton,0)
                
                self.layout()
        
        def _openDialog(self,evt):
                # need to pass the evt (in this case a click or Hit)
                evt.stop()  #no need to pass the evt on I got what I want
                theDialog=dabo.ui.dFileDialog(self)
                theDialog.show()

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


As always if made a mistake help me fix it.
-- 
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