Beispiel #1
0
    def on_ok_clicked(self, obj):
        """The user is satisfied with the dialog choices.  Validate
        the output file name before doing anything else.  If there is
        a file name, gather the options and create the report."""

        # Is there a filename?  This should also test file permissions, etc.
        if not self.parse_target_frame():
            self.window.run()

        # Preparation
        self.parse_format_frame()
        self.parse_user_options()

        self.options.handler.set_paper_metric(
            self.paper_frame.get_paper_metric())
        self.options.handler.set_paper_name(self.paper_frame.get_paper_name())
        self.options.handler.set_orientation(
            self.paper_frame.get_orientation())
        self.options.handler.set_margins(self.paper_frame.get_paper_margins())
        self.options.handler.set_custom_paper_size(
            self.paper_frame.get_custom_paper_size())

        # Create the output document.
        self.make_document()

        # Save options
        self.options.handler.save_options()
        config.set('interface.open-with-default-viewer',
                   self.open_with_app.get_active())
Beispiel #2
0
    def export(self, *obj):
        chooser = Gtk.FileChooserDialog(title=_("Export View as Spreadsheet"),
                                        transient_for=self.uistate.window,
                                        action=Gtk.FileChooserAction.SAVE)
        chooser.add_buttons(_('_Cancel'), Gtk.ResponseType.CANCEL, _('_Save'),
                            Gtk.ResponseType.OK)
        chooser.set_do_overwrite_confirmation(True)

        combobox = Gtk.ComboBoxText()
        label = Gtk.Label(label=_("Format:"))
        label.set_halign(Gtk.Align.END)
        box = Gtk.Box()
        box.pack_start(label, True, True, padding=12)
        box.pack_start(combobox, False, False, 0)
        combobox.append_text(_('CSV'))
        combobox.append_text(_('OpenDocument Spreadsheet'))
        combobox.set_active(0)
        box.show_all()
        chooser.set_extra_widget(box)
        default_dir = config.get('paths.recent-export-dir')
        chooser.set_current_folder(default_dir)

        while True:
            value = chooser.run()
            fn = chooser.get_filename()
            fl = combobox.get_active()
            if value == Gtk.ResponseType.OK:
                if fn:
                    chooser.destroy()
                    break
            else:
                chooser.destroy()
                return
        config.set('paths.recent-export-dir', os.path.split(fn)[0])
        self.write_tabbed_file(fn, fl)
Beispiel #3
0
def _display_welcome_message(parent=None):
    """
    Display a welcome message to the user.
    """
    if not config.get('behavior.betawarn'):
        from .dialog import WarningDialog
        WarningDialog(
            _('Danger: This is unstable code!'),
            _("This Gramps ('master') is a development release. "
              "This version is not meant for normal usage. Use "
              "at your own risk.\n"
              "\n"
              "This version may:\n"
              "1) Work differently than you expect.\n"
              "2) Fail to run at all.\n"
              "3) Crash often.\n"
              "4) Corrupt your data.\n"
              "5) Save data in a format that is incompatible with the "
              "official release.\n"
              "\n"
              "%(bold_start)sBACKUP%(bold_end)s "
              "your existing databases before opening "
              "them with this version, and make sure to export your "
              "data to XML every now and then."
             ) % {'bold_start' : '<b>',
                  'bold_end'   : '</b>'},
            parent=parent)
        config.set('behavior.autoload', False)
        config.set('behavior.betawarn', True)
Beispiel #4
0
    def save(self):
        """
        Perform the actual Save As/Export operation.

        Depending on the success status, set the text for the final page.

        """
        success = False
        try:
            if (self.option_box_instance
                    and hasattr(self.option_box_instance, "no_fileselect")):
                filename = ""
            else:
                filename = self.chooser.get_filename()
                config.set('paths.recent-export-dir',
                           os.path.split(filename)[0])
            ix = self.get_selected_format_index()
            config.set('behavior.recent-export-type', ix)
            export_function = self.map_exporters[ix].get_export_function()
            success = export_function(
                self.dbstate.db, filename,
                User(error=ErrorDialog,
                     parent=self.window,
                     callback=self.callback), self.option_box_instance)
        except:
            #an error not catched in the export_function itself
            success = False
            log.error(_("Error exporting your Family Tree"), exc_info=True)
        return success
Beispiel #5
0
    def do_import(self, dialog, importer, filename):
        self.import_info = None
        position = self.window.get_position() # crock
        dialog.hide()
        self.window.move(position[0], position[1])
        self._begin_progress()

        try:
            #an importer can return an object with info, object.info_text()
            #returns that info. Otherwise None is set to import_info
            self.import_info = importer(self.dbstate.db, filename,
                            User(callback=self._pulse_progress,
                                 uistate=self.uistate,
                                 dbstate=self.dbstate))
            dirname = os.path.dirname(filename) + os.path.sep
            config.set('paths.recent-import-dir', dirname)
        except UnicodeError as msg:
            ErrorDialog(
                _("Could not import file: %s") % filename,
                _("This file incorrectly identifies its character "
                  "set, so it cannot be accurately imported. Please fix the "
                  "encoding, and import again") + "\n\n %s" % msg,
                parent=self.uistate.window)
        except Exception:
            _LOG.error("Failed to import database.", exc_info=True)
        self._end_progress()
