|
From: Alex T. <al...@tw...> - 2006-09-15 12:13:08
|
Jussi Salmela wrote:
>Hello all and particularly Alex Tweedly, I guess!
>
>I'm using Python 2.4.3, wxPython 2.3.0, PythonCard 0.8.2 and its
>Resource Editor on Win XP SP2.
>
>1. I have an ImageButton and a bunch of other components on my page.
>2. I enter
> open
>into the command field of the ImageButton component in the Property Editor.
>3. I click some other component(s) active and then click ImageButton
>active again.
>4. The command field now contains
> <type 'file'>
>instead of the open I entered earlier.
>5. If I now run my program I get an error, so not only the display is
>erroneous but also the resource file.
>6. If I retype open in the command field, save and run, everything works
>as expected.
>
>
Hmmmm - very interesting.
1. It's not unique to ImageButton - happens with any component.
2. It's (probably) not unique to the 'command' attribute - should happen
to some others, but I haven't tried too hard to see which ones it
happens with.
It's caused by the following snippet of code in
modules/propertyEditor.py (and /multipropertyEditor,.py):
> if propName not in ['label', 'stringSelection', 'text',
> 'toolTip', 'userdata']:
> try:
> value = eval(value)
> except:
> pass
I'm not 100% sure why this was wanted. It does let you do interesting
things - e.g. you can enter a string such as
3+8
and it will be evaluated to 11 for you. You can enter a string like
[20+3*15, 17]
and it will be evaluated (to [65,17]) for, say, the position value. And
various other more strange possibilities
(e.g. enter self.position and you get the current co-ords of the
property editor window !!)
But I'm not clear on what the *useful* purpose of this eval is.
In any case, the two oddities I know about are 'open' and 'file'
which both eval to <type 'file'> (though there may be others).
Suggestions (please comment):
1. short term - just avoid either open or file as command names :-)
2. figure out an exhaustive list of strings which eval to something they
"shouldn't", and explicitly check for them (??)
3. decide that you never want to eval the user-entered value to produce
a Python type, so add a test something like
if not isinstance(eval(value), types.TypeType) :
before resetting the variable 'value', thus
if propName not in ['label', 'stringSelection', 'text', 'toolTip',
'userdata']:
try:
if not isinstance(eval(value), types.TypeType) : value =
eval(value)
except:
pass
4. decide whether there is real purpose in doing an 'eval' here at all,
and if there is, limiting the use to those cases, somehow.
--
Alex Tweedly al...@tw... http://www.tweedly.net
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.4/448 - Release Date: 14/09/2006
|