Alex Tweedly wrote:
I think (having actually tried it) that you're right - generating code
which can be sub-classed is very simple, and automating the creation
of that file when the cdxml file is written should be straightforward.
A couple of tweaks to the createClassText method and I think it will
just work - at least for simple cases. The other way should work (I
think) just as well - but because it can't reuse as much of what's
already done, it would be more effort.
Two hours and it should be ready to look at and critique (and
hopefully by then it will have continued to shrink to the point that
you say "why did that take two hours" :-)
Two hours ! Ha !!
It took much longer partly because I ran into some problems that I
needed Ed and Paul's help to get past.
And also because I paid attention when Ed said :
Adding another thing to test and integrate, even if someone else
wrote the code, when that wasn't moving us closer to established
goals, just seemed counter- productive.
So I decided to get around the "integrate and test" issue by moving my
code (back) out of Class Designer (and other parts of Dabo itself), into
a purely "add-on" bit of code that doesn't need to go into Dabo.
Code is at www.tweedly.org/Python/CreateBaseClass.pys for anyone who
wants to try it. (download and change the name from *.pys to just *.py)
To use, you would add the following lines *before* your own class (see
example later)
# These next three lines added to use the UI from a cdxml file
from CreateBaseClass import CreateBaseClassXmlConverter
conv = CreateBaseClassXmlConverter()
exec conv.classFromXml("p2.cdxml", "frm")
The first arg is the name of the cdxml file - in this case "p2.xml"
The second is (part of) the name of the base class - it will actually be
dForm_<arg2>
You then define your own class, making it derive from this base class, e.g.
class MyForm(dForm_frm):
def afterInit(self):
# the following line MUST be added if the derived class has an
afterInit method
dForm_frm.afterInit(self)
self.counter = 1
def onHit_MyBtn(self, evt):
print "hit"
self.counter += 1
self.txt.Value = "you have hit me %s times" % self.counter
:
Note that because of the order of initialization, if your class has an
afterInit method, you must explicitly call the afterInit of the base class.
The full example (inlcuding the original code (commented) before Class
Designer was used to create the layout) can be found at
www.tweedly.org/Python/p2.pys
--
Alex Tweedly http://www.tweedly.net
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.9.0/368 - Release Date: 16/06/2006
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users