Beispiel #6
0
    def save(self):
        """
        Perform the actual Save As/Export operation.

        Depending on the success status, set the text for the final page.

        """
        success = False
        try:
            if (self.option_box_instance and
                hasattr(self.option_box_instance, "no_fileselect")):
                filename = ""
            else:
                filename = self.chooser.get_filename()
                config.set('paths.recent-export-dir', os.path.split(filename)[0])
            ix = self.get_selected_format_index()
            config.set('behavior.recent-export-type', ix)
            export_function = self.map_exporters[ix].get_export_function()
            success = export_function(self.dbstate.db,
                            filename,
                            User(error=ErrorDialog, parent=self.uistate.window,
                                 callback=self.callback),
                            self.option_box_instance)
        except:
            #an error not catched in the export_function itself
            success = False
            log.error(_("Error exporting your Family Tree"), exc_info=True)
        return success
    def on_ok_clicked(self, obj):
        """The user is satisfied with the dialog choices.  Validate
        the output file name before doing anything else.  If there is
        a file name, gather the options and create the report."""

        # Is there a filename?  This should also test file permissions, etc.
        if not self.parse_target_frame():
            self.window.run()

        # Preparation
        self.parse_format_frame()
        self.parse_user_options()

        self.options.handler.set_paper_metric(
            self.paper_frame.get_paper_metric())
        self.options.handler.set_paper_name(
            self.paper_frame.get_paper_name())
        self.options.handler.set_orientation(
            self.paper_frame.get_orientation())
        self.options.handler.set_margins(
            self.paper_frame.get_paper_margins())
        self.options.handler.set_custom_paper_size(
            self.paper_frame.get_custom_paper_size())

        # Create the output document.
        self.make_document()

        # Save options
        self.options.handler.save_options()
        config.set('interface.open-with-default-viewer',
                   self.open_with_app.get_active())
Beispiel #8
0
def clear_history(self):
    """
    Clear all history objects. Replaces DisplayState method.
    Reload history if it is valid for the db.
    """
    hist_list = list(self.history_lookup.values())
    if not hist_list:
        return
    for history in hist_list:
        history.clear()
    if not history.dbstate.is_open():
        return
    try:
        with open(os.path.join(os.path.dirname(__file__), "hist_save.ini"),
                  mode='r', encoding='utf-8') as _fp:
            hist = json.load(_fp)
    except:
        hist = None
        # set these once if not run before so user can unset if he wants
        config.set("behavior.autoload", True)
        config.set("preferences.use-last-view", True)
    if not hist or hist['filename'] != history.dbstate.db.get_dbid():
        return
    for history in hist_list:
        history.mru = hist[history.nav_type]
        if not history.mru:
            continue
        history.history = history.mru[:]
        history.index = len(history.mru) - 1
        newact = history.history[history.index]
        history.emit('mru-changed', (history.mru, ))
        history.emit('active-changed', (newact,))
Beispiel #9
0
    def __init__(self, msg1, msg2, task1, task2, parent=None):
        self.xml = Glade(toplevel='savedialog')
        
        self.top = self.xml.toplevel
        self.top.set_icon(ICON)
        self.top.set_title("%s - Gramps" % msg1)
        
        self.dontask = self.xml.get_object('dontask')
        self.task1 = task1
        self.task2 = task2
        
        label1 = self.xml.get_object('sd_label1')
        label1.set_text('<span weight="bold" size="larger">%s</span>' % msg1)
        label1.set_use_markup(True)
        
        label2 = self.xml.get_object('sd_label2')
        label2.set_text(msg2)
        label2.set_use_markup(True)
        if parent:
            self.top.set_transient_for(parent)
        self.top.show()
        response = self.top.run()
        if response == Gtk.ResponseType.NO:
            self.task1()
        elif response == Gtk.ResponseType.YES:
            self.task2()

        config.set('interface.dont-ask', self.dontask.get_active())
        self.top.destroy()
Beispiel #10
0
    def __init__(self, title, pdata, dbstate, uistate,
                 bm_type, nav_group):
        NavigationView.__init__(self, title, pdata, dbstate, uistate,
                                bm_type, nav_group)

        OsmGps.__init__(self)
        self.dbstate = dbstate
        self.dbstate.connect('database-changed', self.change_db)
        self.default_text = "Enter location here!"
        self.centerlon = config.get("geography.center-lon")
        self.centerlat = config.get("geography.center-lat")
        self.zoom = config.get("geography.zoom")
        self.lock = config.get("geography.lock")
        if config.get('geography.path') == "":
            config.set('geography.path', GEOGRAPHY_PATH)

        self.format_helper = FormattingHelper(self.dbstate)
        self.centerlat = self.centerlon = 0.0
        self.cross_map = None
        self.current_map = None
        self.without = 0
        self.place_list = []
        self.places_found = []
        self.select_fct = None
        self.geo_mainmap = None
        theme = Gtk.IconTheme.get_default()
        self.geo_mainmap = theme.load_surface('gramps-geo-mainmap', 48, 1,
                                              None, 0)
        self.geo_altmap = theme.load_surface('gramps-geo-altmap', 48, 1,
                                             None, 0)
        if (config.get('geography.map_service') in
            (constants.OPENSTREETMAP,
             constants.MAPS_FOR_FREE,
             constants.OPENCYCLEMAP,
             constants.OSM_PUBLIC_TRANSPORT,
             )):
            default_image = self.geo_mainmap
        else:
            default_image = self.geo_altmap
        self.geo_othermap = {}
        for ident in (EventType.BIRTH,
                      EventType.DEATH,
                      EventType.MARRIAGE):
            icon = constants.ICONS.get(int(ident))
            self.geo_othermap[ident] = theme.load_surface(icon, 48, 1, None, 0)
        self.maxyear = 0
        self.minyear = 9999
        self.maxlat = 0.0
        self.minlat = 0.0
        self.maxlon = 0.0
        self.minlon = 0.0
        self.longt = 0.0
        self.latit = 0.0
        self.itemoption = None
        self.menu = None
        self.mark = None
        self.path_entry = None
        self.changemap = None
        self.clearmap = None
        self.nbplaces = 0
