On Sep 12, 2010, at 10:01 AM, Stanislav Colotinschi wrote:
> Hi. I tried to create a menu based on my own class but there's a problem
> that I can't understand. I did something like this in main.py:
>
> [...]
>
> class MainMenu(dabo.ui.dBaseMenuBar):
>
> def initProperties(self):
>
> self.append(caption="&Test")
>
> if __name__=="__main__":
>
> app = dabo.dApp(MainFormClass=None)
>
> app.MenuBarClass = MainMenu
>
> app.setup()
>
> [...]
>
> I tried many possibilities, but I haven't succeeded to append this item
> to the menu. I really don't know how I can do it. Thank you for help.
There are several things that can be improved in this code; Jacek has
already suggested appending the menu in the afterInit() method; that will work,
but will have the effect of *prepending* the menu to the normal items, since
the default menus are created later in the process. Calling the append() from
the afterInitAll() method will do what you probably expect: adding the 'Test'
menu after the default menus.
Another problem is that you are setting the app's 'MenuBarClass'
property, but it doesn't have a property by that name (dabo.ui.dForm does,
however). MenuBars are "owned" by the form that they are associated with. dApp
has a 'DefaultMenuBarClass' property that forms will use if no particular
menubar class has been set in the form's MenuBarClass property.
The main thing that would make this easier for you is to approach it in
the UI layer. You're trying to do things at the uppermost application layer,
when menus are UI elements. I've rewritten your code to use the approach that
is more consistent with the way that Dabo is designed to work: since the form
owns the menu bar, it handles any customization that is needed. Note that by
the time that the form's afterInitAll() fires, the menu bar already exists, and
can be referenced by 'self.MenuBar'. I've also included a line that adds a
simple menu item to the 'Test' menu to demonstrate how this is typically done.
===================================
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import dabo
dabo.ui.loadUI("wx")
class MyMainFormClass(dabo.ui.dForm):
def afterInitAll(self):
testmenu = self.MenuBar.append(caption="&Test")
testmenu.append("Test Item", OnHit=self._onTestItem)
def _onTestItem(self, evt):
dabo.ui.exclaim("Look at me!")
if __name__=="__main__":
app = dabo.dApp(MainFormClass=MyMainFormClass)
app.start()
===================================
I hope that this makes things clearer. Please post any additional
questions you might have.
-- Ed Leafe
_______________________________________________
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]