[pygtk] Win32 file chooser

Chris Lambacher chris at kateandchris.net
Tue Mar 7 04:25:40 WST 2006


I use MFC CreateFileDialog provided by win32ui in win32all.

Here is something that works on win2k and XP for sure:

filtertypes = [('All Font Files (*.ttf, *.otf, *.pfm)', 
                        ('*.ttf','*.otf', '*.pfm')), 
               ('True Type Font Files (*.ttf)', ('*.ttf',)),
               ('Open Type Font Files (*.otf)', ('*.otf',)),
               ('Type 1 Font files (*.pfm)', ('*.pfm',)), 
               ('All Files (*.*)', ('*',))]

filters = []
for fil_name, fil_exts in filtertypes:
    filter = '|'.join((fil_name, ';'.join(fil_exts)))
    filters.append(filter)

filter = '|'.join(filters+[''])
        
dlg = win32ui.CreateFileDialog( True, None, None, 
                                win32con.OFN_HIDEREADONLY | 
                                win32con.OFN_OVERWRITEPROMPT | 
                                win32con.OFN_FILEMUSTEXIST, filter)

dlg.SetOFNTitle('Select font file')

response = dlg.DoModal()
if response != win32con.IDOK:
    return

filename = dlg.GetPathName()
del dlg


On Mon, Mar 06, 2006 at 12:27:19PM +1100, John Pye wrote:
> Hi all,
> 
> Has anyone had any success getting the following example from the FAQ to
> run?
> 
> http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq21.013.htp
> 
> For me, running with Python 2.4 on Win2k, it doesn't work:
> 
> > Exception in thread Thread-12:
> > Traceback (most recent call last):
> >   File "C:\Python24\lib\threading.py", line 442, in __bootstrap
> >     self.run()
> >   File "C:\Python24\lib\threading.py", line 422, in run
> >     self.__target(*self.__args, **self.__kwargs)
> >   File "examplewinfile.py", line 12, in run_dialog
> >     s = winfilechooser._test("This is a dialog", "C:\\WINDOWS")
> >   File "g:\ascend\pygtk\interface\winfilechooser.py", line 132, in _test
> >     if win32gui.GetOpenFileName(cs1.data):
> > TypeError: Argument must be a 88-byte string
> 
> 
> Any suggestions?
> 
> Cheers
> JP
> 
> -- 
> John Pye
> School of Mechanical and Manufacturing Engineering
> The University of New South Wales
> Sydney  NSW 2052  Australia
> t +61 2 9385 5127
> f +61 2 9663 1222
> mailto:john.pye_AT_student_DOT_unsw.edu.au
> http://pye.dyndns.org/
> 
> _______________________________________________
> pygtk mailing list   pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


More information about the pygtk mailing list