Problem with windows (wxframe)

Hi! Im using ogl and creating shapes like a rectangle like this in the code. When I create I create a wxframe together this shape for when I click in the shape I want that open this window(wxframe). But the problem is that I can just open one time. In the second I have an error. What could I do for fix this problem.

Diego

self.shapes=[]
    def Prop(self, event):
        for self.s in self.shapes:
            if self.s[0].Selected():
                janela=self.s[1]
                janela.Show(true)
       def Draw(self, event):
            shape=wxRectangleShape(50,50)
            shape.SetX(event.GetX())
            shape.SetY(event.GetY())
            self.rightwin.diagram.AddShape(shape)
            self.rightwin.Refresh()
            shape.Show(true)

            evthandler = MyEvent()
            evthandler.SetShape(shape)
            evthandler.SetPreviousHandler(shape.GetEventHandler())
            shape.SetEventHandler(evthandler)

            d = []
            self.contador = self.contador + 1
            frame = wxFrame(self, -1, "Objeto #%d" % self.contador)
            wxStaticText(frame, -1, "%dx%d" % (event.GetX(),event.GetY()), wxPoint(10,10))
            d.append(shape)
            d.append(frame)
            self.shapes.append(d)

Diego Galho Prestes wrote:

Hi! Im using ogl and creating shapes like a rectangle like this in the code. When I create I create a wxframe together this shape for when I click in the shape I want that open this window(wxframe). But the problem is that I can just open one time. In the second I have an error. What could I do for fix this problem.

I don't know. Please send a full, but minimal, sample that shows this problem.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Diego Galho Prestes wrote:

Hi! Im using ogl and creating shapes like a rectangle like this in the code. When I create I create a wxframe together this shape for when I click in the shape I want that open this window(wxframe). But the problem is that I can just open one time. In the second I have an error. What could I do for fix this problem.

I don't know. Please send a full, but minimal, sample that shows this problem.

I dont know if I understande what you said, but when I doubleclick in a shape I want that open the frame but when I close and click again happen this message error:
File "ogl.py", line 100, in Prop
    janela.Show(true)
File "/usr/local/lib/python2.2/site-packages/wxPython/wx,py", line 1732, in __getattr__
        raise wxPyDeadObjectError: The C++ part of the wxFrame object has been deleted, attribute access no longer allowed.

Diego

Diego Galho Prestes wrote:

Robin Dunn wrote:

Diego Galho Prestes wrote:

Hi! Im using ogl and creating shapes like a rectangle like this in the code. When I create I create a wxframe together this shape for when I click in the shape I want that open this window(wxframe). But the problem is that I can just open one time. In the second I have an error. What could I do for fix this problem.

I don't know. Please send a full, but minimal, sample that shows this problem.

I dont know if I understande what you said, but when I doubleclick in a shape I want that open the frame but when I close and click again happen this message error:
File "ogl.py", line 100, in Prop
   janela.Show(true)
File "/usr/local/lib/python2.2/site-packages/wxPython/wx,py", line 1732, in __getattr__
       raise wxPyDeadObjectError: The C++ part of the wxFrame object has been deleted, attribute access no longer allowed.

Well that's simple. (Always report the error message or traceback if there is one.) When frames close they call their own Destroy method by default. So you either need to create the frame again, or catch the EVT_CLOSE event and do a self.Hide() so it won't be destroyed.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Well that's simple. (Always report the error message or traceback if there is one.) When frames close they call their own Destroy method by default. So you either need to create the frame again, or catch the EVT_CLOSE event and do a self.Hide() so it won't be destroyed.

Tks, but now I have other problem. I create a event to call this class but I cant do that. It have to call the Open function in the class when I double click the screen.
This is the event

        EVT_LEFT_DCLICK(self.rightwin, self.Prop.Open)

and this is the class

    class Prop(wxFrame):
        def __init__(self, parent, title):
            wxFrame.__init__(self, parent, title, wxPoint(50,50), wxSize(200,300)) EVT_CLOSE(self, self.ClsWindow)
        def Open(self, event):
            for self.s in self.shapes:
                if self.s[0].Selected():
                    janela=self.s[1]
                    janela.Show(true)
        def ClsWindow(self, event):
            self.Hide()

but happen this error...

Traceback(most recent call last):
frame = Prop(self, "Objeto #%d" % self.contador)
NameError: global name "Prop" is not defined
TypeError: unbound method Open() must be called with Prop instance as first argument (got wxMouseEventPtr instance instead)

