Help: filedialog crash

Hi,
I want to implement a function to invoke a
wxFileDialog without wxPython app. (I need to use it
within PyGame.) Strangely enough the dirDialog
functions but the file dialog doesn't: Python crashes
under Windows XP. I'm using Python2.2 and wxPython
2.4.2.4 Any ideas? I need to get this working quickly.
Stani

The code:

import wx

def
dirDialog(defaultPath='',message="www.stani.be",newDir=1):
    """Launchs a directory selector dialog
(wxpython)."""
    style=wx.DEFAULT_DIALOG_STYLE
    if newDir:style|=wx.DD_NEW_DIR_BUTTON
    dlg =
wx.DirDialog(None,message=message,defaultPath=defaultPath,style=style)
    if dlg.Show() == wx.ID_OK:path=dlg.GetPath()
    else:path=''
    dlg.Destroy()
    return path

def
fileDialog(defaultPath='',defaultFile='',message='www.stani.be',

        wildcard =
"*.*",open=1,readOnly=1,overwrite=0,multiple=0,changeDir=0):
    """Launchs file selector dialog."""
    style=wx.OPEN
    if open: style|=wx.OPEN
    else: style|=wx.SAVE
    if not readOnly: style|=wx.HIDE_READONLY
    if not overwrite: style|=wx.OVERWRITE_PROMPT
    if multiple: style|=wx.MULTIPLE
    if changeDir: style|=wx.CHANGE_DIR
    dlg=wx.FileDialog(None, message = message,
defaultDir = defaultPath,
        defaultFile = defaultFile, wildcard =
wildcard, style = style)
    if dlg.ShowModal() ==
wx.ID_OK:path=dlg.GetFileName()
    else:path=''
    dlg.Destroy()
    return path

print fileDialog()

···

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

Just FYI, I tried both dialogs on Linux/RH8 with
wxPython2.4.1.2/Python2.3.1 and both seg fault.

Seems to me that the first arg, parent in both
the wx.DirDialog and wx.FileDialog calls can't be
None, but I may be wrong.

The doc for both does *not* state explicitly that
the arg parent can be NULL. But the wx.Dialog doc
does allow a NULL parent arg, specifically.

/Jean Brouwers

www.stani.be wrote:

···

Hi,
I want to implement a function to invoke a
wxFileDialog without wxPython app. (I need to use it
within PyGame.) Strangely enough the dirDialog
functions but the file dialog doesn't: Python crashes
under Windows XP. I'm using Python2.2 and wxPython
2.4.2.4 Any ideas? I need to get this working quickly.
Stani

The code:

import wx

def
dirDialog(defaultPath='',message="www.stani.be",newDir=1):
    """Launchs a directory selector dialog
(wxpython)."""
    style=wx.DEFAULT_DIALOG_STYLE
    if newDir:style|=wx.DD_NEW_DIR_BUTTON
    dlg =
wx.DirDialog(None,message=message,defaultPath=defaultPath,style=style)
    if dlg.Show() == wx.ID_OK:path=dlg.GetPath()
    else:path=''
    dlg.Destroy()
    return path

def
fileDialog(defaultPath='',defaultFile='',message='www.stani.be',

        wildcard =
"*.*",open=1,readOnly=1,overwrite=0,multiple=0,changeDir=0):
    """Launchs file selector dialog."""
    style=wx.OPEN
    if open: style|=wx.OPEN
    else: style|=wx.SAVE
    if not readOnly: style|=wx.HIDE_READONLY
    if not overwrite: style|=wx.OVERWRITE_PROMPT
    if multiple: style|=wx.MULTIPLE
    if changeDir: style|=wx.CHANGE_DIR dlg=wx.FileDialog(None, message = message,
defaultDir = defaultPath,
        defaultFile = defaultFile, wildcard =
wildcard, style = style)
    if dlg.ShowModal() ==
wx.ID_OK:path=dlg.GetFileName()
    else:path=''
    dlg.Destroy()
    return path

print fileDialog()

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
Yahooist Teil der Yahoo Markenfamilie

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

www.stani.be wrote:

Hi,
I want to implement a function to invoke a
wxFileDialog without wxPython app. (I need to use it
within PyGame.) Strangely enough the dirDialog
functions but the file dialog doesn't: Python crashes
under Windows XP. I'm using Python2.2 and wxPython
2.4.2.4 Any ideas? I need to get this working quickly.

Please find another way to do it as nothing is guaranteed to work without an app object. In fact in 2.5 more of the initialization is delayed until the app object is created and so there most things are guarnteed to not work unless you have created an app object.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!