david whiting wrote:
OK. This sounds similar to the way I used to do this with Foxpro. I
had a single .PRG file with a main fld_valid() function that called
other functions that implemented the validation rules for each
control. In the VALID() clause of each control I just called
fld_valid() and sent the control name and the value entered, so it was
(almost) always the same for every control. This then returned .T. or
.F. depending on whether the data were valid.
I would try to do something similar with dabo: have the function
access the validation rule in the bizobj. But I think my desires are
somewhat ahead of my abilities at the moment and I need to learn more
python. I think I'll try something a little simpler to begin with.
I just wrote up a quick demo of how you can trap dEvents.LostFocus to
interact with a form method fldValid(). While this isn't really the way
we want people using Dabo (writing biz rules in the UI layer) it demos
how to trap LostFocus to implement this. An extension of this demo would
make a bizobj subclass that defines a fieldValidate() function, and the
form's fldValid() would call that bizobj function to determine whether
to keep focus on the control and somehow (dabo.ui.stop()?) communicate
the problem to the user.
The demo is in the dabodemo/tutorial directory in the latest Subversion.
I've also copied/pasted it here for your review. I hope it helps!
#-- begin demo
import dabo
import dabo.dEvents as dEvents
app = dabo.dApp(MainFormClass=None)
app.setup()
class Txt(dabo.ui.dTextBox):
def initEvents(self):
self.bindEvent(dEvents.GotFocus, self.onGotFocus)
self.bindEvent(dEvents.LostFocus, self.onLostFocus)
def onGotFocus(self, evt):
print "onGotFocus for %s" % self.Name
def onLostFocus(self, evt):
print "onLostFocus for %s" % self.Name
print self.Form.fldValid(self)
class MyForm(dabo.ui.dForm):
def afterInit(self):
pan = self.addObject(dabo.ui.dPanel, Size=(200,200))
pan.addObject(Txt, Name="txtName")
pan.addObject(Txt, Name="txtPhone", Top=100)
def fldValid(self, obj):
print "fldValid for %s" % obj.Name
ret = True
if obj.Name == "txtPhone":
if len(obj.Value) < 8:
ret = False
if not ret:
obj.setFocus()
return ret
frm = MyForm()
app.MainForm=frm
frm.show()
app.start()
#-- end demo
--
Paul McNett
http://paulmcnett.com
http://dabodev.com
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users