why is this wxpython script crashing EG?

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
Navi
Posts: 11
Joined: Wed Mar 19, 2014 11:32 pm

why is this wxpython script crashing EG?

Post by Navi » Sat Apr 05, 2014 8:41 am

Pasted this really simple code into an EG Python script:

Code: Select all

import wx

app = wx.PySimpleApp()
choices = ["Alpha", "Baker", "Charlie", "Delta"]
dialog = wx.SingleChoiceDialog(None, "Pick A Word", "Choices",choices)
if dialog.ShowModal() == wx.ID_OK:
    print "You selected: %s\n" % dialog.GetStringSelection()

dialog.Destroy()
in an attempt to open a multple choice dialog. The dialog opens, for a moment, and then EG crashes...any experts know WHY?

User avatar
Pako
Plugin Developer
Posts: 2290
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: why is this wxpython script crashing EG?

Post by Pako » Sat Apr 05, 2014 11:19 am

Navi wrote:The dialog opens, for a moment, and then EG crashes...any experts know WHY?
Unfortunately, I'm not an expert and I can not explain exactly why this is so.
But I know how it can be modified to make it work:

Code: Select all

import wx

choices = ["Alpha", "Baker", "Charlie", "Delta"]

def CreateDialog():
    dialog = wx.SingleChoiceDialog(None, "Pick A Word", "Choices",choices)
    if dialog.ShowModal() == wx.ID_OK:
        print "You selected: %s\n" % dialog.GetStringSelection()
    dialog.Destroy()

wx.CallAfter(CreateDialog)
Pako

Navi
Posts: 11
Joined: Wed Mar 19, 2014 11:32 pm

Re: why is this wxpython script crashing EG?

Post by Navi » Sun Apr 06, 2014 12:24 am

Pako wrote:But I know how it can be modified to make it work:
EDIT: what the heck, I just tried it again and it's working now. SO BIZARRE.

EDIT2: okay so I've noticed, if you make ANY CHANGES to the code above, and press TEST, EG will error like I quoted below. If you hit OK and OPEN THE SCRIPT BACK UP in EG, it'll work fine. How crazy is that?! But, it works!!!!


Thanks! That's exactly what I need...but for some reason when I run that script I get the following error from EG:

Code: Select all

Traceback (most recent call last) (1640):
  File "wx\_core.pyc", line 14660, in <lambda>
  File "33", line 6, in CreateDialog
AttributeError: 'NoneType' object has no attribute 'SingleChoiceDialog'

Post Reply