Beispiel #11
0
    def update_shortcuts(self, arg):
        """
        connect the keyboard or the keypad for shortcuts
        arg is mandatory because this function is also called by
        the checkbox button
        """
        config.set('geography.use-keypad',
                         self._config.get('geography.use-keypad'))
        if config.get('geography.use-keypad'):
            self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMIN,
                                           Gdk.keyval_from_name("KP_Add"))
            self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMOUT,
                                           Gdk.keyval_from_name("KP_Subtract"))
        else:
            self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMIN,
                                           Gdk.keyval_from_name("plus"))
            self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMOUT,
                                           Gdk.keyval_from_name("minus"))

        self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.UP,
                                       Gdk.keyval_from_name("Up"))
        self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.DOWN,
                                       Gdk.keyval_from_name("Down"))
        self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.LEFT,
                                       Gdk.keyval_from_name("Left"))
        self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.RIGHT,
                                       Gdk.keyval_from_name("Right"))

        # For shortcuts work, we must grab the focus
        self.osm.grab_focus()
Beispiel #12
0
def _display_translator_message(parent=None):
    """
    Display a translator-wanted message to the user.
    """
    if config.get('behavior.translator-needed'):
        config.set('behavior.translator-needed', False)
        from gramps.gen.utils.grampslocale import INCOMPLETE_TRANSLATIONS
        language = None
        if glocale.lang in INCOMPLETE_TRANSLATIONS:
            language = glocale.lang
        elif glocale.lang[:2] in INCOMPLETE_TRANSLATIONS:
            language = glocale.lang[:2]
        if language:
            from .dialog import WarningDialog
            from gramps.gen.const import URL_MAILINGLIST
            # we are looking for a translator so leave this in English
            WarningDialog("This Gramps has an incomplete translation",
                          "The translation for the "
                          "current language (%(language)s) is incomplete.\n"
                          "%(bold_start)sGramps%(bold_end)s "
                          "will start anyway, but if you would like "
                          "to improve\nGramps by doing some translating, "
                          "please contact us!\n\n"
                          "Subscribe to gramps-devel at\n%(mailing_list_url)s"
                          "\n" % {'language'         : language,
                                  'bold_start'       : '<b>',
                                  'bold_end'         : '</b>',
                                  'mailing_list_url' : URL_MAILINGLIST},
                          parent=parent)
Beispiel #13
0
    def change_map(self, obj, map_type):
        """
        Change the current map
        """
        if obj is not None:
            self.osm.layer_remove_all()
            self.osm.image_remove_all()
            self.vbox.remove(self.osm)
            self.osm.destroy()
        tiles_path = os.path.join(config.get('geography.path'),
                                  constants.TILES_PATH[map_type])
        if not os.path.isdir(tiles_path):
            try:
                os.makedirs(tiles_path, 0o755) # create dir like mkdir -p
            except:
                ErrorDialog(_("Can't create "
                              "tiles cache directory for '%s'.") %
                              constants.MAP_TITLE[map_type],
                            parent=self.uistate.window)
        config.set("geography.map_service", map_type)
        self.current_map = map_type
        http_proxy = get_env_var('http_proxy')
        if 0:
            self.osm = DummyMapNoGpsPoint()
        else:
            if http_proxy:
                self.osm = osmgpsmap.Map(tile_cache=tiles_path,
                                         proxy_uri=http_proxy,
                                         map_source=constants.MAP_TYPE[
                                                                      map_type])
            else:
                self.osm = osmgpsmap.Map(tile_cache=tiles_path,
                                         map_source=constants.MAP_TYPE[
                                                                      map_type])
        self.osm.props.tile_cache = osmgpsmap.MAP_CACHE_AUTO
        current_map = osmgpsmap.MapOsd(show_dpad=False, show_zoom=True)
        self.end_selection = None
        self.osm.layer_add(current_map)
        self.osm.layer_add(DummyLayer())
        self.selection_layer = self.add_selection_layer()
        self.kml_layer = self.add_kml_layer()
        self.lifeway_layer = self.add_lifeway_layer()
        self.marker_layer = self.add_marker_layer()
        self.date_layer = self.add_date_layer()
        self.message_layer = self.add_message_layer()
        self.cross_map = osmgpsmap.MapOsd(show_crosshair=False)
        self.set_crosshair(config.get("geography.show_cross"))
        self.osm.set_center_and_zoom(config.get("geography.center-lat"),
                                     config.get("geography.center-lon"),
                                     config.get("geography.zoom"))

        self.osm.connect('button_release_event', self.map_clicked)
        self.osm.connect('button_press_event', self.map_clicked)
        self.osm.connect("motion-notify-event", self.motion_event)
        self.osm.connect('changed', self.zoom_changed)
        self.update_shortcuts(True)
        self.osm.show()
        self.vbox.pack_start(self.osm, True, True, 0)
        self.goto_handle(handle=None)
