Call function from another class

L

Lars

Hi
I'm trying to make an simple image viewer in wxPython and rotate an
image with a slider. The code at Pastebin is striped down at bit. The
class Frame(wx.Frame) is the main window, the function "def
CreateMenuBar" (l. 39) creates a menu, where the function "def onRotate
(self,event):" (l. 43) is called. The slider appear in at 2nd window,
class rotationSlider(wx.Frame).
My problem is what to do, when the Okay button is pressed in the
"rotationSlider" frame. How to get the slider value to my main window
and how to call a function to do the rotation. I tried something with
a global variable, but it would make no difference regarding the
function problem. Amongst the other things I've tried is to bind the
event of the 2nd/slider window closing (l. 46), but no.
Python code at Pastebin: http://pastebin.com/m7c24ec34

So some help on Classes and etc., would be appreciated.

/Lars
 
D

Diez B. Roggisch

Lars said:
Hi
I'm trying to make an simple image viewer in wxPython and rotate an
image with a slider. The code at Pastebin is striped down at bit. The
class Frame(wx.Frame) is the main window, the function "def
CreateMenuBar" (l. 39) creates a menu, where the function "def onRotate
(self,event):" (l. 43) is called. The slider appear in at 2nd window,
class rotationSlider(wx.Frame).
My problem is what to do, when the Okay button is pressed in the
"rotationSlider" frame. How to get the slider value to my main window
and how to call a function to do the rotation. I tried something with
a global variable, but it would make no difference regarding the
function problem. Amongst the other things I've tried is to bind the
event of the 2nd/slider window closing (l. 46), but no.
Python code at Pastebin: http://pastebin.com/m7c24ec34

So some help on Classes and etc., would be appreciated.

If I'm not mistaken, in "doRotate" you should be able to refer to the
to-be-closed dialog via

self.frameRotate

Now if you change the "sliderUpdate"-code to store that angle instead of
just letting it fall out of scope, you could access that value through
frameRotate:

def sliderUpdate(self, event):
angle=self.slider.GetValue()
ROTATION_ANGLE=angle
self.angle = angle
self.Destroy()



def doRotate(self,event):
"""Rotating image"""
print self.frameRotate.angle


Diez
 
L

Lars

If I'm not mistaken, in "doRotate" you should be able to refer to the
to-be-closed dialog via
self.frameRotate

Now if you change the "sliderUpdate"-code to store that angle instead of
just letting it fall out of scope, you could access that value through
frameRotate:

def sliderUpdate(self, event):
        angle=self.slider.GetValue()
        ROTATION_ANGLE=angle
        self.angle = angle
        self.Destroy()

def doRotate(self,event):
    """Rotating image"""
    print self.frameRotate.angle

Thanks for replying. If Bind is used in "onRotate":
def onRotate(self,event):
"""Rotate image"""
self.frameRotate = rotationSlider(parent=None, id=-1)
self.Bind(wx.EVT_CLOSE,self.doRotate, self.frameRotate.Destroy)
self.frameRotate.Show()

Then i get:
Traceback (most recent call last):
File "viewer_sep.py", line 136, in onRotate
self.Bind(wx.EVT_CLOSE,self.doRotate, self.frameRotate.Destroy)
File "/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode/wx/
_core.py", line 3629, in Bind
id = source.GetId()
AttributeError: 'function' object has no attribute 'GetId'

My experience with ID is setting it to "-1". So I'm not sure if it is
a wrong use of Bind or an wxPython error.
/Lars
 

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

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top