On Wednesday 28 February 2007 19:00, Ken Dibble wrote:
> Hi John.
>
> Platform: Win
> Python Version: 2.4.4 on win32
> Dabo Version: Version 0.8a; Revision
> UI Version: 2.6.3.3 on wxMSW
>
> I don't think I'm being dense. I took a couple days off to clear my head
> and came back to this. Below is my code and the form .cdxml file, which
> still don't work as I expect, with comments.
>
> To summarize:
>
> I can make a grid work just like it does in the Wiki How-To for populating
> a grid. That strongly suggests to me that I'm doing everything right with
> regard to setting up the database in MySQL, creating a connection in Dabo,
> and accessing the proper biz object, DataSource, and fields.
>
> So then, insofar as possible, I use the exact same database, table, and
> Dabo code to bind a textbox to a single field in in my table and populate
> it by requesting 1 record, and it doesn't work. Instead, the GRID shows the
> one row I want, and the textbox shows nothing. If I get rid of the grid and
> just do the textbox thing with everything else the same, it doesn't do
> anything at all.
>
> As best I can tell, it should work. Please try to show me the exact point
> where I'm wrong.
>
> Thanks.
>
> Ken Dibble
> www.stic-cil.org
>
You are using a cdxml file that you created using the ClassDesigner.
Therefore, the connection information is not required. It does not hurt.
You also don't need to reset the business objects because they were created
and set when you created the cdxml file from ClassDesigner.
See comments in line:
> ## *!* ## Dabo Code ID: dButton-dForm
> def onHit(self, evt):
> # Code from the wiki How-To:
> # This connection works fine, as the rest of this code
> # demonstrates.
>
> self.Form.Application.addConnectFile("C:\DaboProjects\MyMusic\mymusic.cnxml
>")
>
> # Code from the wiki How-To:
> conn = self.Form.Application.getConnectionByName("main")
>
> # Code from the wiki How-To:
> biz = dabo.biz.dBizobj(conn)
>
> # Code from the wiki How-To:
> # These items are correct, as the grid will demonstrate.
> biz.DataSource = "musSongs"
> biz.KeyField = "pkid"
>
> # Code from the wiki How-To (don't know why; it doesn't
> # seem to serve any purpose, like giving me a form-level
> # reference to the biz object that I can use, but if
> # I comment it out, the grid doesn't populate):
> # Add it to the form's collection of bizobj references
> self.Form.addBizobj(biz)
It appears that you are adding the same bizobj to the form that you created in
ClassDesigner - but I think it should still work.
>
> # Code from the wiki How-To:
> # These items are correct, as the grid will demonstrate.
> # Now set up the fields
> biz.addField("pkid")
> biz.addField("songname")
> biz.addField("compdate")
>
> # Code from the wiki How-To:
> # Run the query
> biz.requery()
We are still in the onHit method and you are updating the bizobj but not
telling the form. Therefore, to tell the form about the new data from this
method you would:
self.Form.requery()
But I doubt you should do anything at this point because you have not set the
where clause.
>
> # Code from the wiki How-To (works perfectly; if I
> # don't enter a number in the keyBox textbox, all of my
> # songs appear in the grid. This indicates that:
> # 1. The MySQL database is configured properly for
> # Dabo.
> # 2. The connection is configured properly in Dabo.
> # 3. I'm referring to the proper fields and DataSource.
> # 4. There is data in the table.)
> # The grid may not exist yet; it may be created after
> # this method is run. So use 'callAfter()' to delay
> # populating the grid until we know it is ready.
> dabo.ui.callAfter(self.Form.populateGrid)
>
> # Now try to show just one song in the thisSong textbox,
> # assuming the user entered a number in the keyBox. If
> # s/he didn't, the following code doesn't do anything
> # that I can see.
> myPK = self.Form.keyBox.Value
Good this gets the data from the textbox
>
> # Assuming I put 3 in the keyBox,Prints 3, as I'd expect.
> print myPK
>
> biz.setWhereClause("musSongs.pkid = " + myPK)
OK this will work and you have set the where clause.
>
> # Assuming I put 3 in the keyBox, this prints
> # "musSongs.pkid = 3", also as I'd suspect.
> # This tells me that the query is going to be correct.
> print biz._CurrentCursor.sqlManager._whereClause
>
> biz.requery()
Again you are refreshing the bizobj but telling the form.
>
> # At this point, the grid shows one row--the row I
> # wanted--but the thisSong texbox shows nothing.
> dabo.ui.callAfter(self.Form.showSong)
Where are you setting the value for thisSong textbox?
Assuming "self.Form.thisSong" is what we want to update then you need to set
it's Value somehow.
as in (self.Form.thisSong.Value = the field or somestring or whatever)
But in this case the (self.Form.requery()) should refresh the Value of the
thisSong textbox. This assumes that you set two attributes of the textbox
correctly.
1. DataSource
2. DataField
You could also set the two attributes in code as in:
self.Form.thisSong.DataField = the field name ("songname" I think)
self.Form.thisSong.DataSource = the table name ("musSongs")
>
> ## *!* ## Dabo Code ID: dForm-top
> def afterInit(self):
> # Even though I do this again in the button's onHit,
> # I do it here because the form will not run if there's
> # no code in this method.
>
> self.Application.addConnectFile("C:\DaboProjects\MyMusic\mymusic.cnxml")
>
> def populateGrid(self):
> # Just like in the Wiki How-To:
> self.gridKen.DataSource = "musSongs"
>
> def showSong(self):
> # Just like in the Wiki How-To except it's a dTextBox
> # instead of a dGrid.
> self.Form.thisSong.DataSource = "musSongs"
Ok this could work but you forgot the DataField
I was hoping you would send me the two files:
1. the cdxml file
1. the *-code.py file
send it to me via my email because dabo does not accept attachments.
below is my code for onHit(self,evt)
self.Form.thisSong.DataField = "songname"
self.Form.thisSong.DataSource = "musSongs"
# I only do above in case you did not set the attributes in ClassDesigner.
myLocalBiz = self.Form.getBizobj("musSongs") # created in ClassDesigner
myLocalBiz .setWhereClause("musSongs.pkid = " + myPK) #reset the data
self.Form.requery() # this should refresh the form/screen
I hope this helps!
--
John Fabiani
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users