Beispiel #14
0
    def change_map(self, obj, map_type):
        """
        Change the current map
        """
        if obj is not None:
            self.osm.layer_remove_all()
            self.osm.image_remove_all()
            self.vbox.remove(self.osm)
            self.osm.destroy()
        tiles_path = os.path.join(config.get('geography.path'),
                                  constants.TILES_PATH[map_type])
        if not os.path.isdir(tiles_path):
            try:
                os.makedirs(tiles_path, 0o755) # create dir like mkdir -p
            except:
                ErrorDialog(_("Can't create "
                              "tiles cache directory for '%s'.") %
                              constants.MAP_TITLE[map_type],
                            parent=self.uistate.window)
        config.set("geography.map_service", map_type)
        self.current_map = map_type
        http_proxy = get_env_var('http_proxy')
        if 0:
            self.osm = DummyMapNoGpsPoint()
        else:
            if http_proxy:
                self.osm = osmgpsmap.Map(tile_cache=tiles_path,
                                         proxy_uri=http_proxy,
                                         map_source=constants.MAP_TYPE[
                                                                      map_type])
            else:
                self.osm = osmgpsmap.Map(tile_cache=tiles_path,
                                         map_source=constants.MAP_TYPE[
                                                                      map_type])
        self.osm.props.tile_cache = osmgpsmap.MAP_CACHE_AUTO
        current_map = osmgpsmap.MapOsd(show_dpad=False, show_zoom=True)
        self.end_selection = None
        self.osm.layer_add(current_map)
        self.osm.layer_add(DummyLayer())
        self.selection_layer = self.add_selection_layer()
        self.kml_layer = self.add_kml_layer()
        self.lifeway_layer = self.add_lifeway_layer()
        self.marker_layer = self.add_marker_layer()
        self.date_layer = self.add_date_layer()
        self.message_layer = self.add_message_layer()
        self.cross_map = osmgpsmap.MapOsd(show_crosshair=False)
        self.set_crosshair(config.get("geography.show_cross"))
        self.osm.set_center_and_zoom(config.get("geography.center-lat"),
                                     config.get("geography.center-lon"),
                                     config.get("geography.zoom"))

        self.osm.connect('button_release_event', self.map_clicked)
        self.osm.connect('button_press_event', self.map_clicked)
        self.osm.connect("motion-notify-event", self.motion_event)
        self.osm.connect('changed', self.zoom_changed)
        self.update_shortcuts(True)
        self.osm.show()
        self.vbox.pack_start(self.osm, True, True, 0)
        self.goto_handle(handle=None)
Beispiel #15
0
 def set_zoom_when_center(self, client, cnxn_id, entry, data):
     """
     All geography views must have the same zoom_when_center for maps
     """
     dummy_client = client
     dummy_cnxn_id = cnxn_id
     dummy_data = data
     config.set("geography.zoom_when_center", int(entry))
Beispiel #16
0
 def unhide_plugin(self, id):
     """ Unhide plugin with given id. This will unhide the plugin so queries
     return it again, and write this change to the config
     """
     self.__hidden_plugins.remove(id)
     config.set('plugin.hiddenplugins', list(self.__hidden_plugins))
     config.save()
     self.__hidden_changed()
Beispiel #17
0
 def set_tilepath(self, *obj):
     """
     Save the tile path in the config section.
     """
     if self.path_entry.get_text().strip():
         config.set('geography.path', self.path_entry.get_text())
     else:
         config.set('geography.path', GEOGRAPHY_PATH)
Beispiel #18
0
 def set_path(self, client, cnxn_id, entry, data):
     """
     All geography views must have the same path for maps
     """
     dummy_client = client
     dummy_cnxn_id = cnxn_id
     dummy_data = data
     config.set("geography.path", entry)
Beispiel #19
0
 def dark_variant_changed(self, obj):
     """
     Update dark_variant widget.
     """
     value = obj.get_active()
     config.set('preferences.theme-dark-variant', str(value))
     self.gtksettings.set_property('gtk-application-prefer-dark-theme',
                                   value)
Beispiel #20
0
 def set_tilepath(self, *obj):
     """
     Save the tile path in the config section.
     """
     if self.path_entry.get_text().strip():
         config.set('geography.path', self.path_entry.get_text())
     else:
         config.set('geography.path', GEOGRAPHY_PATH)
Beispiel #21
0
 def unhide_plugin(self, id):
     """ Unhide plugin with given id. This will unhide the plugin so queries
     return it again, and write this change to the config
     """
     self.__hidden_plugins.remove(id)
     config.set("plugin.hiddenplugins", list(self.__hidden_plugins))
     config.save()
     self.__hidden_changed()
Beispiel #22
0
    def __init__(self, title, pdata, dbstate, uistate, bm_type, nav_group):
        NavigationView.__init__(self, title, pdata, dbstate, uistate, bm_type,
                                nav_group)

        OsmGps.__init__(self, uistate)
        self.dbstate = dbstate
        self.dbstate.connect('database-changed', self.change_db)
        self.dbstate.connect('no-database', self.clear_view)
        self.default_text = "Enter location here!"
        self.centerlon = config.get("geography.center-lon")
        self.centerlat = config.get("geography.center-lat")
        self.zoom = config.get("geography.zoom")
        self.lock = config.get("geography.lock")
        if config.get('geography.path') == "":
            config.set('geography.path', GEOGRAPHY_PATH)

        self.format_helper = FormattingHelper(self.dbstate)
        self.centerlat = self.centerlon = 0.0
        self.cross_map = None
        self.current_map = None
        self.without = 0
        self.place_list = []
        self.places_found = []
        self.select_fct = None
        self.geo_mainmap = None
        theme = Gtk.IconTheme.get_default()
        self.geo_mainmap = theme.load_surface('gramps-geo-mainmap', 48, 1,
                                              None, 0)
        self.geo_altmap = theme.load_surface('gramps-geo-altmap', 48, 1, None,
                                             0)
        if (config.get('geography.map_service') in (
                constants.OPENSTREETMAP,
                constants.MAPS_FOR_FREE,
                constants.OPENCYCLEMAP,
                constants.OSM_PUBLIC_TRANSPORT,
        )):
            default_image = self.geo_mainmap
        else:
            default_image = self.geo_altmap
        self.geo_othermap = {}
        for ident in (EventType.BIRTH, EventType.DEATH, EventType.MARRIAGE):
            icon = constants.ICONS.get(int(ident))
            self.geo_othermap[ident] = theme.load_surface(icon, 48, 1, None, 0)
        self.maxyear = 0
        self.minyear = 9999
        self.maxlat = 0.0
        self.minlat = 0.0
        self.maxlon = 0.0
        self.minlon = 0.0
        self.longt = 0.0
        self.latit = 0.0
        self.itemoption = None
        self.menu = None
        self.mark = None
        self.path_entry = None
        self.changemap = None
        self.clearmap = None
        self.nbplaces = 0
