Ask Your Question
1

WxPython crashing PSSE

asked 2013-11-14 16:43:17 -0500

nwilson gravatar image

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()
edit retag flag offensive close merge delete

Comments

thanks EBahr! Works perfect now.

nwilson gravatar imagenwilson ( 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 gravatar imageEBahr ( 2013-11-20 15:38:18 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-11-19 16:39:08 -0500

EBahr gravatar image

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.

edit flag offensive delete link more
0

answered 2013-11-19 15:06:57 -0500

terrytian gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

Stats

Asked: 2013-11-14 16:43:17 -0500

Seen: 853 times

Last updated: Nov 19 '13