Author: btami Date: 2007-03-06 06:44:22 -0600 (Tue, 06 Mar 2007) New Revision: 9427
Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/form/widget.py Log: add dir/file selection dialogs Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/form/widget.py =================================================================== --- trunk/gnue-forms/src/uidrivers/win32/widgets/form/widget.py 2007-03-05 17:51:13 UTC (rev 9426) +++ trunk/gnue-forms/src/uidrivers/win32/widgets/form/widget.py 2007-03-06 12:44:22 UTC (rev 9427) @@ -34,6 +34,7 @@ import win32con import commctrl import win32print +from win32com.shell import shell from PIL import Image, ImageWin, ImageGrab @@ -136,8 +137,9 @@ # Add Statusbar, Toolbar and Menubar as requested and/or allowed if self._form.style != 'dialog': - if not self._form._features['GUI:MENUBAR:SUPPRESS']: - MenuBar(self._uiDriver, self.mainWindow, self._form) + if not self._form.findChildNamed('__main_menu__', 'GFMenu'): + if not self._form._features['GUI:MENUBAR:SUPPRESS']: + MenuBar(self._uiDriver, self.mainWindow, self._form) if not self._form._features['GUI:TOOLBAR:SUPPRESS']: ToolBar(self._uiDriver, self.mainWindow, self._form) @@ -274,7 +276,104 @@ res = win32gui.MessageBox(0, message, title, flags) return _RESPONSE [res] - + + # ------------------------------------------------------------------------- + # Show a file selection dialog + # ------------------------------------------------------------------------- + + def _ui_select_files_(self, title, default_dir, default_file, wildcard, + mode, multiple, overwrite_prompt, file_must_exist): + """ + Bring up a dialog for selecting filenames. + + @param title: Message to show on the dialog + @param default_dir: the default directory, or the empty string + @param default_file: the default filename, or the empty string + @param wildcard: a list of tuples describing the filters used by the + dialog. Such a tuple constists of a description and a fileter. + Example: [('PNG Files', '*.png'), ('JPEG Files', '*.jpg')] + If no wildcard is given, all files will match (*.*) + @param mode: Is this dialog an open- or a save-dialog. If mode is + 'save' it is a save dialog, everything else would be an + open-dialog. + @param multiple: for open-dialog only: if True, allows selecting + multiple files + @param overwrite_prompt: for save-dialog only: if True, prompt for a + confirmation if a file will be overwritten + @param file_must_exist: if True, the user may only select files that + actually exist + + @returns: a sequence of filenames or None if the dialog has been + cancelled. + """ + + wst = '|'.join(['%s|%s' % (descr, filt) for (descr, filt) in wildcard]) + if not wst: + wst = '%s (*.*)|*.*' % u_('All files') + + flags = win32con.OFN_EXPLORER + if mode.lower().startswith('save'): + open = 0 + if overwrite_prompt: + flags |= win32con.OFN_OVERWRITEPROMPT + else: + open = 1 + if multiple: + flags |= win32con.OFN_ALLOWMULTISELECT + + if file_must_exist: + flags |= win32con.OFN_FILEMUSTEXIST + + dlg = win32ui.CreateFileDialog(open, '', default_file, flags, \ + wst, self.mainWindow._PyCWnd) + dlg.SetOFNTitle(title) + if default_dir: + dlg.SetOFNInitialDir(default_dir) + + result = None + if dlg.DoModal() == win32con.IDOK: + if multiple: + result = dlg.GetPathNames() + else: + result = [dlg.GetPathName()] + + return result + + + # ------------------------------------------------------------------------- + # Select a directory + # ------------------------------------------------------------------------- + + def _ui_select_dir_(self, title, default_dir, new_dir): + """ + Bring up a dialog for selecting a directory path. + + @param title: Message to show on the dialog + @param default_dir: the default directory, or the empty string + @param new_dir: If true, add "Create new directory" button and allow + directory names to be editable. On Windows the new directory button + is only available with recent versions of the common dialogs. + + @returns: a path or None if the dialog has been cancelled. + """ + + BIF_EDITBOX = 0x16 # editbox + BIF_NEWDIALOGSTYLE = 0x40 # use the new dialog layout + BIF_NONEWFOLDERBUTTON = 0x200 # hide new folder button + + flags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE + if not new_dir: + flags |= BIF_NONEWFOLDERBUTTON + + # TODO + defaultDir = None + result = shell.SHBrowseForFolder(self.main_window._PyCWnd, defaultDir,\ + title, flags, None, None) + if result is not None: + result = result[1] + return result + + # --------------------------------------------------------------------------- # Display an about box # --------------------------------------------------------------------------- _______________________________________________ commit-gnue mailing list commit-gnue@gnu.org http://lists.gnu.org/mailman/listinfo/commit-gnue