[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9418 - trunk/gnue-forms/src/uidrivers/gtk2/widgets/form
From: |
johannes |
Subject: |
[gnue] r9418 - trunk/gnue-forms/src/uidrivers/gtk2/widgets/form |
Date: |
Wed, 28 Feb 2007 07:51:22 -0600 (CST) |
Author: johannes
Date: 2007-02-28 07:51:21 -0600 (Wed, 28 Feb 2007)
New Revision: 9418
Modified:
trunk/gnue-forms/src/uidrivers/gtk2/widgets/form/widget.py
Log:
Added file- and directory-selection dialogs
issue152 in-progress
Modified: trunk/gnue-forms/src/uidrivers/gtk2/widgets/form/widget.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/widgets/form/widget.py 2007-02-28
13:01:19 UTC (rev 9417)
+++ trunk/gnue-forms/src/uidrivers/gtk2/widgets/form/widget.py 2007-02-28
13:51:21 UTC (rev 9418)
@@ -384,6 +384,103 @@
# ---------------------------------------------------------------------------
+ # Create a FileChooser dialog to select filenames
+ # ---------------------------------------------------------------------------
+
+ 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.
+ """
+
+ if mode.lower().startswith('save'):
+ action = gtk.FILE_CHOOSER_ACTION_SAVE
+ button = gtk.STOCK_SAVE
+ else:
+ action = gtk.FILE_CHOOSER_ACTION_OPEN
+ button = gtk.STOCK_OPEN
+
+ dlg = gtk.FileChooserDialog(title, self.mainWindow, action,
+ (button, gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL,
+ gtk.RESPONSE_REJECT))
+ try:
+ result = None
+ dlg.set_select_multiple(multiple)
+ dlg.set_do_overwrite_confirmation(overwrite_prompt)
+
+ dlg.set_current_folder(default_dir)
+ dlg.set_filename(default_file)
+
+ for (descr, pattern) in wildcard:
+ flt = gtk.FileFilter()
+ flt.set_name(descr)
+ flt.add_pattern(pattern)
+ dlg.add_filter(flt)
+
+ if dlg.run() == gtk.RESPONSE_ACCEPT:
+ result = dlg.get_filenames()
+
+ finally:
+ dlg.destroy()
+
+ return result
+
+
+ # ---------------------------------------------------------------------------
+ # Create a FileChooser dialog to select a directory name
+ # ---------------------------------------------------------------------------
+
+ 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: In GTK2+ the "Create new directory" button is always
+ available and can't be turned off
+
+ @returns: a path or None if the dialog has been cancelled.
+ """
+
+ dlg = gtk.FileChooserDialog(title, self.mainWindow,
+ gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL,
+ gtk.RESPONSE_REJECT))
+ try:
+ result = None
+
+ dlg.set_current_folder(default_dir)
+
+ if dlg.run() == gtk.RESPONSE_ACCEPT:
+ result = dlg.get_filenames()
+
+ finally:
+ dlg.destroy()
+
+ return result
+
+
+ # ---------------------------------------------------------------------------
# Display an about box
# ---------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9418 - trunk/gnue-forms/src/uidrivers/gtk2/widgets/form,
johannes <=