On Aug 24, 2005, at 7:17 AM, Torsten Bronger wrote:

Do you think it makes sense to develop some toy applications in
wxPython before learning Dabo?  (I've found a very good wxPython
book in our library.)

Well, yes and no. Since the Dabo UI is a wrapper around wxPython, it will give you some familiarity with the classes we are using, as well as the use of things like sizers.

One potential drawback, though, is that you might end up a bit more confused when writing code, since most of the API is different. You create objects differently, you alter their appearance differently, you handle events differently, etc. We believe that the Dabo API is simpler and much easier to work with, but it's always harder when you're 'unlearning' another way of doing things. Then again, if you don't like the C++ style of wxPython, maybe if you've struggled with that for a while, you'll really appreciate Dabo's more Pythonic style! ;-)

As part of my talk at PyCon DC 2005, I gave a very simple example that contrasted coding in native wxPython and in Dabo. This example defines a UI window (called a 'frame' in wxPython, 'form' in Dabo), and adds a labeled button that displays a message when clicked. Pretty simple stuff, but it does illustrate the differences. Since this is from the accompanying paper to that talk, I included as comments a lot of the points I made during the live session.

wxPython version
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
import wx

class WxDemoFrame(wx.Frame):
    def __init__(self, parent, id):
        # Note the requirement for always passing an 'id'.
        super(WxDemoFrame, self).__init__(parent=parent, id=id)
        # If we want to to set the text for a frame, we have
        # to call 'SetTitle()'
        self.SetTitle("This is a wx Frame")
        self.SetSize((300, 400))
        btn = wx.Button(self, -1)
        # Now we want to set the text on the button. This
        # time we have to remember that buttons use a
        # method called 'SetLabel()' rather than 'SetTitle()'
        # as the frame class does.
        btn.SetLabel("Click Me")
        # You must send tuples to set the size or position.
        # Even if you only want to change the width or
        # the y-position. You also have to remember which
        # comes first: width or height.
        btn.SetSize((90, 24))
        btn.SetPosition((50, 50))
        # Here's another of those easy-to-remember
        # constants. Every control has its own set of event
        # names you have to remember.
        btn.Bind(wx.EVT_BUTTON, self.onClick)

    def onClick(self, evt):
        # Oh, yeah, those constants are real easy to remember!!
        dlg = wx.MessageDialog(self, "I've been clicked!", "wx Sample",
                wx.OK | wx.ICON_INFORMATION)
        # We have to tell the dialog to show itself...
        dlg.ShowModal()
        # and then remember to release it afterwards.
        dlg.Destroy

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frm = WxDemoFrame(None, -1)
    # OK, now we have to tell Python to show the form
    # Shouldn't this be by default?
    frm.Show(1)
    app.MainLoop()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Now here's the same thing in Dabo:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
import dabo
dabo.ui.loadUI("wx")

class DaboDemoForm(dabo.ui.dForm):
    def afterInit(self):
        # Instead of non-Pythonic setter methods, the Dabo UI uses
        # properties that can be set directly. Also, all objects that
        # display a text string use the same property ('Caption') to
        # manage that text, making it more consistent.
        self.Caption = "This is a Dabo Form"
        # The Width and Height can be set independently, rather than
        # using a single SetSize() method.
        self.Width = 300
        self.Height = 400

    def initChildObjects(self):
# Add the button. We can pass all of the relevant property settings # to the 'addObject()' method, and they will be applied to the resulting
        # control when it is created.
self.addObject(dabo.ui.dButton, Name="btnDabo", Caption="Click Me",
            Width=90, Height=24, Left=50, Top=50)

        # Most controls have an obvious event. Menus get selected,
        # buttons get clicked, check boxes get toggled. Dabo wraps
# these primary events into a single event called 'Hit'. Much easier
        # to remember, and consistent across various controls.
        self.btnDabo.bindEvent(dabo.dEvents.Hit, self.onClick)

    def onClick(self, evt):
        # The Dabo UI has a number of functions built-in that
        # handle the most common needs for displaying messages
# to the user: info (for non-critical messages); stop (for serious
        # problems that require immediate attention); and 'areYouSure',
# for when you want to confirm a potentially critical action by the
        # user. Just pass the message and an optional title, and Dabo
        # handles the rest for you;
        dabo.ui.info(message="I've been clicked", title="Dabo Sample")

if __name__ == '__main__':
    app = dabo.dApp()
    # Just tell Dabo what form class you want to display
    # when the app starts up. Dabo will handle the rest.
    app.MainFormClass = DaboDemoForm
    app.start()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    I hope that this helps you to see the differences.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com




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

Reply via email to