Ah, now here is something that begins to show off just what Dabo can do.
Context: SimpleFormWithBizobj.py can be found in the dabodemo package.
Let's go over the different sections. First comes a class based on the dConnectInfo class. Here the various parameters needed to connect to the backend database are set. For the demo, a public MySQL database on leafe.com has been made available. Feel free to modify, add and delete data, since you won't be harming anything. The data is a copy of some US zipcode information that is restored regularly.
Next comes a class called MyBizobj based on the Dabo base dBizobj class. We have to give this class some basic information about the data it will be working with, such as the name ("DataSource"), the KeyField, and any default values to assign to fields when a new record is created. This is done in the class's beforeInit() method, which is the place to place code that needs to run before the object is created. The demo is set to default to EdLeafe's home town of Penfield, NY, but you should try changing the defaultValues dictionary setting to something else (maybe your home town?), and then running the demo again. Add a new record, and surprise! There are the new default values!
There is one other important property set in the bizobj, and that's RequeryOnLoad. If this is True, the bizobj tells its cursor object to run its query when the form starts up. Typically, though, you don't want to do this; rather, it's better to set up some search criteria first, and then run the query, in order to avoid bringing a ton of records. In this case, we don't want all the zipcode records brought over to the form when it is run, so we set this to False.
Next comes the method where you will be placing most of your business logic. The validateRecord() method is called for every modified record before changes to that record are committed back to the database. The demo contains some basic validation rules; try playing around with this by making your own validation rules and seeing how the form responds to those changes.
If validateRecord() returns a non-empty string, the bizobj will know that there is a problem, and will not allow the save to proceed. Instead, it raises an exception that the form catches; the form then displays the error text you returned from validateRecord so that the user knows what problems existed in the data.
That's all for the bizobj, at least in this simple demo. There are many other hook methods available for influencing the behavior of your app; these will be documented elsewhere. What's important here is that very little needs to be done to make it work.
Finally, we come to the class definition for the form. We set some initial properties here; one thing to note is that this demo was written before we had really fleshed out the framework. Originally you had to interact with the controls in a very wxPython-ish manner; this is visible in the code for setting the Size and Position properties: they both take a tuple representing a point coordinate. Since then we've updated the controls to enable you to set their Left, Top, Right, Bottom, Width and Height properties directly. So the line:
self.Size = (400,280)
would be written now as:
self.Left = 400
self.Top = 280
While this might seem like a step backwards (omigosh! two lines instead of one!), it makes for a more flexible framework, since not all UI toolkits will work with wxPython's point references. By sticking with the now-standard position properties, your code is much more likely to work in whatever UI it is run under.
The form then creates a connection instance, which it will pass to the bizobjs it creates in the instantiateBizobj() method.
THIS IS DEPECREATED CHANGED: NEED TO CLEAN THIS UP Next comes a few lines that set up the SQL used in the bizobj. This is still pretty unpolished; most likely, this logic will be moved to the bizobj, and the form will only have to change things specific to its needs.
Finally, we have the lines that affect the appearance and behavior of the form. [setColumnDefs]?() is a powerful method that takes a list of dictionaries describing the fields to be included in the form, along with details about their appearance. See that page for a more in-depth description of each of the available settings for each field.
I hope that this helps everyone understand this demo app a little better, and gives them some insight into how simple Dabo apps are created. And while this is a pretty simple app, think for a moment what it does: it allows you to interactively create a SQL query against a 50,000-record table in a database located somewhere out across the internet, run the query, sort and edit the results, and save those changes back to the remote database. All in less than 6K of code, including comments!