From 5c71a35aea09d6b94fe0c3c6312e79cba03079c6 Mon Sep 17 00:00:00 2001 From: noirauds Date: Tue, 17 Feb 2015 20:30:03 +0100 Subject: [PATCH] geography: 7948 : Add path selector to the text entry for tile cache --- gramps/plugins/lib/maps/geography.py | 36 ++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/gramps/plugins/lib/maps/geography.py b/gramps/plugins/lib/maps/geography.py index 4d0b1b2b6..eeac38522 100644 --- a/gramps/plugins/lib/maps/geography.py +++ b/gramps/plugins/lib/maps/geography.py @@ -60,6 +60,7 @@ from gramps.gui.managedwindow import ManagedWindow from gramps.gen.config import config from gramps.gui.editors import EditPlace, EditEvent, EditFamily, EditPerson from gramps.gui.selectors.selectplace import SelectPlace +from gramps.gen.constfunc import conv_to_unicode from gi.repository import OsmGpsMap as osmgpsmap from . import constants @@ -1061,11 +1062,11 @@ class GeoGraphyView(OsmGps, NavigationView): table.set_border_width(12) table.set_col_spacings(6) table.set_row_spacings(6) - configdialog.add_text(table, + self.path_entry = Gtk.Entry() + configdialog.add_path_box(table, _('Where to save the tiles for offline mode.'), - 0, line_wrap=False) - configdialog.add_entry(table, '', - 1, 'geography.path') + 0, self.path_entry, config.get('geography.path'), + self.set_tilepath, self.select_tilepath) configdialog.add_text(table, _('If you have no more space in your file system. ' 'You can remove all tiles placed in the above path.\n' @@ -1087,3 +1088,30 @@ class GeoGraphyView(OsmGps, NavigationView): extra_callback=self.update_shortcuts) return _('The map'), table + + def set_tilepath(self, *obj): + if self.path_entry.get_text().strip(): + config.set('geography.path', self.path_entry.get_text()) + else: + config.set('geography.path', GEOGRAPHY_PATH ) + + def select_tilepath(self, *obj): + f = Gtk.FileChooserDialog( + _("Select tile cache directory for offline mode"), + action=Gtk.FileChooserAction.SELECT_FOLDER, + buttons=(Gtk.STOCK_CANCEL, + Gtk.ResponseType.CANCEL, + Gtk.STOCK_APPLY, + Gtk.ResponseType.OK)) + mpath = config.get('geography.path') + if not mpath: + mpath = HOME_DIR + f.set_current_folder(os.path.dirname(mpath)) + + status = f.run() + if status == Gtk.ResponseType.OK: + val = conv_to_unicode(f.get_filename()) + if val: + self.path_entry.set_text(val) + f.destroy() +