* src/DbPrompter.py (SaveAsDbPrompter.change_suggested_name):
Add method; (SaveAsDbPrompter.chooser): Make dialog a class attribute. Connect handler to the filter change event; (get_new_filename): Make a module function (outside any class). svn: r3248
This commit is contained in:
parent
ef0516a415
commit
a0acc27543
@ -1,3 +1,9 @@
|
|||||||
|
2004-07-02 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||||
|
* src/DbPrompter.py (SaveAsDbPrompter.change_suggested_name):
|
||||||
|
Add method; (SaveAsDbPrompter.chooser): Make dialog a class attribute.
|
||||||
|
Connect handler to the filter change event; (get_new_filename): Make
|
||||||
|
a module function (outside any class).
|
||||||
|
|
||||||
2004-07-01 Don Allingham <dallingham@users.sourceforge.net>
|
2004-07-01 Don Allingham <dallingham@users.sourceforge.net>
|
||||||
* src/gramps_main.py: disable find old "find" function
|
* src/gramps_main.py: disable find old "find" function
|
||||||
* src/gramps.glade: enable TreeView find function
|
* src/gramps.glade: enable TreeView find function
|
||||||
|
@ -293,7 +293,7 @@ class NewNativeDbPrompter:
|
|||||||
filter.add_mime_type('application/x-gramps')
|
filter.add_mime_type('application/x-gramps')
|
||||||
choose.add_filter(filter)
|
choose.add_filter(filter)
|
||||||
|
|
||||||
new_filename = self.get_new_filename()
|
new_filename = get_new_filename()
|
||||||
|
|
||||||
choose.set_filename(new_filename)
|
choose.set_filename(new_filename)
|
||||||
choose.set_current_name(os.path.split(new_filename)[1])
|
choose.set_current_name(os.path.split(new_filename)[1])
|
||||||
@ -310,12 +310,6 @@ class NewNativeDbPrompter:
|
|||||||
choose.destroy()
|
choose.destroy()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def get_new_filename(self):
|
|
||||||
ix = 1
|
|
||||||
while os.path.isfile(os.path.expanduser('~/Untitled_%d.grdb' % ix ) ):
|
|
||||||
ix = ix + 1
|
|
||||||
return os.path.expanduser('~/Untitled_%d.grdb' % ix )
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# SaveAsDbPrompter
|
# SaveAsDbPrompter
|
||||||
@ -341,53 +335,57 @@ class SaveAsDbPrompter:
|
|||||||
Select the new file.
|
Select the new file.
|
||||||
Return 1 when selection is made and 0 otherwise.
|
Return 1 when selection is made and 0 otherwise.
|
||||||
"""
|
"""
|
||||||
choose = gtk.FileChooserDialog(_('GRAMPS: Export database'),
|
self.choose = gtk.FileChooserDialog(_('GRAMPS: Export database'),
|
||||||
self.parent_window,
|
self.parent_window,
|
||||||
gtk.FILE_CHOOSER_ACTION_SAVE,
|
gtk.FILE_CHOOSER_ACTION_SAVE,
|
||||||
(gtk.STOCK_CANCEL,
|
(gtk.STOCK_CANCEL,
|
||||||
gtk.RESPONSE_CANCEL,
|
gtk.RESPONSE_CANCEL,
|
||||||
gtk.STOCK_OPEN,
|
gtk.STOCK_OPEN,
|
||||||
gtk.RESPONSE_OK))
|
gtk.RESPONSE_OK))
|
||||||
choose.set_local_only(gtk.FALSE)
|
self.choose.set_local_only(gtk.FALSE)
|
||||||
# Always add automatic (macth all files) filter
|
# Always add automatic (macth all files) filter
|
||||||
filter = gtk.FileFilter()
|
filter = gtk.FileFilter()
|
||||||
filter.set_name(_('By extension'))
|
filter.set_name(_('By extension'))
|
||||||
filter.add_pattern('*')
|
filter.add_pattern('*')
|
||||||
choose.add_filter(filter)
|
self.choose.add_filter(filter)
|
||||||
|
|
||||||
# Always add native format filter
|
# Always add native format filter
|
||||||
filter = gtk.FileFilter()
|
filter = gtk.FileFilter()
|
||||||
filter.set_name(_('GRAMPS databases'))
|
filter.set_name(_('GRAMPS databases'))
|
||||||
filter.add_mime_type('application/x-gramps')
|
filter.add_mime_type('application/x-gramps')
|
||||||
choose.add_filter(filter)
|
self.choose.add_filter(filter)
|
||||||
|
|
||||||
|
chooser_default = self.choose.get_children()[0].get_children()[0].get_children()[0]
|
||||||
|
chooser_default.connect('notify::filter',self.change_suggested_name)
|
||||||
|
|
||||||
# Add more data type selections if opening existing db
|
# Add more data type selections if opening existing db
|
||||||
for (exportData,filter,pattern_list) in Plugins._exports:
|
for (exportData,filter,pattern_list) in Plugins._exports:
|
||||||
choose.add_filter(filter)
|
self.choose.add_filter(filter)
|
||||||
|
|
||||||
if GrampsCfg.lastfile:
|
new_filename = get_new_filename()
|
||||||
choose.set_filename(GrampsCfg.lastfile)
|
self.choose.set_filename(new_filename)
|
||||||
|
self.choose.set_current_name(os.path.split(new_filename)[1])
|
||||||
|
|
||||||
response = choose.run()
|
response = self.choose.run()
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
filename = choose.get_filename()
|
filename = self.choose.get_filename()
|
||||||
filename = os.path.normpath(os.path.abspath(filename))
|
filename = os.path.normpath(os.path.abspath(filename))
|
||||||
(junk,the_file) = os.path.split(filename)
|
(junk,the_file) = os.path.split(filename)
|
||||||
the_ext = os.path.splitext(filename)[1]
|
the_ext = os.path.splitext(filename)[1]
|
||||||
|
|
||||||
if the_ext in ('.grdb', '.GRDB'):
|
if the_ext in ('.grdb', '.GRDB'):
|
||||||
choose.destroy()
|
self.choose.destroy()
|
||||||
try:
|
try:
|
||||||
shutil.copyfile(self.parent.db.get_save_path(),filename)
|
shutil.copyfile(self.parent.db.get_save_path(),filename)
|
||||||
return 1
|
return 1
|
||||||
except shutil.Error, msg:
|
except IOError, msg:
|
||||||
QuestionDialog.ErrorDialog( _("Could not write file: %s") % filename,
|
QuestionDialog.ErrorDialog( _("Could not write file: %s") % filename,
|
||||||
_('System message was: %s') % msg )
|
_('System message was: %s') % msg )
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
for (exportData,filter,pattern_list) in Plugins._exports:
|
for (exportData,filter,pattern_list) in Plugins._exports:
|
||||||
if the_ext in pattern_list:
|
if the_ext in pattern_list:
|
||||||
choose.destroy()
|
self.choose.destroy()
|
||||||
exportData(self.parent.db,filename)
|
exportData(self.parent.db,filename)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
@ -395,5 +393,30 @@ class SaveAsDbPrompter:
|
|||||||
_('The type is not in the list of known file types') )
|
_('The type is not in the list of known file types') )
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
choose.destroy()
|
self.choose.destroy()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def change_suggested_name(self,*args):
|
||||||
|
"""
|
||||||
|
This is the callback of the filter change handler. The suggested
|
||||||
|
file name is set according to the selected filter.
|
||||||
|
"""
|
||||||
|
the_filter = self.choose.get_filter()
|
||||||
|
if the_filter.get_name().find('XML') + 1:
|
||||||
|
self.choose.set_current_name('data.gramps')
|
||||||
|
else:
|
||||||
|
new_filename = get_new_filename()
|
||||||
|
self.choose.set_current_name(os.path.split(new_filename)[1])
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
def get_new_filename():
|
||||||
|
ix = 1
|
||||||
|
while os.path.isfile(os.path.expanduser('~/Untitled_%d.grdb' % ix ) ):
|
||||||
|
ix = ix + 1
|
||||||
|
return os.path.expanduser('~/Untitled_%d.grdb' % ix )
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user