First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
1

WxPython crashing PSSE

asked Nov 14 '13

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()

Comments

thanks EBahr! Works perfect now.

nwilson gravatar imagenwilson (Nov 19 '13)

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

EBahr gravatar imageEBahr (Nov 20 '13)

2 answers

Sort by » oldest newest most voted
1

answered Nov 19 '13

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.

link
0

answered Nov 19 '13

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.

link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

Stats

Asked: Nov 14 '13

Seen: 859 times

Last updated: Nov 19 '13