Beispiel #23
0
 def _save_size(self):
     """
     Save the dimensions of the window to the config file
     """
     if self.width_key is not None:
         (width, height) = self.window.get_size()
         config.set(self.width_key, width)
         config.set(self.height_key, height)
         config.save()
Beispiel #24
0
 def set_default_directory(self, value):
     """Save the name of the current directory, so that any future
     reports will default to the most recently used directory.
     This also changes the directory name that will appear in the
     preferences panel, but does not change the preference in disk.
     This means that the last directory used will only be
     remembered for this session of gramps unless the user saves
     his/her preferences."""
     config.set('paths.report-directory', value)
Beispiel #25
0
 def _save_position(self):
     """
     Save the window's position to the config file
     """
     if self.horiz_position_key is not None:
         (horiz_position, vert_position) = self.window.get_position()
         config.set(self.horiz_position_key, horiz_position)
         config.set(self.vert_position_key, vert_position)
         config.save()
Beispiel #26
0
 def config_crosshair(self, client, cnxn_id, entry, data):
     """
     We asked to change the crosshair.
     """
     if config.get("geography.show_cross"):
         config.set("geography.show_cross", False)
     else:
         config.set("geography.show_cross", True)
     self.set_crosshair(config.get("geography.show_cross"))
Beispiel #27
0
 def set_default_directory(self, value):
     """Save the name of the current directory, so that any future
     reports will default to the most recently used directory.
     This also changes the directory name that will appear in the
     preferences panel, but does not change the preference in disk.
     This means that the last directory used will only be
     remembered for this session of gramps unless the user saves
     his/her preferences."""
     config.set('paths.report-directory', value)
Beispiel #28
0
 def _save_size(self):
     """
     Save the dimensions of the window to the config file
     """
     if self.width_key is not None:
         (width, height) = self.window.get_size()
         config.set(self.width_key, width)
         config.set(self.height_key, height)
         config.save()
Beispiel #29
0
 def hide_plugin(self, id):
     """ Hide plugin with given id. This will hide the plugin so queries do
     not return it anymore, and write this change to the config.
     Note that config will then emit a signal
     """
     self.__hidden_plugins.add(id)
     config.set('plugin.hiddenplugins', list(self.__hidden_plugins))
     config.save()
     self.__hidden_changed()
Beispiel #30
0
 def hide_plugin(self, id):
     """ Hide plugin with given id. This will hide the plugin so queries do
     not return it anymore, and write this change to the config.
     Note that config will then emit a signal
     """
     self.__hidden_plugins.add(id)
     config.set("plugin.hiddenplugins", list(self.__hidden_plugins))
     config.save()
     self.__hidden_changed()
Beispiel #31
0
 def config_crosshair(self, client, cnxn_id, entry, data):
     """
     We asked to change the crosshair.
     """
     if config.get("geography.show_cross"):
         config.set("geography.show_cross", False)
     else:
         config.set("geography.show_cross", True)
     self.set_crosshair(config.get("geography.show_cross"))
Beispiel #32
0
    def __init__(self, title, pdata, dbstate, uistate, bm_type, nav_group):
        NavigationView.__init__(self, title, pdata, dbstate, uistate, bm_type,
                                nav_group)

        OsmGps.__init__(self, uistate)
        self.dbstate = dbstate
        self.dbstate.connect('database-changed', self.change_db)
        self.dbstate.connect('no-database', self.clear_view)
        self.default_text = "Enter location here!"
        self.centerlon = config.get("geography.center-lon")
        self.centerlat = config.get("geography.center-lat")
        self.zoom = config.get("geography.zoom")
        self.lock = config.get("geography.lock")
        if config.get('geography.path') == "":
            config.set('geography.path', GEOGRAPHY_PATH)

        self.uistate = uistate
        self.uistate.connect('font-changed', self.font_changed)
        self.uistate.connect('nameformat-changed', self.build_tree)
        self.format_helper = FormattingHelper(self.dbstate, self.uistate)
        self.centerlat = self.centerlon = 0.0
        self.cross_map = None
        self.current_map = None
        self.without = 0
        self.place_list = []
        self.places_found = []
        self.select_fct = None
        self.geo_mainmap = None
        self.reloadtiles = None
        theme = Gtk.IconTheme.get_default()
        self.geo_mainmap = theme.load_surface('gramps-geo-mainmap', 48, 1,
                                              None, 0)
        self.geo_altmap = theme.load_surface('gramps-geo-altmap', 48, 1, None,
                                             0)
        self.sort = []
        self.geo_othermap = {}
        for ident in (EventType.BIRTH, EventType.DEATH, EventType.MARRIAGE):
            icon = constants.ICONS.get(int(ident))
            self.geo_othermap[ident] = theme.load_surface(icon, 48, 1, None, 0)
        self.maxyear = 0
        self.minyear = 9999
        self.maxlat = 0.0
        self.minlat = 0.0
        self.maxlon = 0.0
        self.minlon = 0.0
        self.longt = 0.0
        self.latit = 0.0
        self.itemoption = None
        self.menu = None
        self.mark = None
        self.path_entry = None
        self.changemap = None
        self.clearmap = None
        self.nbplaces = 0
        self.nbmarkers = 0
        self.place_without_coordinates = []
Beispiel #33
0
 def on_menu_activate(self, menuitem):
     """Copies the owner information from/to the preferences"""
     if menuitem.props.name == 'copy_from_preferences_to_db':
         self.owner.set_from(get_researcher())
         for entry in self.entries:
             entry.update()
             
     elif menuitem.props.name == 'copy_from_db_to_preferences':
         for i in range(len(config_keys)):
             config.set(config_keys[i], self.owner.get()[i])
