user109647
user109647

Reputation:

Closing and Opening Frames in wxPython

I'm working on writing a very simple client/server application as an excuse to start learning network/gui programming in python. At the moment I'm stuck on transitioning from my login frame to the main frame of the application.

The login frame is a subclass of wx.Frame, and basically I just want to close it and open the main frame when it receives confirmation from the server:

def handleServerSignon(self, msg):
    if msg.getCode() == net.message.HANDLE_IN_USE:
        self.status.SetStatusText('Handle already in use')
    elif msg.getCode() == net.message.SIGNON_SUCCESSFUL:
        self.Close()
        mainWindow = wx.Frame(None, wx.ID_ANY, 'main window', wx.DefaultPosition, \
                              (640, 480))

        mainWindow.Show(True)

I can't even get this to give a consistent error message though... sometimes it works, sometimes it crashes with the following:

python: ../../src/xcb_io.c:242: process_responses: Assertion `(((long) (dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed.

Any help is very much appreciated!

Walker

Upvotes: 0

Views: 2042

Answers (2)

Frank Niessink
Frank Niessink

Reputation: 1611

mainWindow is a local variable of handleServerSignon. This is a guess, but I think it may be garbage collected as soon as the handleServerSignon method returns.

Upvotes: 0

Soviut
Soviut

Reputation: 91545

I would make your main frame appear, then show a modal login dialog over top instead.

If you don't want to do that, I suggest you create two separate Frames and have your application listen for a close event on the login frame. Handle the login in that event handler, then have it show the main window. Basically, you don't want to be instantiating the main window in your event handler since once you leave the function, scope is lost the the garbage collector will try to remove your frame.

Lastly, you should consider calling getCode() once and caching the result for your comparisons. Since your if statement and elif statement both call getCode() it very well may be yielding different results.

Upvotes: 2

Related Questions