From e2c6a9cdb47b5a88b38e8803a63680319155b4e5 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Wed, 30 Mar 2011 13:48:46 +0000 Subject: [PATCH] #4795 Gramplet titles now appear in current language, not the language used at time of creation; also added properties for gramplet navtype and orientation preferences svn: r16985 --- src/gen/plug/_pluginreg.py | 38 +++++++++++++++++++++++++++++++- src/gui/grampsbar.py | 6 ++--- src/gui/widgets/grampletpane.py | 39 ++++++++++++++++++++------------- 3 files changed, 64 insertions(+), 19 deletions(-) diff --git a/src/gen/plug/_pluginreg.py b/src/gen/plug/_pluginreg.py index 9d4171987..8f9d6332e 100644 --- a/src/gen/plug/_pluginreg.py +++ b/src/gen/plug/_pluginreg.py @@ -303,8 +303,12 @@ class PluginData(object): The width the gramplet should have detached, default 400 .. attribute:: expand If the attributed should be expanded on start, default False + .. attribute:: gramplet_title_id + Untranslated title to use for the gramplet, default = 'Gramplet' .. attribute:: gramplet_title - Title to use for the gramplet, default = 'Gramplet' + Title to use for the gramplet, default = _('Gramplet') + .. attribute:: navtypes + Navigation types that the gramplet is appropriate for, default = [] .. attribute:: help_url The URL where documentation for the URL can be found @@ -388,6 +392,9 @@ class PluginData(object): self._detached_width = 400 self._expand = False self._gramplet_title = _('Gramplet') + self._gramplet_title_id = 'Gramplet' + self._navtypes = [] + self._orientation = None self._help_url = None #VIEW attr self._viewclass = None @@ -823,6 +830,16 @@ class PluginData(object): def _get_gramplet_title(self): return self._gramplet_title + def _set_gramplet_title_id(self, gramplet_title_id): + if not self._ptype == GRAMPLET: + raise ValueError, 'gramplet_title_id may only be set for GRAMPLET plugins' + if not isinstance(gramplet_title_id, str): + raise ValueError, 'Plugin must have a string as gramplet_title_id' + self._gramplet_title_id = gramplet_title_id + + def _get_gramplet_title_id(self): + return self._gramplet_title_id + def _set_help_url(self, help_url): if not self._ptype == GRAMPLET: raise ValueError, 'help_url may only be set for GRAMPLET plugins' @@ -830,6 +847,22 @@ class PluginData(object): def _get_help_url(self): return self._help_url + + def _set_navtypes(self, navtypes): + if not self._ptype == GRAMPLET: + raise ValueError, 'navtypes may only be set for GRAMPLET plugins' + self._navtypes = navtypes + + def _get_navtypes(self): + return self._navtypes + + def _set_orientation(self, orientation): + if not self._ptype == GRAMPLET: + raise ValueError, 'orientation may only be set for GRAMPLET plugins' + self._orientation = orientation + + def _get_orientation(self): + return self._orientation gramplet = property(_get_gramplet, _set_gramplet) height = property(_get_height, _set_height) @@ -837,6 +870,9 @@ class PluginData(object): detached_width = property(_get_detached_width, _set_detached_width) expand = property(_get_expand, _set_expand) gramplet_title = property(_get_gramplet_title, _set_gramplet_title) + gramplet_title_id = property(_get_gramplet_title_id, _set_gramplet_title_id) + navtypes = property(_get_navtypes, _set_navtypes) + orientation = property(_get_orientation, _set_orientation) help_url = property(_get_help_url, _set_help_url) def _set_viewclass(self, viewclass): diff --git a/src/gui/grampsbar.py b/src/gui/grampsbar.py index 1524384fc..e4ae6b3c2 100644 --- a/src/gui/grampsbar.py +++ b/src/gui/grampsbar.py @@ -138,7 +138,7 @@ class GrampsBar(gtk.Notebook): if "page" in cp.options(sec): default_page = int(cp.get(sec, "page")) else: - data = {"title": sec} + data = {} for opt in cp.options(sec): if opt.startswith("data["): temp = data.get("data", {}) @@ -193,9 +193,9 @@ class GrampsBar(gtk.Notebook): for key in base_opts: if key in gramplet.__dict__: base_opts[key] = gramplet.__dict__[key] - fp.write(("[%s]" + NL) % gramplet.title) + fp.write(("[%s]" + NL) % gramplet.gname) for key in base_opts: - if key in ["content", "title", "row", "column", "page", + if key in ["content", "title", "title_id", "tname", "row", "column", "page", "version", "gramps"]: # don't save continue elif key == "data": diff --git a/src/gui/widgets/grampletpane.py b/src/gui/widgets/grampletpane.py index 924626736..e980a2312 100644 --- a/src/gui/widgets/grampletpane.py +++ b/src/gui/widgets/grampletpane.py @@ -80,7 +80,8 @@ def GET_AVAILABLE_GRAMPLETS(name): "version": gplug.version, "height": gplug.height, "expand": gplug.expand, - "title": gplug.gramplet_title, + "title": gplug.gramplet_title, # translated + "title_id": gplug.gramplet_title_id, # untranslated "content": gplug.gramplet, "detached_width": gplug.detached_width, "detached_height": gplug.detached_height, @@ -957,25 +958,27 @@ class GrampletPane(gtk.ScrolledWindow): # Load the user's gramplets: for (name, opts) in user_gramplets: all_opts = get_gramplet_opts(name, opts) - if "title" not in all_opts: - all_opts["title"] = "Untitled Gramplet" - if "state" not in all_opts: - all_opts["state"] = "maximized" - # uniqify titles: - unique = all_opts["title"] - cnt = 1 - while unique in self.gramplet_map: - unique = all_opts["title"] + ("-%d" % cnt) - cnt += 1 - all_opts["title"] = unique if all_opts["state"] == "closed": self.gramplet_map[all_opts["title"]] = None # save closed name self.closed_opts.append(all_opts) continue + if "state" not in all_opts: + all_opts["state"] = "maximized" + if "title" not in all_opts: + all_opts["title"] = _("Untitled Gramplet") + all_opts["title_id"] = "Untitled Gramplet" + # May have to change title g = make_requested_gramplet(GridGramplet, self, all_opts, self.dbstate, self.uistate) if g: - self.gramplet_map[all_opts["title"]] = g + # make a unique title: + unique = g.get_title() + cnt = 1 + while unique in self.gramplet_map: + unique = g.get_title() + ("-%d" % cnt) + cnt += 1 + g.set_title(unique) + self.gramplet_map[unique] = g self.frame_map[str(g.mainframe)] = g else: print "Can't make gramplet of type '%s'." % name @@ -1074,7 +1077,7 @@ class GrampletPane(gtk.ScrolledWindow): if "pane_orientation" in cp.options(sec): self.pane_orientation = cp.get(sec, "pane_orientation") else: - data = {"title": sec} + data = {} for opt in cp.options(sec): if opt.startswith("data["): temp = data.get("data", {}) @@ -1126,10 +1129,12 @@ class GrampletPane(gtk.ScrolledWindow): for key in base_opts: if key in gramplet.__dict__: base_opts[key] = gramplet.__dict__[key] - fp.write(("[%s]" + NL) % gramplet.title) + fp.write(("[%s]" + NL) % gramplet.gname) for key in base_opts: if key == "content": continue elif key == "title": continue + elif key == "title_id": continue + elif key == "tname": continue elif key == "column": continue elif key == "row": continue elif key == "version": continue # code, don't save @@ -1160,6 +1165,10 @@ class GrampletPane(gtk.ScrolledWindow): for key in base_opts: if key == "content": continue elif key == "title": continue + elif key == "title_id": continue + elif key == "tname": continue + elif key == "version": continue # code, don't save + elif key == "gramps": continue # code, don't save elif key == "data": if not isinstance(base_opts["data"], (list, tuple)): fp.write(("data[0]=%s" + NL) % base_opts["data"])