|
From: Kevin A. <al...@se...> - 2001-09-03 01:39:05
|
We should probably have a different error checking mechanism rather than
throwing a generic exception, but the error:
unable to load template.py
shows that the problem is that there isn't a 'template.py' file to load.
The problem is that your .rsrc.py and main source file don't match up. You
must have used the resourceEditor sample to create your layout and so it
generated default values for the stack and background names. You have:
{'stack':{'type':'Stack',
'name':'Template',
'title':'Template Resource',
'position':(66, 0),
'size':(500, 600),
'backgrounds': [
{'type':'Background',
'file':'template.py',
'classname':'Template',
'name':'bgTemplate',
'components': [
at a minimum, you need to change the background info. After you do your
first 'Save As...' with the resourceEditor, you can quit, open up the file
you saved with an editor, and change the stack and background info, then you
won't have to worry about it unless you decide to change background names...
later. To test your code, I renamed the files to 'sliders.py' and
'sliders.rsrc.py'
'backgrounds': [
{'type':'Background',
'file':'sliders.py',
'classname':'aaa',
'name':'bgMin',
'components': [
I left the 'name' of the background the same, you can change it to something
more meaningful, but then you need to make sure that the method def matches.
def on_bgMin_select(self,target,event):
By convention, 'classname' should start with a capital letter and should be
meaningful, but 'aaa' is still valid, so I didn't change it.
You don't need the 'on_sld1_select' method since you have a background one,
so I commented that out. It turns out my original message had a typo and a
logic problem, so the following line:
if name[:3] == 'sld' and int(name[:3]) in [1,2,3,4]:
^
should be:
if name[:3] == 'sld' and int(name[3:]) in [1,2,3,4]:
however, that doesn't work because trying to do int('Result') throws an
exception, so assuming that you only have four regular sliders and a result
slider you would want to do:
if name[:3] == 'sld' and name[3:]) != 'Result':
Finally, you didn't have a calcResult method, so I added it below, but
didn't finish the calculation for you, so you'll need to change that. The
last thing that the code below doesn't do is deal with your calculation
giving you a result outside the min and max values for your result slider.
You'll have to decide how you want to deal with that possibility.
That gives us changed this code for the class:
class aaa(PythonCardPrototype.model.Background):
def on_menuFileExit_select(self, menu, event):
self.Close()
def calcResult(self):
s1 = self.components.sld1.value
s2 = self.components.sld2.value
s3 = self.components.sld3.value
s4 = self.components.sld4.value
result = 10 # put your calculation here
return result
def displayResult(self,result):
self.components.sldResult.value=int(result)
def on_bgMin_select(self,target,event):
name = target.name
if name[:3] == 'sld' and (name[3:]) != 'Result':
self.displayResult(self.calcResult())
I noticed that your sliders are in a strange order in your layout:
sld4
sldResult
sld1
sld3
sld2
Perhaps you should exchange their y values to make the UI better.
ka
> -----Original Message-----
> From: pyt...@li...
> [mailto:pyt...@li...]On Behalf Of Ronald
> D Stephens
> Sent: Sunday, September 02, 2001 6:07 PM
> To: pyt...@li...
> Subject: [Pythoncard-users] Braindead debugging
>
>
> 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',
> 'classname':'Template',
> '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...
>
>
>
> _______________________________________________
> Pythoncard-users mailing list
> Pyt...@li...
> https://lists.sourceforge.net/lists/listinfo/pythoncard-users
>
|