* src/DbPrompter.py: Factory functions for file filters;

Support for explicit format selection for open and import dialogs.


svn: r4097
This commit is contained in:
Alex Roitman 2005-02-26 02:34:11 +00:00
parent a813772ede
commit 7e981442b0
2 changed files with 85 additions and 68 deletions

View File

@ -17,6 +17,9 @@
* src/Sources.py (SourceEditor.draw): Do not discard reference
data when adding new source.
* src/DbPrompter.py: Factory functions for file filters;
Support for explicit format selection for open and import dialogs.
2005-02-24 Alex Roitman <shura@alex.neuro.umn.edu>
* src/MediaView.py (on_select_row): Add garbage collection call.

View File

@ -152,34 +152,23 @@ class ExistingDbPrompter:
gtk.STOCK_OPEN,
gtk.RESPONSE_OK))
choose.set_local_only(False)
# Always add automatic (macth all files) filter
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('All files'))
mime_filter.add_pattern('*')
choose.add_filter(mime_filter)
# Always add native format filter
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GRAMPS databases'))
mime_filter.add_mime_type(const.app_gramps)
choose.add_filter(mime_filter)
# Always add native format filter
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GRAMPS XML databases'))
mime_filter.add_mime_type(const.app_gramps_xml)
choose.add_filter(mime_filter)
# Always add native format filter
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GEDCOM files'))
mime_filter.add_mime_type(const.app_gedcom)
choose.add_filter(mime_filter)
add_all_files_filter(choose)
add_grdb_filter(choose)
add_xml_filter(choose)
add_gedcom_filter(choose)
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
# Add more data type selections if opening existing db
for (importData,mime_filter,mime_type,native_format) in PluginMgr.import_list:
if not native_format:
choose.add_filter(mime_filter)
format_list.append(mime_type)
_KNOWN_FORMATS[mime_type] = mime_filter.get_name()
(box,type_selector) = format_maker(format_list)
choose.set_extra_widget(box)
# Suggested folder: try last open file, last import, last export,
# then home.
@ -197,6 +186,8 @@ class ExistingDbPrompter:
filename = choose.get_filename()
if len(filename) == 0:
return False
filetype = type_selector.get_value()
if filetype == 'auto':
filetype = get_mime_type(filename)
(the_path,the_file) = os.path.split(filename)
choose.destroy()
@ -267,20 +258,19 @@ class ImportDbPrompter:
gtk.RESPONSE_OK))
choose.set_local_only(False)
# Always add automatic (macth all files) filter
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('All files'))
mime_filter.add_pattern('*')
choose.add_filter(mime_filter)
add_all_files_filter(choose)
add_grdb_filter(choose)
# Always add native format filter
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GRAMPS databases'))
mime_filter.add_mime_type(const.app_gramps)
choose.add_filter(mime_filter)
format_list = [const.app_gramps]
# Add more data type selections if opening existing db
for (importData,mime_filter,mime_type,native_format) in PluginMgr.import_list:
choose.add_filter(mime_filter)
format_list.append(mime_type)
_KNOWN_FORMATS[mime_type] = mime_filter.get_name()
(box,type_selector) = format_maker(format_list)
choose.set_extra_widget(box)
# Suggested folder: try last open file, import, then last export,
# then home.
@ -296,6 +286,8 @@ class ImportDbPrompter:
response = choose.run()
if response == gtk.RESPONSE_OK:
filename = choose.get_filename()
filetype = type_selector.get_value()
if filetype == 'auto':
filetype = get_mime_type(filename)
if filetype == 'application/x-gramps':
@ -349,16 +341,8 @@ class NewNativeDbPrompter:
self.parent.clear_database()
# Always add automatic (macth all files) filter
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('All files'))
mime_filter.add_pattern('*')
choose.add_filter(mime_filter)
# Always add native format filter
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GRAMPS databases'))
mime_filter.add_mime_type(const.app_gramps)
choose.add_filter(mime_filter)
add_all_files_filter(choose)
add_grdb_filter(choose)
# Suggested folder: try last open file, import, then last export,
# then home.
@ -431,32 +415,14 @@ class NewSaveasDbPrompter:
(box,type_selector) = format_maker([const.app_gramps,
const.app_gramps_xml,
const.app_gedcom])
box.show_all()
choose.set_extra_widget(box)
# Always add automatic (macth all files) filter
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('All files'))
mime_filter.add_pattern('*')
choose.add_filter(mime_filter)
# Always add native format filter
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GRAMPS databases'))
mime_filter.add_mime_type(const.app_gramps)
choose.add_filter(mime_filter)
# Always add native format filter
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GRAMPS XML databases'))
mime_filter.add_mime_type(const.app_gramps_xml)
choose.add_filter(mime_filter)
# Always add native format filter
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GEDCOM files'))
mime_filter.add_mime_type(const.app_gedcom)
choose.add_filter(mime_filter)
add_all_files_filter(choose)
add_gramps_files_filter(choose)
add_grdb_filter(choose)
add_xml_filter(choose)
add_gedcom_filter(choose)
# Suggested folder: try last open file, import, then last export,
# then home.
@ -603,4 +569,52 @@ def format_maker(formats):
label = gtk.Label(_('Select file type:'))
box.pack_start(label,expand=False,fill=False,padding=6)
box.add(type_selector)
box.show_all()
return (box,type_selector)
def add_all_files_filter(chooser):
"""
Add an all-permitting filter to the file chooser dialog.
"""
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('All files'))
mime_filter.add_pattern('*')
chooser.add_filter(mime_filter)
def add_gramps_files_filter(chooser):
"""
Add an all-GRAMPS filter to the file chooser dialog.
"""
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('All GRAMPS files'))
mime_filter.add_mime_type(const.app_gramps)
mime_filter.add_mime_type(const.app_gramps_xml)
mime_filter.add_mime_type(const.app_gedcom)
chooser.add_filter(mime_filter)
def add_grdb_filter(chooser):
"""
Add an GRDB filter to the file chooser dialog.
"""
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GRAMPS databases'))
mime_filter.add_mime_type(const.app_gramps)
chooser.add_filter(mime_filter)
def add_xml_filter(chooser):
"""
Add a GRAMPS XML filter to the file chooser dialog.
"""
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GRAMPS XML databases'))
mime_filter.add_mime_type(const.app_gramps_xml)
chooser.add_filter(mime_filter)
def add_gedcom_filter(chooser):
"""
Add a GEDCOM filter to the file chooser dialog.
"""
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GEDCOM files'))
mime_filter.add_mime_type(const.app_gedcom)
chooser.add_filter(mime_filter)