Sorry to beat this subject to death. Using Paul's example of setting a
fictitious table name as the DataSource when creating a BizObject, I was
able to get multiple bizobjs working independently on the same table.
self.Connection = self.Application.getConnectionByName("myconn")
self.bzCatsAll = Cats(self.Connection,DataSource='cats_all')
self.bzCatsSome = Cats(self.Connection,DataSource='cats_some')
The problem comes when I try to set a grid's DataSource to the fictitious
table name. I cannot get the grid to display the table data.
grid.DataSource = 'cats_all' does not seem to work. Same for 'cats_some'.
I have pasted in a turn-key example to show you what I've done. Can you
point our where I have gone wrong? Gmail eats tab stops so I used spaces
for indenting. Still didn't help much.
Steve Rose
import dabo
import dabo.dEvents as dEvents
import dabo.dException as dException
from dabo.dApp import dApp
from dabo.dLocalize import _
from dabo.db.dConnectInfo import dConnectInfo
dabo.ui.loadUI('wx')
class Cats(dabo.biz.dBizobj):
def afterInit(self):
self.DataSource = "cats"
self.KeyField = "pkid"
self.addFrom("cats")
self.addField("pkid")
self.addField("name")
self.addField("color")
class CatsPanel(dabo.ui.dPanel):
def afterInit(self):
catsGrid1 =
dabo.ui.dGrid(self,AlternateRowColoring=True,ColumnCount=2,RegID='catsGrid1',SelectionMode
="Row",Editable=False,MovableColumns =False,
Searchable=True,Top=50,Left=50,Height=200,Width=300)
catsGrid1.DataSource = 'cats_all'
catsGrid1.Columns[0].DataField = "name"
catsGrid1.Columns[0].Width = 100
catsGrid1.Columns[1].DataField = "color"
catsGrid1.Columns[1].Width = 100
class MainForm(dabo.ui.dForm):
def afterInit(self):
self.Sizer=vs= dabo.ui.dSizer('v')
catsPanel = CatsPanel(self)
self.Caption = "Cats"
self.Connection = self.Application.getConnectionByName("myconn")
self.bzCatsAll = Cats(self.Connection,DataSource='cats_all')
self.bzCatsSome = Cats(self.Connection,DataSource='cats_some')
self.addBizobj(self.bzCatsAll)
self.requery(self.bzCatsAll)
self.requery(self.bzCatsSome)
# test out the bizObjects:
print 'name - cats_all:', self.bzCatsAll.Record.name # prints 'Blackie';
correct
print 'color -cats_all:', self.bzCatsAll.Record.color # prints 'black';
correct
print 'total - cats_all:', self.bzCatsAll.RowCount # prints 6; correct
# navigate in bzCatsSome:
self.next(self.bzCatsSome)
print 'name - cats_some:', self.bzCatsSome.Record.name # prints 'Brownie';
correct
print 'color - cats_some:', self.bzCatsSome.Record.color # prints 'brown'
; correct
#check to see if bzCatsAll record pointer moved after bzCatsSome
navigated:
print 'name - cats_all:', self.bzCatsAll.Record.name # prints 'Blackie';
correct
print 'color -cats_all:', self.bzCatsAll.Record.color # prints 'black';
correct
vs.append1x(catsPanel)
self.catsGrid1.update() # no help in getting grid to display data.
self.catsGrid1.DataSource = ""
self.catsGrid1.DataSource = 'cats_all' # reasserted grid DataSource but no
help.
if __name__ == "__main__":
app = dabo.dApp()
# Manages how preferences are saved
app.BasePrefKey = "dabo.app.minimal.dtForm"
dabo.settings.MDI = False
app.MainFormClass = MainForm
## The following information can be used in various places in your app:
app.setAppInfo("appShortName", _("Cats Form"))
app.setAppInfo("appName", _("Cats"))
app.setAppInfo("appDescription", _("Cats and colors"))
## Connections:
dbFileName = ":memory:"
connInfo = dConnectInfo(Name="myconn",
DbType="SQLite",Database=dbFileName)
app.addConnectInfo(connInfo)
## create database on the fly:
conn = app.getConnectionByName("myconn")
curs= conn.getDaboCursor()
# create tables and testdata:
scriptList = """
create table cats (
pkid integer primary key autoincrement not null,
name text,
color text
);
insert into cats (name,color) values ('Blackie','black');
insert into cats (name,color) values ('Brownie','brown');
insert into cats (name,color) values ('Snowflake','white');
""".split(";")
for stmt in scriptList:
if stmt.strip():
curs.execute(stmt)
dabo.infoLog.write(stmt)
app.setup()
app.start()
--- StripMime Report -- processed MIME parts ---
multipart/alternative
text/plain (text body -- kept)
text/html
---
_______________________________________________
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/%(messageid)s