[dabo-users] forcing bizobj to recognize ui change & exception

Author: Miguel Lopes

Posted: 2009-07-12 at 07:39:36

My main form is composed of navigation on the left and a

dPageFrameNoTabs on the right.

Every time I want to display a new page I click on a button in the navigator.

This not only changes de current Page, also lazy loads it (if

unloaded) and changes the primary bizobj if need (loads bizobjs if not

loaded and assigns then to the fom).

Everything was working very well until I tried to trap for changes in

the ui before changing page.

I needed to do this because if I changed a couple of textboxes and

then navigated to a new page, Dabo would not be aware of the changes.

1. So a question (and the fast way to solving my problem) is:

How can I force Dabo to recognize there are changes?

If I'm able to do this, then I can check for them and avoid all the

subsequent problems.

2. Here's what I've tried and the woes I got!

After failed attempts at using confirmChanges() and isAnyChanged(), I

tried form.requery() but this gives raise to a strange exception when

I pressed "Yes" on the save changes dialog. If I press "No" everything

works well, and if I press "Cancel" the navigation happens without

problems and when I get back to the Page I get the dialog again!

Traceback (most recent call last):

File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dControlMixin.py",

line 27, in _onWxHit

self.raiseEvent(dEvents.Hit, evt, *args, **kwargs)

File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dPemMixin.py",

line 949, in raiseEvent

super(dPemMixin, self).raiseEvent(eventClass, nativeEvent, *args, **kwargs)

File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/lib/eventMixin.py",

line 93, in raiseEvent

bindingFunction(event)

File "/Users/miguel/Documents/programming/daboprgs/HandCoding_02/ui/MainForm.py",

line 92, in onAppModuleNav

self.requery(self.PrimaryBizobj)

File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dForm.py",

line 473, in requery

if not self.confirmChanges(bizobjs=bizobj):

File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dForm.py",

line 165, in confirmChanges

self.save(dataSource=biz.DataSource)

TypeError: save() got an unexpected keyword argument 'dataSource'

My code is:

def onAppModuleNav(self, evt):

"""Navigate to application module.

Loads the module if not loaded yet!

NOTE: Toolbar updates automagically in each page.

"""

self.requery()

# if self.PrimaryBizobj.isAnyChanged(useCurrentParent=None): #

Doesn't work

# self.confirmChanges()

caption = evt.EventObject.Caption

self.navToModule(caption)

self.requery()

def navToModule(self, caption):

"""Takes a module page name as argument.

Get the corresponding class and, if not instanciated,

instanciate it and load it.

"""

for label,klass in APP_MODULES:

if label == caption:

page = klass

break

mainPanel = self.splitter.Panel2

# Check if module main page is already instanciated

for pg in mainPanel.Pages:

if isinstance(pg, page):

page = pg

break

# if we are already on the right page exit

if mainPanel.SelectedPage == page:

return

else:

try:

# if there is a selected page

self.removeModuleToolBar(mainPanel.SelectedPage)

except AttributeError:

pass

# SET PRIMARY BIZOBJ

self.changePrimaryBizobj(page)

try:

# if already loaded & page is instance

mainPanel.showPage(page)

self.showModuleToolBar(mainPanel.SelectedPage)

except AttributeError:

# page is not loaded & is class

PageClass = page

mainPanel.appendPage(PageClass, makeActive=True)

self.loadModuleToolbar(mainPanel.SelectedPage)

def changePrimaryBizobj(self, modulePageReference):

"""Uses the modulePageReference to access its class attributes

bizobjData.

bizobjData is a dict containing: datasource, bizobj, childBizobjs.

Tries to get the bizobj by datasource & if needed creates one,

its children, and

assigns it as the primaryBozobj of the MainForm.

Notes:

"""

newPrimaryBizobj =

self.getBizobj(modulePageReference.bizobjData['datasource'])

if newPrimaryBizobj == None:

# bizobj does not exists - instanciate it

newPrimaryBizobj =

modulePageReference.bizobjData['bizobj'](self.Connection)

self.addBizobj(newPrimaryBizobj)

for klass in modulePageReference.bizobjData['childBizobjs']:

childBiz = klass(self.Connection)

newPrimaryBizobj.addChild(childBiz)

self.PrimaryBizobj = newPrimaryBizobj

Txs for all the help,

Miguel

©2009 Miguel Lopes