From a45d86f0adf68a567a94304dc25ed8ae2165bdca Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Sat, 19 Mar 2022 20:48:37 +0000 Subject: [PATCH] Allow gramplets to have an orientation dependent layout Use this for the gallery gramplets. Implements #11527. --- gramps/gen/plug/_gramplet.py | 10 ++++++++++ gramps/gui/views/pageview.py | 6 ++++-- gramps/gui/widgets/grampletbar.py | 12 +++++++++++- gramps/plugins/gramplet/gallery.py | 6 ++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/gramps/gen/plug/_gramplet.py b/gramps/gen/plug/_gramplet.py index b6b7d67c5..5aab65d80 100644 --- a/gramps/gen/plug/_gramplet.py +++ b/gramps/gen/plug/_gramplet.py @@ -484,3 +484,13 @@ class Gramplet: By default, assume that the gramplet has data. """ self.set_has_data(True) + + def set_orientation(self, orientation): + """ + Called when the gramplet orientation changes. A gramplet may override + this if it has a preferred horizontal and vertical layout. + + :param orientation: A Gtk.Orientation (VERTCIAL or HORIZONTAL) + :type orientation: int + """ + pass diff --git a/gramps/gui/views/pageview.py b/gramps/gui/views/pageview.py index d5700a301..25aa221c2 100644 --- a/gramps/gui/views/pageview.py +++ b/gramps/gui/views/pageview.py @@ -150,10 +150,12 @@ class PageView(DbGUIElement, metaclass=ABCMeta): defaults = self.get_default_gramplets() self.sidebar = GrampletBar(self.dbstate, self.uistate, self, self.ident + "_sidebar", - defaults[0]) + defaults[0], + Gtk.Orientation.VERTICAL) self.bottombar = GrampletBar(self.dbstate, self.uistate, self, self.ident + "_bottombar", - defaults[1]) + defaults[1], + Gtk.Orientation.HORIZONTAL) hpane = Gtk.Paned() self.vpane = Gtk.Paned(orientation=Gtk.Orientation.VERTICAL) hpane.pack1(self.vpane, resize=True, shrink=False) diff --git a/gramps/gui/widgets/grampletbar.py b/gramps/gui/widgets/grampletbar.py index 29c727aab..5edefd495 100644 --- a/gramps/gui/widgets/grampletbar.py +++ b/gramps/gui/widgets/grampletbar.py @@ -90,7 +90,8 @@ class GrampletBar(Gtk.Notebook): """ A class which defines the graphical representation of the GrampletBar. """ - def __init__(self, dbstate, uistate, pageview, configfile, defaults): + def __init__(self, dbstate, uistate, pageview, configfile, defaults, + orientation=Gtk.Orientation.VERTICAL): Gtk.Notebook.__init__(self) self.dbstate = dbstate @@ -98,6 +99,7 @@ class GrampletBar(Gtk.Notebook): self.pageview = pageview self.configfile = os.path.join(VERSION_DIR, "%s.ini" % configfile) self.defaults = defaults + self.orientation = orientation self.detached_gramplets = [] self.empty = False self.close_buttons = [] @@ -433,6 +435,8 @@ class GrampletBar(Gtk.Notebook): Called when a new page is added to the GrampletBar. """ gramplet = self.get_nth_page(new_page) + if isinstance(gramplet, TabGramplet): + gramplet.set_orientation(self.orientation) if self.empty: if isinstance(gramplet, TabGramplet): self.empty = False @@ -634,6 +638,12 @@ class TabGramplet(Gtk.ScrolledWindow, GuiGramplet): """ return self + def set_orientation(self, orientation): + """ + Called when the gramplet orientation changes. + """ + self.pui.set_orientation(orientation) + #------------------------------------------------------------------------- # # DetachedWindow class diff --git a/gramps/plugins/gramplet/gallery.py b/gramps/plugins/gramplet/gallery.py index 777a8cdc2..17473ba22 100644 --- a/gramps/plugins/gramplet/gallery.py +++ b/gramps/plugins/gramplet/gallery.py @@ -52,6 +52,12 @@ class Gallery(Gramplet): self.top = Gtk.Box(spacing=3) return self.top + def set_orientation(self, orientation): + """ + Called when the gramplet orientation changes. + """ + self.top.set_orientation(orientation) + def clear_images(self): """ Remove all images from the Gramplet.