Beispiel #34
0
 def _save_size(self):
     """
     Save the dimensions of the window to the config file
     """
     # self.width_key is set in the subclass, typically in its _local_init
     if self.width_key is not None:
         (width, height) = self.window.get_size()
         config.set(self.width_key, width)
         config.set(self.height_key, height)
         config.save()
Beispiel #35
0
 def _save_size(self):
     """
     Save the dimensions of the window to the config file
     """
     # self.width_key is set in the subclass (or in setup_configs)
     if self.width_key is not None:
         (width, height) = self.window.get_size()
         config.set(self.width_key, width)
         config.set(self.height_key, height)
         config.save()
Beispiel #36
0
 def _save_size(self):
     """
     Save the dimensions of the window to the config file
     """
     # self.width_key is set in the subclass (or in setup_configs)
     if self.width_key is not None:
         (width, height) = self.window.get_size()
         config.set(self.width_key, width)
         config.set(self.height_key, height)
         config.save()
Beispiel #37
0
 def config_zoom_and_position(self, client, cnxn_id, entry, data):
     """
     Do we need to lock the zoom and position ?
     """
     if config.get("geography.lock"):
         config.set("geography.lock", False)
         self._set_center_and_zoom()
     else:
         config.set("geography.lock", True)
     self.lock = config.get("geography.lock")
Beispiel #38
0
    def on_menu_activate(self, menuitem):
        """Copies the owner information from/to the preferences"""
        if menuitem.props.name == 'copy_from_preferences_to_db':
            self.owner.set_from(get_researcher())
            for entry in self.entries:
                entry.update()

        elif menuitem.props.name == 'copy_from_db_to_preferences':
            for i in range(len(config_keys)):
                config.set(config_keys[i], self.owner.get()[i])
    def save(self, obj):
        "Save values"
        print("saving")
        apikey = self.entry_apikey.get_text()
        set_apikey(apikey)

        apiurl = self.entry_apiurl.get_text()
        set_apiurl(apiurl)

        config.set("behavior.addons-url", self.addons_url)
Beispiel #40
0
 def config_zoom_and_position(self, client, cnxn_id, entry, data):
     """
     Do we need to lock the zoom and position ?
     """
     if config.get("geography.lock"):
         config.set("geography.lock", False)
         self._set_center_and_zoom()
     else:
         config.set("geography.lock", True)
     self.lock = config.get("geography.lock")
Beispiel #41
0
    def on_changed(self, obj):
        """
        called when a button state change
        save is immediate
        """
        sep_iter = obj.get_active_iter()

        if sep_iter is not None:
            model = obj.get_model()
            sep = model[sep_iter][0]
            config.set('csv.delimiter', sep)
Beispiel #42
0
 def set_mapservice(self, mapkey):
     """
     change the service that runs on click of the menutoolbutton
     used as callback menu on menu clicks
     """
     self.mapservice = mapkey
     for label in self.mapslistlabel:
         label.set_label(self.mapservice_label())
         label.show()
     config.set('interface.mapservice', mapkey)
     config.save()
Beispiel #43
0
 def on_toggled(self, obj, entry):
     """
     called when a button state change
     save is immediate
     """
     if obj.get_active():
         button = obj.get_label()
         config.set('csv.dialect', button)
         if button == _("Custom"):
             entry.set_sensitive(True)
         else:
             entry.set_sensitive(False)
Beispiel #44
0
    def __init__(self, title, pdata, dbstate, uistate,
                 bm_type, nav_group):
        NavigationView.__init__(self, title, pdata, dbstate, uistate,
                                bm_type, nav_group)

        self.dbstate = dbstate
        self.dbstate.connect('database-changed', self.change_db)
        self.default_text = "Enter location here!"
        self.centerlon = config.get("geography.center-lon")
        self.centerlat = config.get("geography.center-lat")
        self.zoom = config.get("geography.zoom")
        self.lock = config.get("geography.lock")
        if config.get('geography.path') == "" :
            config.set('geography.path', GEOGRAPHY_PATH )
        OsmGps.__init__(self)

        self.format_helper = FormattingHelper(self.dbstate)
        self.centerlat = self.centerlon = 0.0
        self.cross_map = None
        self.current_map = None
        self.without = 0
        self.place_list = []
        self.places_found = []
        self.select_fct = None
        self.geo_mainmap = None
        path = os.path.join(IMAGE_DIR, "48x48",
                            ('gramps-geo-mainmap' + '.png' ))
        with open(path, 'rb') as fh: # this is to avoid bug with cairo 1.8.8
            self.geo_mainmap = cairo.ImageSurface.create_from_png(fh)
        #self.geo_mainmap = cairo.ImageSurface.create_from_png(path)
        path = os.path.join(IMAGE_DIR, "48x48",
                            ('gramps-geo-altmap' + '.png' ))
        with open(path, 'rb') as fh: # this is to avoid bug with cairo 1.8.8
            self.geo_altmap = cairo.ImageSurface.create_from_png(fh)
        #self.geo_altmap = cairo.ImageSurface.create_from_png(path)
        if ( config.get('geography.map_service') in
            ( constants.OPENSTREETMAP,
              constants.MAPS_FOR_FREE,
              constants.OPENCYCLEMAP,
              constants.OSM_PUBLIC_TRANSPORT,
             )):
            default_image = self.geo_mainmap
        else:
            default_image = self.geo_altmap
        self.geo_othermap = {}
        for ident in ( EventType.BIRTH,
                    EventType.DEATH,
                    EventType.MARRIAGE ):
            path = os.path.join(IMAGE_DIR, "48x48",
                                (constants.ICONS.get(int(ident), default_image) + '.png' ))
            with open(path, 'rb') as fh: # this is to avoid bug with cairo 1.8.8
                self.geo_othermap[ident] = cairo.ImageSurface.create_from_png(fh)
