Index
2009-07-12 07:39 – Miguel Lopes : [dabo-users] forcing bizobj to recognize ui change & exception
2009-07-12 08:25 – Miguel Lopes : Re: [dabo-users] forcing bizobj to recognize ui change & exception
2009-07-12 09:02 – Ed Leafe : Re: [dabo-users] forcing bizobj to recognize ui change & exception
2009-07-12 09:33 – Miguel Lopes : Re: [dabo-users] forcing bizobj to recognize ui change & exception
2009-07-12 09:40 – Ed Leafe : Re: [dabo-users] forcing bizobj to recognize ui change & exception
2009-07-12 10:03 – Miguel Lopes : Re: [dabo-users] forcing bizobj to recognize ui change & exception
2009-07-12 10:06 – Miguel Lopes : Re: [dabo-users] forcing bizobj to recognize ui change & exception
2009-07-12 11:38 – Ed Leafe : Re: [dabo-users] forcing bizobj to recognize ui change & exception
2009-07-12 12:04 – Miguel Lopes : Re: [dabo-users] forcing bizobj to recognize ui change & exception
2009-07-12 12:38 – Ed Leafe : Re: [dabo-users] forcing bizobj to recognize ui change & exception
Back to top
[dabo-users] forcing bizobj to recognize ui change & exception

Author: Miguel Lopes

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

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
Back to top
Re: [dabo-users] forcing bizobj to recognize ui change & exception

Author: Miguel Lopes

Posted: 2009-07-12 08:25:06   Link

On Sun, Jul 12, 2009 at 12:39 PM, Miguel Lopes<mig.e.lopes@gmail.com> wrote:

>

> 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!

Also self.PrimaryBizobj.getChangedRows(includeNewUnchanged=True)

returns an empty list. Should it not return a the current record

(since I changed something in the ui)?

Miguel

©2009 Miguel Lopes
Back to top
Re: [dabo-users] forcing bizobj to recognize ui change & exception

Author: Ed Leafe

Posted: 2009-07-12 09:02:45   Link

On Jul 12, 2009, at 6:39 AM, Miguel Lopes wrote:

> 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'

Did you override the save() method of your form? If so, can you post

your modified save()?

-- Ed Leafe

©2009 Ed Leafe
Back to top
Re: [dabo-users] forcing bizobj to recognize ui change & exception

Author: Miguel Lopes

Posted: 2009-07-12 09:33:50   Link

On Sun, Jul 12, 2009 at 2:02 PM, Ed Leafe<ed@leafe.com> wrote:

> On Jul 12, 2009, at 6:39 AM, Miguel Lopes wrote:

>

>> =A0File "/Library/Frameworks/Python.framework/Versions/2.5/lib/

>> python2.5/site-packages/dabo/ui/uiwx/dForm.py",

>> line 165, in confirmChanges

>> =A0 =A0self.save(dataSource=3Dbiz.DataSource)

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

>

> =A0 =A0 =A0 =A0Did you override the save() method of your form? If so, ca=

n you post

> your modified save()?

>

>

> -- Ed Leafe

Well, not much of an override!

def save(self, evt): self.super()

Miguel

©2009 Miguel Lopes
Back to top
Re: [dabo-users] forcing bizobj to recognize ui change & exception

Author: Ed Leafe

Posted: 2009-07-12 09:40:31   Link

On Jul 12, 2009, at 8:33 AM, Miguel Lopes wrote:

> Well, not much of an override!

>

> def save(self, evt): self.super()

That's your problem: you've overridden a framework method and changed

the interface. Delete that and the error should go away.

Also, the use of 'evt' indicates to me that you are using save() as

an event handler. Don't confuse handlers with regular methods; it's

typically better to do something like:

def onSave(self, evt):

self.save()

This way it is clear that onSave() is there to handle the event, and

it handles it by calling the save() method.

-- Ed Leafe

©2009 Ed Leafe
Back to top
Re: [dabo-users] forcing bizobj to recognize ui change & exception

Author: Miguel Lopes

Posted: 2009-07-12 10:03:39   Link

On Sun, Jul 12, 2009 at 2:40 PM, Ed Leafe<ed@leafe.com> wrote:

> On Jul 12, 2009, at 8:33 AM, Miguel Lopes wrote:

>

>> Well, not much of an override!

>>

>> =A0 =A0def save(self, evt): self.super()

>

> =A0 =A0 =A0 =A0That's your problem: you've overridden a framework method =

and changed

> the interface. Delete that and the error should go away.

>

> =A0 =A0 =A0 =A0Also, the use of 'evt' indicates to me that you are using =

save() as

> an event handler. Don't confuse handlers with regular methods; it's

> typically better to do something like:

>

> def onSave(self, evt):

> =A0 =A0 =A0 =A0self.save()

>

> =A0 =A0 =A0 =A0This way it is clear that onSave() is there to handle the =

event, and

> it handles it by calling the save() method.

>

>

>

> -- Ed Leafe

>

Ok! I clean that up. But still, if I do a change in the current record

and then navigate to a different page Dabo doesn't recogine the

existence of changes. I still have the behavior of recognizing changes

when I go back to the page.

If I issue self.PrimaryBizobj.getChangedRows(includeNewUnchanged=3DTrue)

has a first call on my onAppModuleNav(self, evt) method I get an empty

list!

Using self.requery() works but there are some caveats:

* I would rather not query the database if there's no need for that,

and here it makes no sense to do it!

* Chosing "Yes" or "No" in the "Do you wish to save your changes

dialog" works well. "No" aborts the method, "Yes" saves and moves on.

* But "Cancel" does not stop the method, navigates away and remains

active when I came back. It makes sense its active since neither Yes

