dabodemo Commit
Revision 333
Date: 2005-11-10 10:15:58 -0800 (Thu, 10 Nov 2005)
Author: ed

Changed:
_U  trunk/montana.py
A   trunk/simpleDemo1.py

Log:
Added the first in what I hope will be a series of demos that newcomers to Dabo 
can look at to get a taste of what Dabo code looks like. 

This demo shows event binding, RegID usage, and binding of controls to values 
other than database table columns. It also uses absolute positioning, which was 
done on my OS X box, so it might not look as good on other platforms.



Diff:

Property changes on: trunk/montana.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/simpleDemo1.py
===================================================================
--- trunk/simpleDemo1.py        2005-11-05 07:05:27 UTC (rev 332)
+++ trunk/simpleDemo1.py        2005-11-10 18:15:58 UTC (rev 333)
@@ -0,0 +1,93 @@
+"""This is a very simple demo designed to show a few things about 
+Dabo programming:
+
+- I've laid out the form using absolute positioning instead of sizers.
+Nothing about Dabo requires sizers. The layout looks great on my 
+OS X box; I'm sure it will look less ideal on other platforms.
+
+- The EditBox is bound to a method of the form. Nothing in Dabo 
+requires that you bind controls to fields in a database table. You 
+can easily achieve highly interactive UIs by using the data binding
+of controls.
+
+- Note how simple it is to populate a list: just set the 'Choices' property
+to the list containing the values you want, and it's done!
+
+- Auto-binding of events: note that we're binding to the Hit events of
+both the button and the dropdown list. Dabo resolves that by using the 
+RegID property of those controls. This is a developer-definable label that
+must be unique across a given form. You don't need to define them for all
+controls; just for those you wish to reference. Given an event 'XXX',
+creating an 'onXXX()' method in the form binds that method to the form's 
+XXX event, but creating a method named 'onXXX_zzz()' binds that method 
+to the XXX event of the object whose RegID ='zzz', no matter where on
+the form that object exists.
+
+- Calling the 'refresh()' method of a control will update that control with
+its bound value. Calling 'refresh()' of the form will update all controls on 
+the form.
+
+"""
+
+import wx
+import dabo
+dabo.ui.loadUI("wx")
+import dabo.dEvents as dEvents
+
+
+class DocStringForm(dabo.ui.dForm):
+       def afterInit(self):
+               self.Caption = "DocString Demo"
+               self.Size = (660, 400)
+               
+               self.btn = dabo.ui.dButton(self, Left=50, Top=50, 
RegID="button",
+                               Width=320, Caption="Click Me to Populate the 
Dropdown List")
+               
+               self.dd = dabo.ui.dDropdownList(self, Width=150, Left=50,
+                               Top=100, RegID="ddList")
+                               
+               self.edt = dabo.ui.dEditBox(self, Width=360, Height=200,
+                               Left=250, Top=100, DataSource="form", 
+                               DataField="getdocstring")
+               
+               self.spnPos = dabo.ui.dSpinner(self, Left=50, Top=200,
+                               DataSource="ddList", DataField="PositionValue")
+               
+               lbl = dabo.ui.dLabel(self, Left=50, Top=180, 
+                               Caption="Selected Item")
+       
+       
+       def onHit_ddList(self, evt):
+               """Note: this will fire when the dropdown list is changed"""
+               self.refresh()
+
+
+       def onHit_button(self, evt):
+               """This populates the DropdownList control"""
+               self.dd.Choices = dir(self.btn)
+               self.spnPos.Max = len(self.dd.Choices)
+               self.dd.PositionValue = 0
+
+
+       def getdocstring(self):
+               """ Return the docstring for the selected 
prop/method/attribute"""
+               ret = ""
+               val = self.dd.StringValue
+               if val:
+                       try:
+                               ret = eval("self.btn.__class__.%s.__doc__" % 
val)
+                       except:
+                               ret = None
+               if ret is None:
+                       ret = "-no docstring available-"
+               return ret
+               
+
+def main():
+       app = dabo.dApp()
+       app.MainFormClass = DocStringForm
+       app.start()
+
+if __name__ == '__main__':
+       main()
+


Property changes on: trunk/simpleDemo1.py
___________________________________________________________________
Name: svn:eol-style
   + native




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to