Beispiel #45
0
    def _save_position(self, save_config=True):
        """
        Save the window's position to the config file

        (You can set save_config False if a _save_size() will instantly follow)
        """
        # self.horiz_position_key is set in the subclass (or in setup_configs)
        if self.horiz_position_key is not None:
            (horiz_position, vert_position) = self.window.get_position()
            config.set(self.horiz_position_key, horiz_position)
            config.set(self.vert_position_key, vert_position)
            if save_config:
                config.save()
Beispiel #46
0
 def config_crosshair(self, client, cnxn_id, entry, data):
     """
     We asked to change the crosshair.
     """
     dummy_client = client
     dummy_cnxn_id = cnxn_id
     dummy_entry = entry
     dummy_data = data
     if config.get("geography.show_cross"):
         config.set("geography.show_cross", False)
     else:
         config.set("geography.show_cross", True)
     self.set_crosshair(config.get("geography.show_cross"))
Beispiel #47
0
    def _save_position(self, save_config=True):
        """
        Save the window's position to the config file

        (You can set save_config False if a _save_size() will instantly follow)
        """
        # self.horiz_position_key is set in the subclass (or in setup_configs)
        if self.horiz_position_key is not None:
            (horiz_position, vert_position) = self.window.get_position()
            config.set(self.horiz_position_key, horiz_position)
            config.set(self.vert_position_key, vert_position)
            if save_config:
                config.save()
Beispiel #48
0
 def set_mapservice(self, action, value):
     """
     change the service that runs on click of the menutoolbutton
     used as callback menu on menu clicks
     """
     if action:
         action.set_state(value)
     self.mapservice = mapkey = value.get_string()
     config.set('interface.mapservice', mapkey)
     config.save()
     _ui = self.__create_maps_menu_actions()
     self.uimanager.add_ui_from_string(_ui)
     self.uimanager.update_menu()
     return False
Beispiel #49
0
 def default_clicked(self, obj):
     self.gtksettings.set_property('gtk-font-name', self.def_font)
     self.gtksettings.set_property('gtk-theme-name', self.def_theme)
     self.gtksettings.set_property('gtk-application-prefer-dark-theme',
                                   self.def_dark)
     config.set('preferences.font', '')
     config.set('preferences.theme', '')
     config.set('preferences.theme-dark-variant', '')
     # fill combo with names and select active if current matches
     self.theme.remove_all()
     for indx, theme in enumerate(self.t_names):
         self.theme.append_text(theme)
         if theme == self.def_theme:
             self.theme.set_active(indx)
     self.dark.set_active(self.def_dark)
     # Clear out scrollbar stuff
     if not win():  # don't mess with this on Linux etc.
         return
     self.sc_text.set_active(False)
     config.set('interface.fixed-scrollbar', '')
     self.gtksettings.set_property('gtk-primary-button-warps-slider', 1)
     if hasattr(MyPrefs, 'provider'):
         Gtk.StyleContext.remove_provider_for_screen(
             Screen.get_default(), MyPrefs.provider)
     try:
         txt = subprocess.check_output(
             'reg delete HKCU\Environment /v GTK_OVERLAY_SCROLLING /f',
             shell=True)
     except subprocess.CalledProcessError:
         pass
Beispiel #50
0
 def set_mapservice(self, action, value):
     """
     change the service that runs on click of the menutoolbutton
     used as callback menu on menu clicks
     """
     if action:
         action.set_state(value)
     self.mapservice = mapkey = value.get_string()
     config.set('interface.mapservice', mapkey)
     config.save()
     _ui = self.__create_maps_menu_actions()
     self.uimanager.add_ui_from_string(_ui)
     self.uimanager.update_menu()
     return False
Beispiel #51
0
 def save_center(self, lat, lon):
     """
     Save the longitude and lontitude in case we switch between maps.
     """
     _LOG.debug("save_center : %s,%s", lat, lon)
     if (-90.0 < lat < +90.0) and (-180.0 < lon < +180.0):
         config.set("geography.center-lat", lat)
         config.set("geography.center-lon", lon)
     else:
         _LOG.debug("save_center : new coordinates : %s,%s", lat, lon)
         _LOG.debug("save_center : old coordinates : %s,%s", lat, lon)
         # osmgpsmap bug ? reset to prior values to avoid osmgpsmap problems.
         self.osm.set_center_and_zoom(config.get("geography.center-lat"),
                                      config.get("geography.center-lon"),
                                      config.get("geography.zoom"))
Beispiel #52
0
 def save_center(self, lat, lon):
     """
     Save the longitude and lontitude in case we switch between maps.
     """
     _LOG.debug("save_center : %s,%s", lat, lon)
     if (-90.0 < lat < +90.0) and (-180.0 < lon < +180.0):
         config.set("geography.center-lat", lat)
         config.set("geography.center-lon", lon)
     else:
         _LOG.debug("save_center : new coordinates : %s,%s", lat, lon)
         _LOG.debug("save_center : old coordinates : %s,%s", lat, lon)
         # osmgpsmap bug ? reset to prior values to avoid osmgpsmap problems.
         self.osm.set_center_and_zoom(config.get("geography.center-lat"),
                                      config.get("geography.center-lon"),
                                      config.get("geography.zoom"))
