commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r9419 - trunk/gnue-forms/src/uidrivers/wx/widgets/form


From: johannes
Subject: [gnue] r9419 - trunk/gnue-forms/src/uidrivers/wx/widgets/form
Date: Wed, 28 Feb 2007 08:10:07 -0600 (CST)

Author: johannes
Date: 2007-02-28 08:10:07 -0600 (Wed, 28 Feb 2007)
New Revision: 9419

Modified:
   trunk/gnue-forms/src/uidrivers/wx/widgets/form/widget.py
Log:
Added File- and Dir-Selection dialogs

issue152 in-progress



Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/form/widget.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/form/widget.py    2007-02-28 
13:51:21 UTC (rev 9418)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/form/widget.py    2007-02-28 
14:10:07 UTC (rev 9419)
@@ -277,7 +277,102 @@
     finally:
       dialog.Destroy ()
 
+  # -------------------------------------------------------------------------
+  # 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')
+
+      if mode.lower().startswith('save'):
+          flags = wxSAVE
+          if overwrite_prompt:
+              flags |= wxOVERWRITE_PROMPT
+      else:
+          flags = wxOPEN
+          if multiple:
+              flags |= wxMULTIPLE
+
+      if file_must_exist:
+          flags |= wxFILE_MUST_EXIST
+
+      dlg = wxFileDialog(self.mainWindow, title, default_dir, default_file,
+              wst, flags)
+      try:
+          result = None
+          mres = dlg.ShowModal()
+          if mres == wxID_OK:
+              if multiple:
+                  result = dlg.GetPaths()
+              else:
+                  result = [dlg.GetPath()]
+      finally:
+          dlg.Destroy()
+
+      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.
+      """
+        
+      if new_dir:
+          flags = wxDD_NEW_DIR_BUTTON
+      else:
+          flags = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
+
+      dlg = wxDirDialog(self.mainWindow, title, default_dir, flags)
+      try:
+          result = None
+          mres = dlg.ShowModal()
+          if mres == wxID_OK:
+              result = dlg.GetPath()
+
+      finally:
+          dlg.Destroy()
+            
+      return result
+
+
   # ---------------------------------------------------------------------------
   # Display an about box
   # ---------------------------------------------------------------------------





reply via email to

[Prev in Thread] Current Thread [Next in Thread]