We have an application (with a gui) that
embeds Python inside it. Code between BEGIN PROGRAM and END PROGRAM is
executed by the Python processor, and each program causes a new thread to be
created, which dies at the END PROGRAM call. (Other code inbetween would be our
standard syntax.)
In order to minimize contention with the
regular gui, we create wx.PySimpleApp objects and destroy them as soon as
possible. This generally works fine, but the two programs below do not get
along well. Each one can be run many times in the same session, but running
the second one after the first one has been run causes the file dialog ShowModal
call always to return 5101, Cancel, without ever showing the dialog.
Putting all the wxPython stuff on a separate
thread does not help. My suspicion is that there is some state that is not removed
when the app is destroyed and the new thread requires it. But, to reiterate,
each program can be run repeatedly separately. Sometimes after running the
second one, running the first one again produces a “common dialog failed” alert
with a code of ffff.
This is all on Windows, and wxPython 2.8 (it
also failed on 2.6).
Any hints on what might be happening here or
how to get around it would be greatly appreciated.
*** running the
following as one program works. As separate programs, the second one fails.
BEGIN PROGRAM.
import spss,
spssdata, re, wx, sys
import threading
stringVars = []
for i in
range(spss.GetVariableCount()):
** if
spss.GetVariableType(i) != 0:**
** stringVars.append(spss.GetVariableName(i))**
pcvars = "not
set"
app =
wx.PySimpleApp()
dlg =
wx.MultiChoiceDialog(None, “Select one or more variables\nfor
analysis”,
** “Descriptive
Statistics”, stringVars)**
if dlg.ShowModal()
== wx.ID_OK:
** varsx =
dlg.GetSelections()**
else:
** varsx = None**
dlg.Destroy()
app.Destroy()
print varsx
END PROGRAM.
BEGIN PROGRAM.
import wx
repapp =
wx.PySimpleApp()
repdlg =
wx.FileDialog(None,“Save file as
…”,defaultDir="~/Desktop",defaultFile="",wildcard=“PDF
File (.pdf)|.pdf|Word File (.doc)|.doc|Powerpoint File
(.ppt)|.ppt”,style=wx.SAVE)
print
“repdlg:”, type(repdlg), repdlg
rc =
repdlg.ShowModal()
if rc== wx.ID_OK:
** outfile =
repdlg.GetPath()**
else:
** outfile = None**
repdlg.Destroy()
repapp.Destroy()
END PROGRAM.
Jon K. Peck
SPSS Inc.
312-651-3435