Gseos.FileMenu
Previous  Top  Next

FileMenu(fCallback, strFilter, wFlags, [bPriority])

The FileMenu() function allows you to hook into the GSEOS file handling and use the common File/Open, File/SaveAs, etc. menus for your own file types. When you register for file handling your callback routine will be called with the file name the user selected and the operation he wants to perform on the file. You can register for all supported file modes: New, Open, Append, SaveAs.

ParameterDescription     
fCallbackThe callback function should take two parameters: fCallback(strFile, wMode) Where strFile is the file name the user selected and wMode is one of the file modes specified in the flags parameter.     
strFilterThe filter, the actual extensions should be in parentheses with a descriptive text before that: "Python Modules (*.py; *.pyd; *.pyc)". If multiple extensions are provided they must be separated by semicolon (;).  
wFlagsSpecifies the file mode to register for. If this parameter is 0 this filter is removed from the file handling. wFlags can be one or more of the following constants. If you specify just one parameter you can simply use the constant, for more than one parameter you or the values together. Here the constants valid for wFlags: REG_FILENEW, REG_FILEOPEN, REG_FILEAPPEND, REG_FILESAVEAS, REG_FILEPRINT.     
bPriorityOptional, specifies the order in the list. Smaller numbers occur higher up in the list. You should not install your custom filters before or in between the standard GSEOS filters. If you don't specify this parameter the filter is appended at the end of the list.     

Returns
None

Comments
When your callback function is called all it gets passed is the name of the file the user wants to operate on and the mode flag. The file is not opened or touched in any way. The file operations you want to perform are up to you. However, if the callback function is called with REG_FILEOPEN it is guaranteed that the file exists.

Example
The following sample defines a callback function that processes the file a user selects from the File/Open menu. It then registers the filter with GSEOS:

from Gseos import *

def fOnImgFile(strFileName, wMode):
  if (wMode == REG_FILEOPEN):
    fProcessMyFile(strFileName)

  elif (wMode == REG_FILESAVEAS):
    fSaveMyResult(strFileName)

# Register with GSEOS
FileMenu(fOnImgFile, 'Image Files (*.img)', REG_FILEOPEN | REG_FILESAVEAS)