1

WxPython crashing PSSE

I'm running the code below using the run macro button on the toolbar in PSSE 32. It runs fine the first time. I close the window and run it again. When I close it this time, PSSE says it has encountered an error and needs to close. It seems as if the first time, there was something left running that conflicts with the second request. Is there something I need to do to effectively close the python script? Some sort of garbage collection?

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, (550, 350))

        system_events_list = ['Bridger Fault', 'Salt Solar Outage', 'Hunter Fault']

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        hbox3 = wx.BoxSizer(wx.HORIZONTAL)

        panel = wx.Panel(self, -1)
        self.system_events = wx.ListBox(panel, 26, wx.DefaultPosition, (170, 130), system_events_list, wx.LB_SINGLE)
        self.system_events.SetSelection(0)
        btn = wx.Button(panel, wx.ID_CLOSE, 'Close')
        hbox1.Add(self.system_events, 0, wx.TOP, 40)
        hbox3.Add(btn, 0, wx.ALIGN_CENTRE)
        vbox.Add(hbox1, 0, wx.ALIGN_CENTRE)
        vbox.Add(hbox3, 1, wx.ALIGN_CENTRE)
        panel.SetSizer(vbox)

        self.Bind(wx.EVT_BUTTON, self.OnClose, id=wx.ID_CLOSE)
        self.Bind(wx.EVT_LISTBOX, self.OnSelect, id=26)

    def OnClose(self, event):
        self.Close()

    def OnSelect(self, event):
        index = event.GetSelection()
        system_event = self.system_events.GetString(index)

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'listbox.py')
        frame.Centre()
        frame.Show(True)
        return True

app = MyApp(0)
app.MainLoop()
nwilson's avatar
100
nwilson
asked 2013-11-14 16:43:17 -0500
edit flag offensive 0 remove flag close merge delete

Comments

thanks EBahr! Works perfect now.

nwilson's avatar nwilson (2013-11-19 16:47:28 -0500) edit

@nwilson no problem! This one had me scratching my head for a while... also, those look like PACE system events ;)

EBahr's avatar EBahr (2013-11-20 15:38:18 -0500) edit
add a comment see more comments

2 Answers

1

I am not quite sure why it does this, but add

app.Destroy()

at the very end of your code and it should work fine.

EBahr's avatar
420
EBahr
answered 2013-11-19 16:39:08 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

Seems that your wxpython program did not actually quit the main-loop at the first time even you close the window.

Since you have:

app.MainLoop()

I am not familiar with wxpython. But I think you should add some code to let your program leave the main loop at the 'close button' function.

terrytian's avatar
49
terrytian
answered 2013-11-19 15:06:57 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments

Your Answer

Login/Signup to Answer