Beispiel #53
0
    def _post_load_newdb_nongui(self, filename, title=None):
        """
        Called after a new database is loaded.
        """
        if not filename:
            return

        if filename[-1] == os.path.sep:
            filename = filename[:-1]
        name = os.path.basename(filename)
        self.dbstate.db.db_name = title
        if title:
            name = title

        # This method is for UI stuff when the database has changed.
        # Window title, recent files, etc related to new file.

        self.dbstate.db.set_save_path(filename)

        # apply preferred researcher if loaded file has none
        res = self.dbstate.db.get_researcher()
        owner = get_researcher()
        # If the DB Owner Info is empty and
        # [default] Researcher is not empty and
        # database is empty, then copy default researcher to DB owner
        if (res.is_empty()
                and not owner.is_empty()
                and self.dbstate.db.get_total() == 0):
            self.dbstate.db.set_researcher(owner)

        name_displayer.set_name_format(self.dbstate.db.name_formats)
        fmt_default = config.get('preferences.name-format')
        name_displayer.set_default_format(fmt_default)

        self.dbstate.db.enable_signals()
        self.dbstate.signal_change()

        config.set('paths.recent-file', filename)

        recent_files(filename, name)
        self.file_loaded = True
Beispiel #54
0
    def _post_load_newdb_nongui(self, filename, title=None):
        """
        Called after a new database is loaded.
        """
        if not filename:
            return

        if filename[-1] == os.path.sep:
            filename = filename[:-1]
        name = os.path.basename(filename)
        self.dbstate.db.db_name = title
        if title:
            name = title

        # This method is for UI stuff when the database has changed.
        # Window title, recent files, etc related to new file.

        self.dbstate.db.set_save_path(filename)

        # apply preferred researcher if loaded file has none
        res = self.dbstate.db.get_researcher()
        owner = get_researcher()
        # If the DB Owner Info is empty and
        # [default] Researcher is not empty and
        # database is empty, then copy default researcher to DB owner
        if (res.is_empty()
                and not owner.is_empty()
                and self.dbstate.db.get_total() == 0):
            self.dbstate.db.set_researcher(owner)

        name_displayer.set_name_format(self.dbstate.db.name_formats)
        fmt_default = config.get('preferences.name-format')
        name_displayer.set_default_format(fmt_default)

        self.dbstate.db.enable_signals()
        self.dbstate.signal_change()

        config.set('paths.recent-file', filename)

        recent_files(filename, name)
        self.file_loaded = True
Beispiel #55
0
    def _update(self):
        """ store changed objects formats in DB """

        update = False
        for prim_obj, dummy in self.xobjects:
            obj_value = self.obj_values[prim_obj]
            if obj_value.object_fmt != obj_value.stored_fmt:
                constant = 'preferences.%sprefix' % PREFIXES[prim_obj]
                config.set(constant, obj_value.object_fmt)
                update = True

        if update:
            config.save()
            self.db.set_prefixes(
                config.get('preferences.iprefix'),
                config.get('preferences.oprefix'),
                config.get('preferences.fprefix'),
                config.get('preferences.sprefix'),
                config.get('preferences.cprefix'),
                config.get('preferences.pprefix'),
                config.get('preferences.eprefix'),
                config.get('preferences.rprefix'),
                config.get('preferences.nprefix'))
Beispiel #56
0
    def export(self, *obj):
        chooser = Gtk.FileChooserDialog(
            _("Export View as Spreadsheet"),
            self.uistate.window,
            Gtk.FileChooserAction.SAVE,
            (_('_Cancel'), Gtk.ResponseType.CANCEL,
             _('_Save'), Gtk.ResponseType.OK))
        chooser.set_do_overwrite_confirmation(True)

        combobox = Gtk.ComboBoxText()
        label = Gtk.Label(label=_("Format:"))
        label.set_halign(Gtk.Align.END)
        box = Gtk.Box()
        box.pack_start(label, True, True, padding=12)
        box.pack_start(combobox, False, False, 0)
        combobox.append_text(_('CSV'))
        combobox.append_text(_('OpenDocument Spreadsheet'))
        combobox.set_active(0)
        box.show_all()
        chooser.set_extra_widget(box)
        default_dir = config.get('paths.recent-export-dir')
        chooser.set_current_folder(default_dir)

        while True:
            value = chooser.run()
            fn = chooser.get_filename()
            fl = combobox.get_active()
            if value == Gtk.ResponseType.OK:
                if fn:
                    chooser.destroy()
                    break
            else:
                chooser.destroy()
                return
        config.set('paths.recent-export-dir', os.path.split(fn)[0])
        self.write_tabbed_file(fn, fl)
Beispiel #57
0
def _display_generic_message(warning_type, config_key, parent=None):
    """
    Display a generic warning message to the user, with the
    warning_type in it -- if the config_key key is not set

    :param warning_type: the general name of the warning, e.g. "master"
    :type warning_type: str
    :param config_key: name of gramps.ini config key, e.g. "behavior.betawarn"
    :type config_key: str
    """
    if not config.get(config_key):
        from .dialog import WarningDialog
        WarningDialog(
            _('Danger: This is unstable code!'),
            _("This Gramps ('%s') is a development release.\n"
             ) % warning_type +
            _("This version is not meant for normal usage. Use "
              "at your own risk.\n"
              "\n"
              "This version may:\n"
              "1) Work differently than you expect.\n"
              "2) Fail to run at all.\n"
              "3) Crash often.\n"
              "4) Corrupt your data.\n"
              "5) Save data in a format that is incompatible with the "
              "official release.\n"
              "\n"
              "%(bold_start)sBACKUP%(bold_end)s "
              "your existing databases before opening "
              "them with this version, and make sure to export your "
              "data to XML every now and then."
             ) % {'bold_start' : '<b>',
                  'bold_end'   : '</b>'},
            parent=parent)
        config.set('behavior.autoload', False)
        config.set(config_key, True)
Beispiel #58
0
 def _cleanup_on_exit(self):
     config.set("behavior.addmedia-image-dir", self.last_directory)
     config.set("behavior.addmedia-relative-path", self.relative_path)
     config.save()