Call function from another class

Diez B. Roggisch deets at nospam.web.de
Mon Jul 27 06:43:14 EDT 2009


Lars wrote:

> 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
 



More information about the Python-list mailing list