Quantcast

wx.FileDialog to open folder or wx.DirDialog to open file

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

wx.FileDialog to open folder or wx.DirDialog to open file

JC Tan
Hi all,

I am wondering is it possible to use wx.FileDialog to select folder (or
wx.DirDialog to select file)? Does wx has something more "generic"? I
need a single dialog to allow user to select either file or folder or
both. Please advise. Thank You.

Regards,
-JC Tan

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: wx.FileDialog to open folder or wx.DirDialog to open file

David Goldsmith-3
Unless I am mistaken, you should be able to use wx.FileDialog's GetPaths() method together w/ os.path.IsFile() and os.path.IsDir() to robustly handle whatever type of path-specified object the user has selected when they click OK (and if you want to make it clear to the user in advance that they'll have this flexibility, just throw up a wx.MessageBox before the FileDialog gets shown - clunky, but functional).

DG
--- On Tue, 6/10/08, JC Tan <[hidden email]> wrote:

> From: JC Tan <[hidden email]>
> Subject: [wxpython-users] wx.FileDialog to open folder or wx.DirDialog to open file
> To: [hidden email]
> Date: Tuesday, June 10, 2008, 8:22 PM
> Hi all,
>
> I am wondering is it possible to use wx.FileDialog to
> select folder (or
> wx.DirDialog to select file)? Does wx has something more
> "generic"? I
> need a single dialog to allow user to select either file or
> folder or
> both. Please advise. Thank You.
>
> Regards,
> -JC Tan
> _______________________________________________
> wxpython-users mailing list
> [hidden email]
> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


     

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: wx.FileDialog to open folder or wx.DirDialog to open file

JC Tan
David,

Thank you for your reply.

 I am looking at my code now on linux (Fedora 8 - Gnome 2.2), it seems the wx.FileDialog on GTK will BROWSE the folder instead of selecting it when Open is clicked (refer screenshots attached), which mean I am unable to select a folder path.

Any other idea?

Regards,
-JC Tan



David Goldsmith wrote:
Unless I am mistaken, you should be able to use wx.FileDialog's GetPaths() method together w/ os.path.IsFile() and os.path.IsDir() to robustly handle whatever type of path-specified object the user has selected when they click OK (and if you want to make it clear to the user in advance that they'll have this flexibility, just throw up a wx.MessageBox before the FileDialog gets shown - clunky, but functional).

DG
--- On Tue, 6/10/08, JC Tan [hidden email] wrote:

  
From: JC Tan [hidden email]
Subject: [wxpython-users] wx.FileDialog to open folder or wx.DirDialog to open file
To: [hidden email]
Date: Tuesday, June 10, 2008, 8:22 PM
Hi all,

I am wondering is it possible to use wx.FileDialog to
select folder (or 
wx.DirDialog to select file)? Does wx has something more
"generic"? I 
need a single dialog to allow user to select either file or
folder or 
both. Please advise. Thank You.

Regards,
-JC Tan
_______________________________________________
wxpython-users mailing list
[hidden email]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
    


      
_______________________________________________
wxpython-users mailing list
[hidden email]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


  


FileDialog00.jpg (73K) Download Attachment
FileDialog01.jpg (74K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: wx.FileDialog to open folder or wx.DirDialog to open file

Robin Dunn
JC Tan wrote:
> David,
>
> Thank you for your reply.
>
>  I am looking at my code now on linux (Fedora 8 - Gnome 2.2), it seems
> the wx.FileDialog on GTK will BROWSE the folder instead of selecting it
> when Open is clicked (refer screenshots attached), which mean I am
> unable to select a folder path.

If you want a file then use wx.FileDialog.  If you want a folder then
use wx.DirDialog.  That's why there are two different classes.  If you
must be able to select either from the same dialog then you'll need to
create your own.

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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: wx.FileDialog to open folder or wx.DirDialog to open file

David Goldsmith-3
In reply to this post by JC Tan
JC: The following is inelegant but get's your "job" done.  But perhaps if you tell us more about your use-case, we can suggest some better options...

DG

## Begin included code

import wx

class myFileDialog(wx.FileDialog):
    def __init__(self, parent):
        wx.FileDialog.__init__(self, parent)

    def ShowModal(self):
        wx.MessageBox("To get a directory chooser instead, simply click cancel")
        if super(myFileDialog, self).ShowModal() == wx.ID_OK:
            return self
#        else:
           

class hybridDlg(wx.DirDialog):
    def __init__(self, parent):
        wx.DirDialog.__init__(self, parent)
        self.FileDialog = myFileDialog(self)

    def ShowModal(self):
        if self.FileDialog.ShowModal() == wx.ID_OK:
            pass
        else:
            if super(hybridDlg, self).ShowModal() == wx.ID_OK:
                pass

class myFrame(wx.Frame):
    def __init__(self, parent, id, title=''):
        wx.Frame.__init__(self, parent, id, title)
        self.dlg = hybridDlg(self)

class myApp(wx.App):
    def OnInit(self):
        self.frame = myFrame(None, -1)
        self.SetTopWindow(self.frame)
        self.frame.Fit()
        self.frame.Show()
        self.frame.dlg.ShowModal()
        return True

if __name__ == '__main__':
    app = myApp(0)
    app.MainLoop()

## End included code

--- On Wed, 6/11/08, David Goldsmith <[hidden email]> wrote:

> From: David Goldsmith <[hidden email]>
> Subject: Re: [wxpython-users] wx.FileDialog to open folder or wx.DirDialog to open file
> To: [hidden email]
> Date: Wednesday, June 11, 2008, 2:11 AM
> Unless I am mistaken, you should be able to use
> wx.FileDialog's GetPaths() method together w/
> os.path.IsFile() and os.path.IsDir() to robustly handle
> whatever type of path-specified object the user has
> selected when they click OK (and if you want to make it
> clear to the user in advance that they'll have this
> flexibility, just throw up a wx.MessageBox before the
> FileDialog gets shown - clunky, but functional).
>
> DG
> --- On Tue, 6/10/08, JC Tan <[hidden email]>
> wrote:
>
> > From: JC Tan <[hidden email]>
> > Subject: [wxpython-users] wx.FileDialog to open folder
> or wx.DirDialog to open file
> > To: [hidden email]
> > Date: Tuesday, June 10, 2008, 8:22 PM
> > Hi all,
> >
> > I am wondering is it possible to use wx.FileDialog to
> > select folder (or
> > wx.DirDialog to select file)? Does wx has something
> more
> > "generic"? I
> > need a single dialog to allow user to select either
> file or
> > folder or
> > both. Please advise. Thank You.
> >
> > Regards,
> > -JC Tan
> > _______________________________________________
> > wxpython-users mailing list
> > [hidden email]
> >
> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


     
_______________________________________________
wxpython-users mailing list
[hidden email]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Loading...