Diego Galho Prestes wrote:

Robin Dunn wrote:

Well that's simple. (Always report the error message or traceback if there is one.) When frames close they call their own Destroy method by default. So you either need to create the frame again, or catch the EVT_CLOSE event and do a self.Hide() so it won't be destroyed.

Tks, but now I have other problem. I create a event to call this class but I cant do that. It have to call the Open function in the class when I double click the screen.
This is the event

       EVT_LEFT_DCLICK(self.rightwin, self.Prop.Open)

[...]

Traceback(most recent call last):
frame = Prop(self, "Objeto #%d" % self.contador)
NameError: global name "Prop" is not defined
TypeError: unbound method Open() must be called with Prop instance as first argument (got wxMouseEventPtr instance instead)

What is self.Prop? A class or an instance of the class? (Hint: it needs to be an instance.)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Diego Galho Prestes wrote:

Robin Dunn wrote:

Well that's simple. (Always report the error message or traceback if there is one.) When frames close they call their own Destroy method by default. So you either need to create the frame again, or catch the EVT_CLOSE event and do a self.Hide() so it won't be destroyed.

Tks, but now I have other problem. I create a event to call this class but I cant do that. It have to call the Open function in the class when I double click the screen.
This is the event

       EVT_LEFT_DCLICK(self.rightwin, self.Prop.Open)

[...]

Traceback(most recent call last):
frame = Prop(self, "Objeto #%d" % self.contador)
NameError: global name "Prop" is not defined
TypeError: unbound method Open() must be called with Prop instance as first argument (got wxMouseEventPtr instance instead)

What is self.Prop? A class or an instance of the class? (Hint: it needs to be an instance.)

Well, I cant answer you question becouse Im dont know what it is exactly, but I'll try to explain what I wants. I already changed a little my code so I'll put again. I have a class Prop inside my main class where the program is, and in this class Prop I have a function (Open) that I want to execute in the event. I dont know how to call this function inside the class.

class Prop(wxFrame):
        def __init__(self, parent, id):
            wxFrame.__init__(self, parent, id)
            EVT_CLOSE(self, self.ClsWindow)

        def New(self, cont, x, y):
            frame = wxFrame(self, -1, "Objeto #%d" % cont, wxPoint(50,50), wxSize(200,300))
            wxStaticText(frame, -1, "%dx%d" % (x,y), wxPoint(10,10))
            return frame

        def Open(self, event=None):
            for s in self.shapes:
                if s[0].Selected():
                    janela=s[1]
                    janela.Show(true)

        def ClsWindow(self, event):
            self.Hide()

this is the class and I want to call the Open function and also New function to create one. How can I call these two functions outside the class Prop.

Diego

Diego Galho Prestes wrote:

Tks, but now I have other problem. I create a event to call this class but I cant do that. It have to call the Open function in the class when I double click the screen.
This is the event

       EVT_LEFT_DCLICK(self.rightwin, self.Prop.Open)

[...]

Traceback(most recent call last):
frame = Prop(self, "Objeto #%d" % self.contador)
NameError: global name "Prop" is not defined
TypeError: unbound method Open() must be called with Prop instance as first argument (got wxMouseEventPtr instance instead)

What is self.Prop? A class or an instance of the class? (Hint: it needs to be an instance.)

Well, I cant answer you question becouse Im dont know what it is exactly, but I'll try to explain what I wants. I already changed a little my code so I'll put again. I have a class Prop inside my main class where the program is, and in this class Prop I have a function (Open) that I want to execute in the event. I dont know how to call this function inside the class.

Okay, that's what I thought. You need to read about the difference between bound and unbound methods in Python. In a nutshell you can't call an unbound method without passing an instance of the class as the first parameter, on the other hand, bound methods are already bound to a particular instance and so you don't need to pass one.

In your example self.Prop is a class and so self.Prop.Open is an unbound method. When the event happens wxPython has no idea what to pass for the instance and so it just passes the event object like always, and you get the exception since that first (and only) parameter is not an instance of self.Prop.

Probably what you want to do is to bind directly to a new method of self, and then it can create the Prop instance and call its Open method. Something like this:

         EVT_LEFT_DCLICK(self.rightwin, self.OnOpenProp)
     def OnOpenProp(self, event):
  self.prop = self.Prop(self, -1)
  self.prop.Open()

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!