The line "self.data = ..." needs to be moved before the use of the validators.
HTH, Phil
···
At 12:00 PM 10/26/2007, you wrote:
I am having difficulty extrapolating the data transferring validator
example (listing 9.14, pages 286-288 in the wPIA book) to my application. I
will try to clearly explain what I've done and hope it's sufficient to have
someone point out my error(s).The main notebook panel has a button to add new records:
self.fsAddButton = wx.Button(self, wx.ID_ADD, label='Add')
self.Bind(wx.EVT_BUTTON, self.OnAdd, self.fsAddButton)and the method, self.OnAdd, calls a dialog box:
newSet = setDlg()
result = newSet.ShowModal()
if result == wx.ID_OK:
# copy widget values into transfer names.
self.fsName = newSet.fsTerm.GetValue()
self.fsVar = newSet.fsPar.GetValue()
self.fsSubComp = newSet.subName.GetValue()
self.fsComp = newSet.compName.GetValue()
self.fsNum = newSet.fsSeq.GetStringSelection()I'd like to have self.fsVar, self.fsSubComp, and self.fsComp passed to the
dialog box, while self.fsName and self.fsNum is passed back from the dialog
box.This is the setDlg() class with the sizer commands omitted:
class setDlg(wx.Dialog): # Used to add or modify a fuzzy term set
def __init__(self):
wx.Dialog.__init__(self, None, wx.ID_ANY, "Add a New Term Set", size=(800, 400))<sizer data>
seqLab = wx.StaticText(self, wx.ID_ANY, 'Sequence No.: ')
seqList = ['1', '2', '3', '4', '5', '6', '7']
self.fsSeq = wx.Choice(self, wx.ID_ANY, size=wx.Size(75, 25), choices=seqList,
style=wx.TAB_TRAVERSAL|wx.RAISED_BORDER,
validator=NotEmptyValidator())nameLab = wx.StaticText(self, wx.ID_ANY, 'Set Name: ')
self.fsTerm = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(125, 25),
style=wx.TAB_TRAVERSAL|wx.RAISED_BORDER,
validator=DataXferValidator(self.data, "termName"))parLab = wx.StaticText(self, wx.ID_ANY, 'Parent Variable: ')
self.fsPar = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(125, 25),
style=wx.TAB_TRAVERSAL|wx.RAISED_BORDER,
validator=DataXferValidator(self.data, "curParent"))subLab = wx.StaticText(self, wx.ID_ANY, 'Subcomponent: ')
self.subName = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(125, 25),
style=wx.TAB_TRAVERSAL|wx.RAISED_BORDER,
validator=DataXferValidator(self.data, "curSubComp"))compLab = wx.StaticText(self, wx.ID_ANY, 'Component: ')
self.compName = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(125, 25),
style=wx.TAB_TRAVERSAL|wx.RAISED_BORDER,
validator=DataXferValidator(self.data, "curComp"))line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
self.OkBut = wx.Button(self, wx.ID_OK, 'OK')
self.CancelBut = wx.Button(self, wx.ID_CANCEL, 'Cancel')
self.OkBut.SetDefault()<sizer stuff omitted>
self.SetSizer(sizer)
self.Fit()self.data = {"termName" : modFzySet().fzySet,
"curParent" : modFzySet().parVar,
"curSubComp" : modFzySet().subComp,
"curComp" : modFzySet().Comp}The error I see when I click the "Add" button is:
Traceback (most recent call last):
File "/data1/eikos/fuzSetPage.py", line 489, in OnAdd
newSet = setDlg()
File "/data1/eikos/fuzSetPage.py", line 636, in __init__
validator=DataXferValidator(self.data, "termName"))
AttributeError: 'setDlg' object has no attribute 'data'So, I have a syntax error that I don't see. I'd appreciate guidance on how
to have the setDlg dialog box see the data dictionary I set up (or a correct
dictionary if that's the problem).Rich