From: Andy T. <an...@cr...> - 2001-09-03 01:36:11
|
Morning all, I take a couple of days away from e-mail and the list goes bananas. Maybe I should take a couple of weeks off ;-) Anyway, Ron, you are almost there, I've annotated the lines you need to change; Ronald D Stephens wrote: > PythonCard file, aaa.py > > #!/usr/bin/python > > """ > __version__ = "$Revision: 1.1 $" > __date__ = "$Date: 2001/08/06 20:32:41 $" > """ > > import PythonCardPrototype > from PythonCardPrototype.loader import configOptions > import os, sys > > class aaa(PythonCardPrototype.model.Background): > > def on_menuFileExit_select(self, menu, event): > self.Close() > > > def displayResult(self,result): > self.components.sldResult.value=int(result) > > def on_sld1_select(self,target,event): > result = self.calcResult() > self.displayResult(result) > > > def on_bgMin_select(self,target,event): > name = target.name > if name[:3] == 'sld' and int(name[:3]) in [1,2,3,4]: > self.displayResult(self.calcResult()) > > > if __name__ == '__main__': > base, ext = os.path.splitext(sys.argv[0]) > filename = base + ".rsrc.py" > > configOptions() > > app = PythonCardPrototype.model.PythonCardApp(filename) > app.MainLoop() > __________________________________________________________ > ________________________________________________________ > > > aaa.rsrc.py > > {'stack':{'type':'Stack', > 'name':'Template', > 'title':'Template Resource', > 'position':(66, 0), > 'size':(500, 600), > > 'backgrounds': [ > {'type':'Background', > 'file':'template.py', -- 'file':'aaa.py', > 'classname':'Template', -- 'classname':'aaa', > 'name':'bgTemplate', > 'components': [ > > {'type':'Slider', > 'name':'sldResult', > 'position':(6, 91), > 'size':(200, 20), > 'layout':'horizontal', > 'max':400, > 'min':1, > 'value':55, > }, > > {'type':'Slider', > 'name':'sld1', > 'position':(9, 160), > 'size':(200, 20), > 'layout':'horizontal', > 'max':100, > 'min':1, > 'value':55, > }, > > {'type':'Slider', > 'name':'sld2', > 'position':(10, 295), > 'size':(200, 20), > 'layout':'horizontal', > 'max':100, > 'min':1, > 'value':64, > }, > > {'type':'Slider', > 'name':'sld3', > 'position':(11, 227), > 'size':(200, 20), > 'layout':'horizontal', > 'max':100, > 'min':1, > 'value':1, > }, > > {'type':'Slider', > 'name':'sld4', > 'position':(10, 9), > 'size':(200, 20), > 'layout':'horizontal', > 'max':100, > 'min':1, > 'value':28, > }, > > ] # end components > } # end background > ] # end backgrounds > } } > > > attmpt to run results::: > > > unable to load template.py > Traceback (most recent call last): > File "C:/Python21/PythonCardPrototype/samples/minimal/aaa.py", line 38, in ? > app = PythonCardPrototype.model.PythonCardApp(filename) > File "C:\PYTHON21\PythonCardPrototype\model.py", line 125, in __init__ > clazz = module.__dict__[ bg.classname ] > UnboundLocalError: local variable 'module' referenced before assignment > > Look, I promise to stop wasting your time soon... > No wasting, you've identified an interesting point. By not changing the 'file' and 'classname' attributes of your stack you managed to confuse the loader. Its an interesting conundrum, because we run aaa.py which causes the framework to load aaa.rsrc.py which *must* point back to aaa.py otherwise you see the error you got. Smacks of a bit of a circular reference to me and maybe something worth looking at? I know the original intention was for a run time engine which would first look at the rsrc file, thus the reference to aaa.py and class aaa makes sense. Perhaps it is just our round about unit testing strategy that causes the confusion. I leave it to the team to decide ... I haven't looked at the documentation but I suspect we need another paragraph in 'getting started'. I'll have a look at adding it later. Regards, Andy -- ----------------------------------------------------------------------- From the desk of Andrew J Todd esq. "Shave my poodle!" |