views:

603

answers:

2

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

A: 

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.

Soviut
Thanks, that's definitely a much cleaner solution. Appreciate it!
staircaseduets
A: 

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.

Frank Niessink