[Newb] Still not able to solve class attribution

K

Knoppix User

Hi folks

I still have not been able to solve this one, which didn't manage to
garner a response yesterday, so I'm rephrasing it here.

If I define an attribute in the __init__ statement of a class, I should be
able to access that attribute in a later method of that class, right?

I have run into a situation where that does not SEEM to happen [newbie
alert].

What should I be looking into to try to solve this bug, as I am SOL with
new ideas?!

Although I am using wx, I do not believe that this has anything to do with
wx, but with syntax / semantics.

Any thoughts are very much appreciated.

I copy the original question below, for convenience.

Steve




class GIP(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title, size = (600, 460))

....

self.Image = wx.StaticBitmap(self, -1, wx.EmptyBitmap(*self.thumbSize),
pos = (160,10)) <<<<<<<<<<<<<<<<<<<<I thunk I dunnit here!

....

def DisplayImg(self, rot):
self.SetStatusText('Current image: ' + self.jpgList[self.curJpg])
img = wx.Image(self.jpgList[self.curJpg], wx.BITMAP_TYPE_JPEG)
if rot == 90:
img = img.Rotate90()
elif rot == 180:
img = img.Rotate(1, (0,0))
elif rot == 270:
img = img.Rotate(1.5, (0,0))
img = self.ScaleImg(img)
img = wx.BitmapFromImage(img)
self.Image.SetBitmap(img) <<<<<<<<<<<<<<<<<<<<<<<Problem
self.txtFName.Clear()
filen = self.GetFName(self.jpgList[self.curJpg])
self.txtFName.WriteText(filen)
self.txtDirName.SetLabel(self.dirName)


Traceback (most recent call last):
File "/usr/lib/python2.3/site-packages/sm/scriptutils.py", line 49, in run
exec codeObject in mainDict
File "<source>", line 197, in ?
File "/usr/lib/python2.3/site-packages/wxPython/wx.py", line 1951, in __init__
_wxStart(self.OnInit)
File "<source>", line 191, in OnInit
File "<source>", line 78, in __init__
File "<source>", line 116, in DisplayImg
AttributeError: GIP instance has no attribute 'Image'
 
P

Peter Otten

Knoppix said:
class GIP(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title, size = (600, 460))

....

Just an idea: how about moving the following statement up immediately after
the wx.Frame.__init__(...). The DisplayImg() method *could* be called in
the code you abbreviate with the above four dots.
self.Image = wx.StaticBitmap(self, -1,
wx.EmptyBitmap(*self.thumbSize),
pos = (160,10)) <<<<<<<<<<<<<<<<<<<<I thunk I dunnit here!

Peter
 
K

Knoppix User

Just an idea: how about moving the following statement up immediately after
the wx.Frame.__init__(...). The DisplayImg() method *could* be called in
the code you abbreviate with the above four dots.

Thanks for the idea Peter. No go. I did think of that earlier, and checked
a printout very carefully to make sure about that.

Anyway, I did move it up to be the first method after __init__, just to
check again.

:-(

Steve
 
K

Knoppix User

On Sun, 11 Jan 2004 18:36:22 +0100, Peter Otten wrote:

You were on the right track, Peter!

Your comment go me thinking some more. The error was not in the last line,
but the second to last.

I have quite a long init method, and the conflict was between the code
that sets up the StaticBitmap, and a prior reference to that code, from a
Button.

Thanks for jarring my mind-track in the right direction!!!!

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top