Multiple Calling a wxPython dialog box within SPSS 17

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiple Calling a wxPython dialog box within SPSS 17

Georg Maubach-2
Multiple Calling a wxPython dialog box within SPSS 17

Hi All,

I have created the following dialog with xwPython called from a syntax editor window of PASW Statistics 17:

BEGIN PROGRAM PYTHON .

import wx

app = wx.PySimpleApp()
x=0
while x==0:
    dialog = wx.TextEntryDialog(None,
                                "Please enter countryID (as foldername)?",
                                "Text Entry",
                                "PLEASE enter countryID here!",
                                style=wx.OK|wx.CANCEL)
    if dialog.ShowModal() == wx.ID_OK:
        countryID=dialog.GetValue()
        if (dialog.GetValue()!="" and dialog.GetValue()!="PLEASE enter countryID here!"):
            x=1
print "countryID: ", countryID

dialog.Destroy()
app.Destroy()

END PROGRAM .

When I start a new session of SPSS 17 the dialog is properly displayed. But calling it the second time nothing happens when running from inside SPSS 17. If I do the same using a Python IDE like WingIDE the dialog is presented even it I run the routine twice.

What do I have to change to get the dialog even if I run it multiple times in SPSS?

I have to add that we need to run it in SPSSdX mode instead of SPSSxD mode.

Best regards

G.Maubach


Reply | Threaded
Open this post in threaded view
|

Re: Multiple Calling a wxPython dialog box within SPSS 17

Peck, Jon
Multiple Calling a wxPython dialog box within SPSS 17

I think the problem comes from creating and destroying the app object multiple times in the same session.  Back when the Python code ran in the same process as SPSS, it was unwise to leave the wxPython app around, because it fought with the regular SPSS gui.  With recent versions, where Python is running in a separate process, this shouldn’t be an issue anymore.

 

So, if you change the code below so that it doesn’t destroy the app at the end of the program and reuses the app object if it already exists, you should be okay.  Remember that the Python variables stay around across multiple programs run in the same session.

 

Ideally, you should shut down the app when the SPSS program terminates, but you can probably get away without that step.

 

HTH,

Jon Peck

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Georg Maubach
Sent: Wednesday, August 26, 2009 10:26 AM
To: [hidden email]
Subject: [SPSSX-L] Multiple Calling a wxPython dialog box within SPSS 17

 

Hi All,

I have created the following dialog with xwPython called from a syntax editor window of PASW Statistics 17:

BEGIN PROGRAM PYTHON .

import wx

app = wx.PySimpleApp()
x=0
while x==0:
    dialog = wx.TextEntryDialog(None,
                                "Please enter countryID (as foldername)?",
                                "Text Entry",
                                "PLEASE enter countryID here!",
                                style=wx.OK|wx.CANCEL)
    if dialog.ShowModal() == wx.ID_OK:
        countryID=dialog.GetValue()
        if (dialog.GetValue()!="" and dialog.GetValue()!="PLEASE enter countryID here!"):
            x=1
print "countryID: ", countryID

dialog.Destroy()
app.Destroy()

END PROGRAM .

When I start a new session of SPSS 17 the dialog is properly displayed. But calling it the second time nothing happens when running from inside SPSS 17. If I do the same using a Python IDE like WingIDE the dialog is presented even it I run the routine twice.

What do I have to change to get the dialog even if I run it multiple times in SPSS?

I have to add that we need to run it in SPSSdX mode instead of SPSSxD mode.

Best regards

G.Maubach