Sibylle Koczian wrote:
> Hello,
> 
> I don't understand the API documentation of dPageFrame.appendPage: the 
> parameters are pgCls, caption, imgKey. pgCls seems to be a reference to the 
> _class_ of the page being added, right? How do I get a reference to the 
> instance to add controls to the page?
> 
> There is no dPageFrame demo which would show how to do it.
> 
> Or should I always create a dPage subclass, complete with the controls i want 
> my page to have? But even then, what if I wanted to add several instances of 
> the same subclass?
> 
> Or what did I miss here?
> 
> Thank you
> Sibylle
> 

The following will not run for you, it's meant as an example:

# -*- coding: utf-8 -*-

import dabo
dabo.ui.loadUI("wx")

from ug import *

from biz import *

class EtypEnumForm(ugForm):
    def initProperties(self):
        # The following won't work, as these aren't properties of dForm
(there must be some
        # magic in the cdxml layer that sets these appropriately). Ed,
can this functionality
        # get moved into main Dabo?

        # The following are taken from the attributes in the cdxml
above, and translate directly:
        self.Name = "EtypEnumForm"
        self.Caption = "EtypEnumForm"
        self.Top = 0
        self.Left = 0
        self.Width = 800
        self.Height = 600

    def createBizobjs(self):
        # EtypEnum
        etypBizobj = EtypBizobj(self.Connection)
        self.addBizobj(etypBizobj)

        enumBizobj = EnumBizobj(self.Connection)
        enumBizobj.addOrderBy("sort_order")
        self.addBizobj(enumBizobj)

        enumBizobj.LinkField = "etyp_iid"
        enumBizobj.FillLinkFromParent = True
        etypBizobj.addChild(enumBizobj)

        etypBizobj.addOrderBy("e_tok")

        #etypBizobj.AutoCommit = True
        #enumBizobj.AutoCommit = True

    def deleteEnum(self):
        # Form
        if self.dGridEnum.Selection[0] < 0:
            dabo.ui.info(message="You have to select a record first.",
title="Information")
            return
        if not dabo.ui.areYouSure(message="Delete selected Enum
record?", title=None,
                        defaultNo=True, cancelButton=False):
            return

        #currow = self.dGridEtyp.CurrentRow
        enumBizobj = self.getBizobj(dataSource="ENUM")

        try:
            enumBizobj.deleteCurrentRecord()
            self.requery()
            self.refresh()
        except Exception, e:
            dabo.errorLog.write(e)
            dabo.ui.info(message="Deletion of current Enum record
failed:\n\n%s" % e, title="Error")

    def deleteEtyp(self):
        # Form
        print "deleteEtyp()"
        if self.dGridEtyp.Selection[0] < 0:
            dabo.ui.info(message="You have to select a record first.",
title="Information")
            return
        if not dabo.ui.areYouSure(message="Delete selected Etyp
record?", title=None,
                        defaultNo=True, cancelButton=False):
            return

        #currow = self.dGridEtyp.CurrentRow
        etypBizobj = self.PrimaryBizobj

        #etypiid = etypBizobj.getDataSet(rowStart=currow, rows=1)[0]['iid']
        #etypBizobj.deleteAllChildren()
        #self.delete(prompt=False)
        try:
            etypBizobj.deleteCurrentRecord()
            self.requery()
            self.refresh()
        except Exception, e:
            dabo.errorLog.write(e)
            dabo.ui.info(message="Deletion of current Etyp record
failed:\n\n%s" % e, title="Error")

    def newEtyp(self):
        self.new()

    def newEnum(self):
        enumBizobj = self.getBizobj(dataSource="ENUM")
        enumBizobj.new()
        self.update()

    def requerybysearch(self):
        val = self.dSearchToken.Value
        etypBizobj = self.getBizobj(dataSource="ETYP")
        if val == None or val == "":
            etypBizobj.setWhereClause("")
            etypBizobj.setParams(())
            #print 'etypBizobj.setWhereClause("")'
        else:
            #print self.dSearchToken.Value
            etypBizobj.setWhereClause("e_tok starting with ?")
            etypBizobj.setParams((self.dSearchToken.Value,))
            #print 'etypBizobj.setWhereClause(starting with...)'
        self.requery()
        self.refresh()

    def afterInit(self):
        # Main sizer and ScrollPanel:
        self.Sizer = dabo.ui.dSizer("v")
        sp = dabo.ui.dScrollPanel(self)
        self.Sizer.append1x(sp, alignment='center')
        sp_vs = sp.Sizer = dabo.ui.dSizer("v")
        sp_vs_hs = dabo.ui.dSizer("h")
        sp_vs.append(sp_vs_hs, "expand", alignment="top")
        hs = dabo.ui.dSizer("h")
        sp_vs_hs.append1x(hs, alignment="top")

        # Search box at top:
        hs.appendSpacer(5)
        hs.append(dabo.ui.dLabel(sp, Name="lblEtyp", Caption="Etyp:"),
alignment="middle")
        hs.append(dabo.ui.dTextBox(sp, RegID="dSearchToken", Width=140,
ForceCase="upper"), "expand", border=5)
        hs.append(dabo.ui.dButton(sp, Caption="Search",
Name="btnSearch", OnHit=self.onHit_btnSearch), alignment="middle", border=5)

        # PageFrame:
        pgf = dabo.ui.dPageFrame(sp)
        pgf.appendPage(Page1)
        pgf.appendPage(Page2)
        pgf.appendPage(Page3)
        sp_vs.append1x(pgf)

        # Save/Cancel/Close buttons aligned to right:
        hs = dabo.ui.dSizer("h")
        sp_vs.append(hs, alignment="right")
        hs.append(dabo.ui.dButton(sp, Caption="Save", Name="btnSave",
OnHit=self.onHit_btnSave), alignment="middle", border=5)
        hs.append(dabo.ui.dButton(sp, Caption="Cancel",
Name="btnCancel", OnHit=self.onHit_btnCancel), alignment="middle", border=5)
        hs.append(dabo.ui.dButton(sp, Caption="Close", Name="btnClose",
DefaultButton=True, OnHit=self.onHit_btnClose), alignment="middle",
border=5)
        self.layout()

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

    def onHit_btnClose(self, evt):
        self.ugFormClose()

    def onHit_btnCancel(self, evt):
        self.cancel()

    def onHit_btnSearch(self, evt):
        self.requerybysearch()


    def _getParentForm(self):
        try:
            return self._parentForm
        except AttributeError:
            return None

    def _setParentForm(self, val):
        self._parentForm = val

    ParentForm = property(_getParentForm, _setParentForm)


class Page1(dabo.ui.dPage):
    def initProperties(self):
        self.Caption = "Browse Etyp"
        self.Name = "pgBrwEtyp"

    def afterInit(self):
        # Main sizer:
        self.Sizer = dabo.ui.dSizer("h")

        # Left side (Etyp):
        vs = dabo.ui.dSizer("v")
        self.Sizer.append1x(vs)
        vs.append(dabo.ui.dLabel(self, FontBold=True, Caption="Etyp"),
border=5, alignment="center")
        grid = dabo.ui.dGrid(self, RegID="dGridEtyp", DataSource="ETYP",
                             BorderStyle='Simple',
                             SelectionMode="Row", MultipleSelection=False)
        grid.addColumn(Caption="Token", DataField="e_tok")
        grid.addColumn(Caption="Value", DataField="e_val")
        vs.append1x(grid, border=5)

        # Right side (Enum):
        vs = dabo.ui.dSizer("v")
        self.Sizer.append1x(vs)
        vs.append(dabo.ui.dLabel(self, FontBold=True, Name="dLabel1",
Caption="Enum"), border=5, alignment="center")
        grid = dabo.ui.dGrid(self, RegID="dGridEnum", DataSource="ENUM",
                             BorderStyle='Simple',
                             SelectionMode="Row", MultipleSelection=False)
        grid.addColumn(Caption="Token", DataField="e_tok")
        grid.addColumn(Caption="Value", DataField="e_val")
        vs.append1x(grid, border=5)


class Page2(dabo.ui.dPage):
    def initProperties(self):
        self.Caption = "Edit Etyp"
        self.Name = "pgEditEtyp"

    def afterInit(self):
        # Main sizer:
        self.Sizer = dabo.ui.dSizer("v")

        # The labels and textboxes in a gridsizer:
        #gs = dabo.ui.dGridSizer(HGap=5, VGap=5, MaxDimension="r",
Cols=2, Rows=2)
        gs = dabo.ui.dGridSizer(HGap=5, VGap=5, MaxCols=2)
        self.Sizer.append1x(gs, border=10)
        gs.append(dabo.ui.dLabel(self, Caption="Token:"))
        gs.append(dabo.ui.dTextBox(self, DataSource="ETYP",
DataField="e_tok", ForceCase="upper"), "expand")
        gs.append(dabo.ui.dLabel(self, Caption="Value:"))
        gs.append(dabo.ui.dTextBox(self, DataSource="ETYP",
DataField="e_val"), "expand")
        gs.setColExpand(True, 1)

        # The New/Delete buttons, centered at the bottom:
        hs = dabo.ui.dSizer("h")
        hs.append(dabo.ui.dButton(self, Caption="New",
Name="btnNewEtyp", OnHit=self.onHit_btnNewEtyp), "expand", border=5)
        hs.append(dabo.ui.dButton(self, Caption="Delete",
Name="btnDeleteEtyp", OnHit=self.onHit_btnDeleteEtyp), "expand", border=5)
        self.Sizer.append(hs, alignment="center")

    def onHit_btnNewEtyp(self, evt):
        self.Form.newEtyp()

    def onHit_btnDeleteEtyp(self, evt):
        self.Form.deleteEtyp()


class Page3(dabo.ui.dPage):
    def initProperties(self):
        self.Caption = "Edit Enum"
        self.Name = "pgEditEnum"

    def afterInit(self):
        # Main sizer:
        self.Sizer = dabo.ui.dSizer("v")

        # label and textbox in a gridsizer:
        #gs = dabo.ui.dGridSizer(HGap=5, VGap=5, MaxDimension="r",
Cols=2, Rows=1)
        gs = dabo.ui.dGridSizer(HGap=5, VGap=5, MaxCols=2)
        gs.setColExpand(True, 1)
        self.Sizer.append(gs, "expand", border=10)
        gs.append(dabo.ui.dLabel(self, Caption="Etyp Token:", Width=67))
 ## Setting Width here makes the label wrap to match the cdxml
        gs.append(dabo.ui.dTextBox(self, DataSource="ETYP",
DataField="e_tok", ForceCase="upper", ReadOnly=True), "expand")

        # Separator line:
        self.Sizer.append(dabo.ui.dLine(self), "expand")

        # The labels and textboxes in a gridsizer:
        #gs = dabo.ui.dGridSizer(HGap=5, VGap=5, MaxDimension="r",
Cols=2, Rows=6)
        gs = dabo.ui.dGridSizer(HGap=5, VGap=5, MaxCols=2)
        gs.setColExpand(True, 1)
        self.Sizer.append1x(gs, border=10)
        gs.append(dabo.ui.dLabel(self, Caption="Token:"))
        gs.append(dabo.ui.dTextBox(self, DataSource="ENUM",
DataField="e_tok", ForceCase="upper"), "expand")

        gs.append(dabo.ui.dLabel(self, Caption="Value:"))
        gs.append(dabo.ui.dTextBox(self, DataSource="ENUM",
DataField="e_val"), "expand")

        gs.append(dabo.ui.dLabel(self, Caption="Str1:"))
        gs.append(dabo.ui.dTextBox(self, DataSource="ENUM",
DataField="e_str1"), "expand")

        gs.append(dabo.ui.dLabel(self, Caption="Str2:"))
        gs.append(dabo.ui.dTextBox(self, DataSource="ENUM",
DataField="e_str2"), "expand")

        gs.append(dabo.ui.dLabel(self, Caption="Str3:"))
        gs.append(dabo.ui.dTextBox(self, DataSource="ENUM",
DataField="e_str3"), "expand")

        gs.append(dabo.ui.dLabel(self, Caption="Sort Order:", Width=67))
 ## see above "width" comment
        gs.append(dabo.ui.dTextBox(self, DataSource="ENUM",
DataField="sort_order"), "expand")

        # The New/Delete buttons, centered at the bottom:
        hs = dabo.ui.dSizer("h")
        hs.append(dabo.ui.dButton(self, Caption="New",
Name="btnNewEnum", OnHit=self.onHit_btnNewEnum), "expand", border=5)
        hs.append(dabo.ui.dButton(self, Caption="Delete",
Name="btnDeleteEnum", OnHit=self.onHit_btnDeleteEnum), "expand", border=5)
        self.Sizer.append(hs, alignment="center")

    def onHit_btnNewEnum(self, evt):
        self.Form.newEnum()

    def onHit_btnDeleteEnum(self, evt):
        self.Form.deleteEnum()


if __name__ == "__main__":
    import os, sys
    #app = dabo.dApp(MainFormClass=None)
    app = ugApp(MainFormClass=None)
    app.Charset = 'UTF8'
    app.setup()
    logfile = sys.stdout
    app.DatabaseActivityLog = logfile
    frm = EtypEnumForm(CxnName="fbtool_dev", CxnFile="path://fwadm.cnxml")
    frm.show()
    app.start()



_______________________________________________
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/[EMAIL PROTECTED]

Reply via email to