* src/DbPrompter.py: Add NewNativeDbPrompter class for setting up
a native database. Enable opening any format on the startup. * src/gramps_main.py: Use NewNativeDbPrompter when opening non-native data. svn: r3237
This commit is contained in:
parent
3213e0e928
commit
e0973cb653
@ -1,3 +1,9 @@
|
|||||||
|
2004-06-28 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||||
|
* src/DbPrompter.py: Add NewNativeDbPrompter class for setting up
|
||||||
|
a native database. Enable opening any format on the startup.
|
||||||
|
* src/gramps_main.py: Use NewNativeDbPrompter when opening
|
||||||
|
non-native data.
|
||||||
|
|
||||||
2004-06-27 Don Allingham <dallingham@users.sourceforge.net>
|
2004-06-27 Don Allingham <dallingham@users.sourceforge.net>
|
||||||
* src/gramps_main.py: fix import problem
|
* src/gramps_main.py: fix import problem
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ import Utils
|
|||||||
import const
|
import const
|
||||||
import GrampsCfg
|
import GrampsCfg
|
||||||
import QuestionDialog
|
import QuestionDialog
|
||||||
|
import Plugins
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -58,6 +59,7 @@ class DbPrompter:
|
|||||||
|
|
||||||
def __init__(self,parent,want_new,parent_window=None,file_hint=None):
|
def __init__(self,parent,want_new,parent_window=None,file_hint=None):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
self.parent_window = parent_window
|
||||||
self.file_hint = file_hint
|
self.file_hint = file_hint
|
||||||
opendb = gtk.glade.XML(const.gladeFile, "opendb","gramps")
|
opendb = gtk.glade.XML(const.gladeFile, "opendb","gramps")
|
||||||
top = opendb.get_widget('opendb')
|
top = opendb.get_widget('opendb')
|
||||||
@ -89,8 +91,8 @@ class DbPrompter:
|
|||||||
|
|
||||||
def chooser(self,save):
|
def chooser(self,save):
|
||||||
if save:
|
if save:
|
||||||
choose = gtk.FileChooserDialog('Create GRAMPS database',
|
choose = gtk.FileChooserDialog(_('GRAMPS: Create database'),
|
||||||
None,
|
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,
|
||||||
@ -98,34 +100,118 @@ class DbPrompter:
|
|||||||
gtk.RESPONSE_OK))
|
gtk.RESPONSE_OK))
|
||||||
self.parent.clear_database()
|
self.parent.clear_database()
|
||||||
else:
|
else:
|
||||||
choose = gtk.FileChooserDialog('Open GRAMPS database',
|
choose = gtk.FileChooserDialog(_('GRAMPS: Open database'),
|
||||||
None,
|
self.parent_window,
|
||||||
gtk.FILE_CHOOSER_ACTION_OPEN,
|
gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||||
(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)
|
choose.set_local_only(gtk.FALSE)
|
||||||
|
# Always add automatic (macth all files) filter
|
||||||
filter = gtk.FileFilter()
|
filter = gtk.FileFilter()
|
||||||
filter.set_name(_('GRAMPS databases'))
|
filter.set_name(_('Automatic'))
|
||||||
filter.add_pattern('*.grdb')
|
|
||||||
choose.add_filter(filter)
|
|
||||||
|
|
||||||
filter = gtk.FileFilter()
|
|
||||||
filter.set_name(_('All files'))
|
|
||||||
filter.add_pattern('*')
|
filter.add_pattern('*')
|
||||||
choose.add_filter(filter)
|
choose.add_filter(filter)
|
||||||
|
|
||||||
|
# Always add native format filter
|
||||||
|
filter = gtk.FileFilter()
|
||||||
|
filter.set_name(_('GRAMPS databases'))
|
||||||
|
filter.add_mime_type('application/x-gramps')
|
||||||
|
choose.add_filter(filter)
|
||||||
|
|
||||||
if save:
|
if save:
|
||||||
|
# Set the suggested filename for the newly created file
|
||||||
if self.file_hint:
|
if self.file_hint:
|
||||||
choose.set_filename(self.file_hint)
|
choose.set_filename(self.file_hint)
|
||||||
elif GrampsCfg.lastfile:
|
elif GrampsCfg.lastfile:
|
||||||
choose.set_filename(GrampsCfg.lastfile)
|
choose.set_filename(GrampsCfg.lastfile)
|
||||||
|
else:
|
||||||
|
# Add more data type selections if opening existing db
|
||||||
|
for (importData,filter,mime_type) in Plugins._imports:
|
||||||
|
choose.add_filter(filter)
|
||||||
|
|
||||||
|
response = choose.run()
|
||||||
|
if response == gtk.RESPONSE_OK:
|
||||||
|
filename = choose.get_filename()
|
||||||
|
if save:
|
||||||
|
if os.path.splitext(filename)[1] != ".grdb":
|
||||||
|
filename = filename + ".grdb"
|
||||||
|
choose.destroy()
|
||||||
|
self.parent.read_file(filename)
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
filetype = gnome.vfs.get_mime_type(filename)
|
||||||
|
if filetype == 'application/x-gramps':
|
||||||
|
choose.destroy()
|
||||||
|
self.parent.read_file(filename)
|
||||||
|
return 1
|
||||||
|
(junk,the_file) = os.path.split(filename)
|
||||||
|
for (importData,filter,mime_type) in Plugins._imports:
|
||||||
|
if filetype == mime_type or the_file == mime_type:
|
||||||
|
choose.destroy()
|
||||||
|
QuestionDialog.OkDialog( _("Opening non-native format"),
|
||||||
|
_("New gramps database has to be set up "
|
||||||
|
"when opening non-native formats. The "
|
||||||
|
"following dialog will let you select "
|
||||||
|
"the new database."),
|
||||||
|
self.parent_window)
|
||||||
|
NewNativeDbPrompter(self.parent,self.parent_window,filename)
|
||||||
|
importData(self.parent.db,filename)
|
||||||
|
self.parent.import_tool_callback()
|
||||||
|
return 1
|
||||||
|
QuestionDialog.ErrorDialog( _("Could not open file: %s") % filename,
|
||||||
|
_('The type "%s" is not in the list of known file types') % filetype )
|
||||||
|
|
||||||
|
else:
|
||||||
|
choose.destroy()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# NewNativeDbPrompter
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
class NewNativeDbPrompter:
|
||||||
|
"""Set up a new empty native database."""
|
||||||
|
|
||||||
|
def __init__(self,parent,parent_window=None,file_hint=None):
|
||||||
|
self.parent = parent
|
||||||
|
self.parent_window = parent_window
|
||||||
|
self.file_hint = file_hint
|
||||||
|
self.chooser()
|
||||||
|
|
||||||
|
def chooser(self):
|
||||||
|
choose = gtk.FileChooserDialog(_('GRAMPS: Create GRAMPS database'),
|
||||||
|
self.parent_window,
|
||||||
|
gtk.FILE_CHOOSER_ACTION_SAVE,
|
||||||
|
(gtk.STOCK_CANCEL,
|
||||||
|
gtk.RESPONSE_CANCEL,
|
||||||
|
gtk.STOCK_OPEN,
|
||||||
|
gtk.RESPONSE_OK))
|
||||||
|
self.parent.clear_database()
|
||||||
|
|
||||||
|
# Always add automatic (macth all files) filter
|
||||||
|
filter = gtk.FileFilter()
|
||||||
|
filter.set_name(_('Automatic'))
|
||||||
|
filter.add_pattern('*')
|
||||||
|
choose.add_filter(filter)
|
||||||
|
|
||||||
|
# Always add native format filter
|
||||||
|
filter = gtk.FileFilter()
|
||||||
|
filter.set_name(_('GRAMPS databases'))
|
||||||
|
filter.add_mime_type('application/x-gramps')
|
||||||
|
choose.add_filter(filter)
|
||||||
|
|
||||||
|
if self.file_hint:
|
||||||
|
choose.set_filename(self.file_hint)
|
||||||
|
elif GrampsCfg.lastfile:
|
||||||
|
choose.set_filename(GrampsCfg.lastfile)
|
||||||
|
|
||||||
response = choose.run()
|
response = choose.run()
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
filename = choose.get_filename()
|
filename = choose.get_filename()
|
||||||
if save and os.path.splitext(filename)[1] != ".grdb":
|
if os.path.splitext(filename)[1] != ".grdb":
|
||||||
filename = filename + ".grdb"
|
filename = filename + ".grdb"
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
self.parent.read_file(filename)
|
self.parent.read_file(filename)
|
||||||
|
@ -1475,7 +1475,7 @@ class Gramps:
|
|||||||
"following dialog will let you select "
|
"following dialog will let you select "
|
||||||
"the new database."),
|
"the new database."),
|
||||||
self.topWindow)
|
self.topWindow)
|
||||||
DbPrompter.DbPrompter(self,1,self.topWindow,filename)
|
DbPrompter.NewNativeDbPrompter(self,self.topWindow,filename)
|
||||||
importData(self.db,filename)
|
importData(self.db,filename)
|
||||||
self.import_tool_callback()
|
self.import_tool_callback()
|
||||||
opened = 1
|
opened = 1
|
||||||
@ -1531,9 +1531,12 @@ class Gramps:
|
|||||||
opened = 0
|
opened = 0
|
||||||
for (importData,filter,mime_type) in Plugins._imports:
|
for (importData,filter,mime_type) in Plugins._imports:
|
||||||
if filetype == mime_type or the_file == mime_type:
|
if filetype == mime_type or the_file == mime_type:
|
||||||
|
print mime_type
|
||||||
|
print "Keys before:", self.db.get_person_keys()
|
||||||
importData(self.db,filename)
|
importData(self.db,filename)
|
||||||
self.import_tool_callback()
|
self.import_tool_callback()
|
||||||
opened = 1
|
opened = 1
|
||||||
|
print "Keys after:", self.db.get_person_keys()
|
||||||
break
|
break
|
||||||
if not opened:
|
if not opened:
|
||||||
ErrorDialog( _("Could not open file: %s") % filename,
|
ErrorDialog( _("Could not open file: %s") % filename,
|
||||||
|
Loading…
Reference in New Issue
Block a user