nor No was choosen! But it should also abort navigation.

* I checked the return value of self.requery(). Seems like it's bugged:

* "Yes" returns True

* "Cancel" returns None

* "No" returns True. Should it not return False?

Miguel

©2009 Miguel Lopes
Back to top
Re: [dabo-users] forcing bizobj to recognize ui change & exception

Author: Miguel Lopes

Posted: 2009-07-12 10:06:58   Link

On Sun, Jul 12, 2009 at 3:03 PM, Miguel Lopes<mig.e.lopes@gmail.com> wrote:

> On Sun, Jul 12, 2009 at 2:40 PM, Ed Leafe<ed@leafe.com> wrote:

>> On Jul 12, 2009, at 8:33 AM, Miguel Lopes wrote:

>>

>>> Well, not much of an override!

>>>

>>> =A0 =A0def save(self, evt): self.super()

>>

>> =A0 =A0 =A0 =A0That's your problem: you've overridden a framework method=

and changed

>> the interface. Delete that and the error should go away.

>>

>> =A0 =A0 =A0 =A0Also, the use of 'evt' indicates to me that you are using=

save() as

>> an event handler. Don't confuse handlers with regular methods; it's

>> typically better to do something like:

>>

>> def onSave(self, evt):

>> =A0 =A0 =A0 =A0self.save()

>>

>> =A0 =A0 =A0 =A0This way it is clear that onSave() is there to handle the=

event, and

>> it handles it by calling the save() method.

>>

>>

>>

>> -- Ed Leafe

>>

>

> Ok! I clean that up. But still, if I do a change in the current record

> and then navigate to a different page Dabo doesn't recogine the

> existence of changes. I still have the behavior of recognizing changes

> when I go back to the page.

>

> If I issue self.PrimaryBizobj.getChangedRows(includeNewUnchanged=3DTrue)

> has a first call on my onAppModuleNav(self, evt) method I get an empty

> list!

>

> Using self.requery() works but there are some caveats:

> * I would rather not query the database if there's no need for that,

> and here it makes no sense to do it!

> * Chosing "Yes" or "No" in the "Do you wish to save your changes

> dialog" works well. "No" aborts the method, "Yes" saves and moves on.

> * But "Cancel" does not stop the method, navigates away and remains

> active when I came back. It makes sense its active since neither Yes

> nor No was choosen! But it should also abort navigation.

> * I checked the return value of self.requery(). Seems like it's bugged:

> =A0 =A0 =A0 =A0 =A0* "Yes" returns True

> =A0 =A0 =A0 =A0 =A0* "Cancel" returns None

> =A0 =A0 =A0 =A0 =A0* "No" returns True. Should it not return False?

>

> Miguel

>

Correction!

"No" does not abort the method. It discards changes and proceeds with

navigation.

Sorry for the mistake.

Miguel

©2009 Miguel Lopes
Back to top
Re: [dabo-users] forcing bizobj to recognize ui change & exception

Author: Ed Leafe

Posted: 2009-07-12 11:38:27   Link

On Jul 12, 2009, at 9:03 AM, Miguel Lopes wrote:

> If I issue self.PrimaryBizobj.getChangedRows(includeNewUnchanged=True)

> has a first call on my onAppModuleNav(self, evt) method I get an empty

> list!

OK, now you're crossing levels way too deeply. The form should only

work through the main methods that talk to the bizobj such as

confirmChanges().

You say that you've changed some values, but confirmChanges() did not

do anything, indicating that there were no changes in the bizobj. Can

you verify that the controls that were changed were indeed bound to

the bizobj? I.e., that their DataSource was the bizobj's DataSource,

and that the DataField was indeed a column in the primary bizobj's

data set? Check for capitalization errors, etc.

-- Ed Leafe

©2009 Ed Leafe
Back to top
Re: [dabo-users] forcing bizobj to recognize ui change & exception

Author: Miguel Lopes

Posted: 2009-07-12 12:04:51   Link

On Sun, Jul 12, 2009 at 4:38 PM, Ed Leafe<ed@leafe.com> wrote:

> On Jul 12, 2009, at 9:03 AM, Miguel Lopes wrote:

>

>> If I issue self.PrimaryBizobj.getChangedRows(includeNewUnchanged=3DTrue)

>> has a first call on my onAppModuleNav(self, evt) method I get an empty

>> list!

>

>

> =A0 =A0 =A0 =A0OK, now you're crossing levels way too deeply. The form sh=

ould only

> work through the main methods that talk to the bizobj such as

> confirmChanges().

>

> =A0 =A0 =A0 =A0You say that you've changed some values, but confirmChange=

s() did not

> do anything, indicating that there were no changes in the bizobj.

True confirmChanges() always returns and never brings the dialog up

and I didn't mess with self.CheckForChanges.

> Can

> you verify that the controls that were changed were indeed bound to

> the bizobj? I.e., that their DataSource was the bizobj's DataSource,

> and that the DataField was indeed a column in the primary bizobj's

> data set? Check for capitalization errors, etc.

Yes this is confirmed. I doubled checked, asserted it. Also, if I save

the changes before trying to navigate I have no problems.

Miguel

©2009 Miguel Lopes
Back to top
Re: [dabo-users] forcing bizobj to recognize ui change & exception

Author: Ed Leafe

Posted: 2009-07-12 12:38:32   Link

On Jul 12, 2009, at 11:04 AM, Miguel Lopes wrote:

> Yes this is confirmed. I doubled checked, asserted it. Also, if I save

> the changes before trying to navigate I have no problems.

Has the control that contains the changed value already lost focus

before you call confirmChanges()? If not, would adding a call to the

form's activeControlValid() method help?

-- Ed Leafe

©2009 Ed Leafe