Win32gui... file dialogs?
Alex Martelli
alex at magenta.com
Sat Aug 26 06:55:44 EDT 2000
"Alex Martelli" <alex at magenta.com> wrote in message
news:8o80gd02091 at news1.newsguy.com...
[snip]
> > OTOH, maybe working out the struct magic for win32gui, and putting
> > that into a .py file would be a better option?
>
> It seems to be something that could be made to work right now.
[snip]
> a null at the end?), or maybe I need array & buffer_info()...?
It was easier than I thought -- BUT, the multiselect isn't working!
Anyway, here is what I have so far, at a highly-prototypal stage:
-- file ofn.py
import win32gui, struct, array
OFN_ALLOWMULTISELECT=0x00000200
OFN_EXPLORER=0x00080000
def arrayToStrings(resultArray):
"return list-of-strings corresponding to a char array"
astr=resultArray.tostring()
manyStrings=[]
while len(astr) and astr[0]!='\000':
i=astr.index('\000')
manyStrings.append(astr[:i])
astr=astr[i+1:]
return manyStrings
def buildOfn(resultarray,multisel=1,newlook=1):
"build an OPENFILENAME struct as a string"
flags=0
if multisel: flags=flags|OFN_ALLOWMULTISELECT
if newlook: flags=flags|OFN_EXPLORER
file,maxfile=resultarray.buffer_info()
return struct.pack(
"3i2P2iPiPi2PI2hPi2P",
76, 0, 0, # size, owner-hwnd, hinstance
0, 0, 0, 0, # filter, custom-filter, max-cust-filter,
filter-index
file, maxfile, # file, max-file
0, 0, # file-title, max-file-title
0, 0, # initial-dir, dialog-title
flags, 0, 0, # flags, file-offset, file-extension
0, # def-ext
0, 0, 0) # cust-data, func-hook, template-name
def openNames(multisel=1,newlook=1):
resultBuffer=array.array('c',8192*'\000')
ofn=buildOfn(resultBuffer,multisel,newlook)
isok=win32gui.GetOpenFileName(ofn)
if not isok: return []
return arrayToStrings(resultBuffer)
This seems to work just fine (on my Win98 box, with Python
1.6b1 from the Activestate distribution), BUT, the multiselect
feature isn't working...! The flag is being "seen": to verify
this, one can play with both multisel and newlook. If multisel
is 0, the look is the 'new' (Explorer) one anyway; but if
multisel is 1, and newlook is 0, the old-style (Windows 3)
file-selection dialog appears -- as per MS's docs (and no files
are actually displayed, since no filter was set). But with both
multisel and newlook to 1, as per default, the dialog is fine,
new-look style, but NOT multiselection -- each clic 'overwrites'
the previously selected file rather than appending, and only
the last-clicked file is in the result.
I think I'm pretty close and just missing something silly, but
can't see it (yet?), so I decided to share what I have, for now,
as I think more eyes may well help...!-)
Alex
More information about the Python-list
mailing list