PDA

View Full Version : FileChooser


disbeat
03-30-2011, 10:09 AM
Hi,

Is there a built in way to provide a file choosing window or something?

If no, is vizard compatible with libraries like gtk, so I can use its implementation, like in:

http://www.eurion.net/python-snippets/snippet/File%20Chooser.html

Thanks in advance

farshizzo
03-30-2011, 10:29 AM
If you plan on upgrading to Vizard 4, you can use the vizinput module to display file open/save dialogs:import vizinput
filename = vizinput.fileOpen()
filename = vizinput.fileSave()

If you need code that works with Vizard 3, then you can use the win32gui module that comes with Vizard:
import win32gui
import win32con
import pywintypes

def OpenFileDialog():
try:
value = win32gui.GetOpenFileNameW(
hwndOwner = viz.window.getHandle(),
InitialDir = '',
Flags = win32con.OFN_EXPLORER|win32con.OFN_FILEMUSTEXIST|w in32con.OFN_NOCHANGEDIR,
File = '',
Filter = '' )
except pywintypes.error:
return ''
else:
return value[0]

def SaveFileDialog():
try:
value = win32gui.GetSaveFileNameW(
hwndOwner = viz.window.getHandle(),
InitialDir = '',
Flags = win32con.OFN_EXPLORER|win32con.OFN_NOCHANGEDIR,
File = '',
Filter = '' )
except pywintypes.error:
return ''
else:
return value[0]