Hi, I'm finally on to my first real project in Dabo/Python. I will
attempt to duplicate a system I've developed in VFP. It is a data driven
menu system which allows defining queries to different databases, define
variables to be user-filled,  combining the queries and outputting the
result to Excel files (very simplified description). I will be
versioning it (Bazaar), including any mail exchange/comments regarding
the system and, if Ed allows it, uploading it to Dabo's site.
Here goes my initial code. This is just an empty form that will display
the menu (it may end up as just a toolbar) and call another form which
will allow the input of filter data and perform the queries and output
routines.
Now I want to read the menu definition (getFullMenuBarList()) from
several tables in a sqlite database, and I'm wondering which would be my
best path. I think this does not call for a BizObj as I won't need to
update or insert data here, but I will be needing a couple of queries
and some processing to get my menuList, I think I would do this with
temporary cursors (Ha! Haven't even read the docs about temp cursors).
What would your advise be?

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# -*- coding: utf-8 -*-

##------------  Just for testing -------------##
def doOpen(evt):
    dabo.ui.info("'Open' option clicked", title='Info!')

def doClose(evt):
    dabo.ui.info("'Close' option clicked", title='Info!')

def doEdit(evt):
    dabo.ui.info("'Edit' option clicked", title='Info!')

def doSO1(evt):
    dabo.ui.info("'Sub-Option1' option clicked", title='Info!')

def doSO2(evt):
    dabo.ui.info("'Sub-Option2' option clicked", title='Info!')
##--------------------------------------------##

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

##----- These will probably end up in a business rules file -----##
def getFullMenuBarList() :
    # This will eventually come from an sqlite database
    menuList = [MMenu('&File', [MMOption('Open', doOpen, 'Ctrl-O', 'Open
a file')
                                , MMOption('Close', doClose, 'Ctrl-L',
'Close a file')
                                , MMOption('Separator')
                                , MMOption('Edit', doEdit, 'Ctrl-E',
'Edit a file')
                                , MMenu('SubMenu',
[MMOption('Sub-Option1', doSO1, help='Sub Option 1')
                                                    ,
MMOption('Sub-Option2', doSO2, help='Sub Option 2')
                                                    ]
                                        )
                                ]
                      )
                , MMenu('&Edit', [])
                ]
    return menuList

def getIniParamDict() :
    # parameters will be read from an .ini file / Is there something in
Dabo? or just use ConfigParser module?
    parDict = {'MainFormCapt' : 'Multi Menu'}
    return parDict
##---------------------------------------------------------------##

class MMenu(object) :
    def __init__(self, caption, contents) :
        self.caption = caption
        self.contents = contents

class MMOption(object) :
    def __init__(self, caption, action=None, hotKey='', help='') :
        self.caption = caption
        self.action = action
        self.hotKey = hotKey
        self.help = help
    def isSeparator(self) :
        return (self.caption.lower() == 'separator'
                and not self.action
                and not self.hotKey
                and not self.help)

class MultiMenuBar(dabo.ui.dMenuBar):
    def _afterInit(self) :
        super(MultiMenuBar, self)._afterInit()
        self.populateMB(getFullMenuBarList())
    def populateMB(self, MBList) :
        for item in MBList :
            menu = self.append(item.caption)
            self.populateMenu(menu, item.contents)
    def populateMenu(self, menu, contentList) :
        for item in contentList :
            if isinstance(item, MMenu) :
                subMenu = dabo.ui.dMenu(Caption=item.caption)
                menu.appendMenu(subMenu)
                self.populateMenu(subMenu, item.contents)
            elif isinstance(item, MMOption) :
                if item.isSeparator() :
                    menu.appendSeparator()
                else :
                    menu.append(item.caption, HotKey=item.hotKey,
OnHit=item.action, help=item.help)

def main():
    app = dabo.dApp(MainFormClass=None)
    app.setup()

    iPD = getIniParamDict()       
    form = dabo.ui.dForm(app.MainForm, Caption=iPD['MainFormCapt'],
MenuBarClass=MultiMenuBar)

    panel = dabo.ui.dPanel(form)
    panel.BackColor = 'blue'
    form.Sizer.append(panel, 1, 'x')

    form.Maximize()
    form.show()
    app.start()

if __name__ == '__main__':
    main()
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



_______________________________________________
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/[email protected]

Reply via email to