diff --git a/gramps/cli/arghandler.py b/gramps/cli/arghandler.py index 47e9b8da6..542ca26d6 100644 --- a/gramps/cli/arghandler.py +++ b/gramps/cli/arghandler.py @@ -52,6 +52,7 @@ from .plug import cl_report, cl_book from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext from gramps.gen.constfunc import conv_to_unicode +from gramps.gen.config import config #------------------------------------------------------------------------- # @@ -490,8 +491,8 @@ class ArgHandler(object): self.imp_db_path, title = self.dbman.create_new_db_cli() else: self.imp_db_path = get_empty_tempdir("import_dbdir") - - newdb = self.dbstate.make_database("bsddb") + dbid = config.get('behavior.database-backend') + newdb = self.dbstate.make_database(dbid) newdb.write_version(self.imp_db_path) try: diff --git a/gramps/gen/config.py b/gramps/gen/config.py index c97f65b12..af2d90130 100644 --- a/gramps/gen/config.py +++ b/gramps/gen/config.py @@ -134,6 +134,7 @@ register('behavior.last-check-for-updates', "1970/01/01") register('behavior.previously-seen-updates', []) register('behavior.do-not-show-previously-seen-updates', True) register('behavior.database-path', os.path.join( HOME_DIR, 'grampsdb')) +register('behavior.database-backend', 'bsddb') register('behavior.date-about-range', 50) register('behavior.date-after-range', 50) register('behavior.date-before-range', 50) diff --git a/gramps/gui/configure.py b/gramps/gui/configure.py index bd4a133bf..8146f5090 100644 --- a/gramps/gui/configure.py +++ b/gramps/gui/configure.py @@ -1387,25 +1387,59 @@ class GrampsPreferences(ConfigureDialog): self.uistate.viewmanager.do_reg_plugins(self.dbstate, self.uistate) + def database_backend_changed(self, obj): + the_list = obj.get_model() + the_iter = obj.get_active_iter() + db_choice = the_list.get_value(the_iter, 2) + config.set('behavior.database-backend', db_choice) + def add_famtree_panel(self, configdialog): grid = Gtk.Grid() grid.set_border_width(12) grid.set_column_spacing(6) grid.set_row_spacing(6) + current_line = 0 + backend_plugins = self.uistate.viewmanager._pmgr.get_reg_databases() + obox = Gtk.ComboBox() + cell = Gtk.CellRendererText() + obox.pack_start(cell, True) + obox.add_attribute(cell, 'text', 1) + # Build model: + model = Gtk.ListStore(GObject.TYPE_INT, + GObject.TYPE_STRING, + GObject.TYPE_STRING) + count = 0 + active = 0 + default = config.get('behavior.database-backend') + for plugin in sorted(backend_plugins, key=lambda plugin: plugin.name): + if plugin.id == default: + active = count + model.append(row=[count, plugin.name, plugin.id]) + count += 1 + obox.set_model(model) + # set the default value as active in the combo + obox.set_active(active) + obox.connect('changed', self.database_backend_changed) + lwidget = BasicLabel("%s: " % _('Database backend')) + grid.attach(lwidget, 1, current_line, 1, 1) + grid.attach(obox, 2, current_line, 1, 1) + current_line += 1 self.dbpath_entry = Gtk.Entry() self.add_path_box(grid, _('Family Tree Database path'), - 0, self.dbpath_entry, config.get('behavior.database-path'), + current_line, self.dbpath_entry, config.get('behavior.database-path'), self.set_dbpath, self.select_dbpath) + current_line += 1 #self.add_entry(grid, # _('Family Tree Database path'), # 0, 'behavior.database-path') self.add_checkbox(grid, _('Automatically load last Family Tree'), - 1, 'behavior.autoload') + current_line, 'behavior.autoload') + current_line += 1 return _('Family Tree'), grid diff --git a/gramps/gui/dbman.py b/gramps/gui/dbman.py index eda65fe06..31b3f281e 100644 --- a/gramps/gui/dbman.py +++ b/gramps/gui/dbman.py @@ -80,6 +80,7 @@ from .ddtargets import DdTargets from gramps.gen.recentfiles import rename_filename, remove_filename from .glade import Glade from gramps.gen.db.exceptions import DbException +from gramps.gen.config import config _RETURN = Gdk.keyval_from_name("Return") _KP_ENTER = Gdk.keyval_from_name("KP_Enter") @@ -104,25 +105,6 @@ ICON_COL = 6 RCS_BUTTON = { True : _('_Extract'), False : _('_Archive') } -class DatabaseDialog(Gtk.MessageDialog): - def __init__(self, parent, options): - """ - options = [(pdata, number), ...] - """ - Gtk.MessageDialog.__init__(self, - parent, - flags=Gtk.DialogFlags.MODAL, - type=Gtk.MessageType.QUESTION, - ) - self.set_icon(ICON) - self.set_title('') - self.set_markup('%s' % - _('Database Backend for New Tree')) - self.format_secondary_text( - _("Please select a database backend type:")) - for option, number in options: - self.add_button(option.name, number) - class DbManager(CLIDbManager): """ Database Manager. Opens a database manager window that allows users to @@ -780,23 +762,7 @@ class DbManager(CLIDbManager): message. """ self.new.set_sensitive(False) - dbid = None - pmgr = BasePluginManager.get_instance() - pdata = pmgr.get_reg_databases() - # If just one database backend, just use it: - if len(pdata) == 0: - DbManager.ERROR(_("No available database backends"), - _("Please check your dependencies.")) - elif len(pdata) == 1: - dbid = pdata[0].id - elif len(pdata) > 1: - options = sorted(list(zip(pdata, range(1, len(pdata) + 1))), key=lambda items: items[0].name) - d = DatabaseDialog(self.top, options) - number = d.run() - d.destroy() - if number >= 0: - dbid = [option[0].id for option in options if option[1] == number][0] - ### Now, let's load it up + dbid = config.get('behavior.database-backend') if dbid: try: self._create_new_db(dbid=dbid)