On Friday 04 September 2009 12:22:26 pm jpoorra...@aol.com wrote: > Dabo ones. > > We're back to trying to integrate forms together using a menu, and we're up > against a number of obstacles. Last Friday Ed, Paul and John had helpful > suggestions on how to proceed, but we're not quite getting it. > > For now, we've decided to go with the quickStart structure. We want to > start up a mainForm that has a logo on it but doesn't do much else. From > the menu at the top of the screen, we want to be able to launch forms that > we've created with the ClassDesigner. > > How do we add our forms to the Menu? We've been trying to use the code from > the AppWizard app that adds forms to the File/Open menu, with no success. > > First, we wanted to see if we could add things to the menu in the > quickstart structure, . We put a form file called "FrmRuns.py" (created by > the appWizard) into our ui directory. > > Our main program looks like this: > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > import dabo > dabo.ui.loadUI("wx") > > app = dabo.dApp() > > # IMPORTANT! Change app.MainFormClass value to the name > # of the form class that you want to run when your > # application starts up. > app.MainFormClass = "randp.cdxml" #dabo.ui.dFormMain > > app.setup() > app.start() > > This the same as the standard quickstart main.py, except that we added > app.setup() before the start(), since we figured that setup would call the > _initModuleNames function that loads forms in the .\ui directory into the > app, including the above mentioned FrmRuns.py > > Then we added code from MenFileOpen.py from the appWizard to the afterInit > method of our main form "randp.cdxml" Here's the code we put in the form's > afterInit: > > ## *!* ## Dabo Code ID: dForm-top > def afterInit(self): > app = self.Application > autoHotKeys = True > > # Define the forms you want in your open menu here. Insert a ("-", None) > # tuple and the code below will insert a separator in its place. > Explicitly # set up which character has the hotkey by adding a & in front > of it and # by turning off the autoHotKeys flag. > > forms = (("Runs", app.ui.FrmRuns), > ("-", None), > ) > > for form in forms: > caption = form[0] > if caption == "-": > # insert separator instead: > self.appendSeparator() > else: > if autoHotKeys and "&" not in caption: > caption = "&%s" % caption > plainCaption = caption.replace("&", "") > itm = dabo.ui.dMenuItem(self, Caption=caption, > HelpText="Open the %s module" % plainCaption, > Tag=form[1]) > itm.bindEvent(dEvents.Hit, self.openForm) > self.appendItem(itm) > > > Running python randp.py, we get the error: > > 'module' object has no attribute 'FrmRuns' > > So, clearly, the _intModuleNames isn't picking up this form. > > The second, more serious problem for us is still how we can load our CD > designed cdxml forms into the app.ui so we can call them from a menu. > > Ed suggested using the dabo.ui.createForm function, but his example > instantiates the form as the name MyForm. How can we append the form to the > app.ui as an attribute, which is what the dApp._initModuleNames apparently > does? Could it be as simple as App.ui.FrmRuns = > dabo.ui.createForm("ui\FrmRuns.cdxml")? > > Thanks, > > Jonathan Poor
I'm a little confused where you want to place the menu items. I think you want them under the "File" of the menu. mb = self.Form.MenuBar fileMenu = mb.getMenu("File") ModuleMenu = dabo.ui.dMenu(Caption="Select Module") ModuleMenu.append('SomeForm',help='Open SomeForm', OnHit=self.loadSomeForm) fileMenu.insertMenu(1, ModuleMenu) def loadSomeForm(self,evt): frm=dabo.ui.createForm('somestring') frm.show() all this depends on when you add the menu to the form. I often do it in afterInitAll() Johnf --- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html --- _______________________________________________ Post Messages to: Dabo-users@leafe.com 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/200909041253.58926.jfabi...@yolo.com