Allow gramplets to have an orientation dependent layout

Use this for the gallery gramplets.

Implements #11527.
This commit is contained in:
Nick Hall 2022-03-19 20:48:37 +00:00
parent 3b2d845992
commit a45d86f0ad
4 changed files with 31 additions and 3 deletions

View File

@ -484,3 +484,13 @@ class Gramplet:
By default, assume that the gramplet has data. By default, assume that the gramplet has data.
""" """
self.set_has_data(True) 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

View File

@ -150,10 +150,12 @@ class PageView(DbGUIElement, metaclass=ABCMeta):
defaults = self.get_default_gramplets() defaults = self.get_default_gramplets()
self.sidebar = GrampletBar(self.dbstate, self.uistate, self, self.sidebar = GrampletBar(self.dbstate, self.uistate, self,
self.ident + "_sidebar", self.ident + "_sidebar",
defaults[0]) defaults[0],
Gtk.Orientation.VERTICAL)
self.bottombar = GrampletBar(self.dbstate, self.uistate, self, self.bottombar = GrampletBar(self.dbstate, self.uistate, self,
self.ident + "_bottombar", self.ident + "_bottombar",
defaults[1]) defaults[1],
Gtk.Orientation.HORIZONTAL)
hpane = Gtk.Paned() hpane = Gtk.Paned()
self.vpane = Gtk.Paned(orientation=Gtk.Orientation.VERTICAL) self.vpane = Gtk.Paned(orientation=Gtk.Orientation.VERTICAL)
hpane.pack1(self.vpane, resize=True, shrink=False) hpane.pack1(self.vpane, resize=True, shrink=False)

View File

@ -90,7 +90,8 @@ class GrampletBar(Gtk.Notebook):
""" """
A class which defines the graphical representation of the GrampletBar. 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) Gtk.Notebook.__init__(self)
self.dbstate = dbstate self.dbstate = dbstate
@ -98,6 +99,7 @@ class GrampletBar(Gtk.Notebook):
self.pageview = pageview self.pageview = pageview
self.configfile = os.path.join(VERSION_DIR, "%s.ini" % configfile) self.configfile = os.path.join(VERSION_DIR, "%s.ini" % configfile)
self.defaults = defaults self.defaults = defaults
self.orientation = orientation
self.detached_gramplets = [] self.detached_gramplets = []
self.empty = False self.empty = False
self.close_buttons = [] self.close_buttons = []
@ -433,6 +435,8 @@ class GrampletBar(Gtk.Notebook):
Called when a new page is added to the GrampletBar. Called when a new page is added to the GrampletBar.
""" """
gramplet = self.get_nth_page(new_page) gramplet = self.get_nth_page(new_page)
if isinstance(gramplet, TabGramplet):
gramplet.set_orientation(self.orientation)
if self.empty: if self.empty:
if isinstance(gramplet, TabGramplet): if isinstance(gramplet, TabGramplet):
self.empty = False self.empty = False
@ -634,6 +638,12 @@ class TabGramplet(Gtk.ScrolledWindow, GuiGramplet):
""" """
return self return self
def set_orientation(self, orientation):
"""
Called when the gramplet orientation changes.
"""
self.pui.set_orientation(orientation)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# DetachedWindow class # DetachedWindow class

View File

@ -52,6 +52,12 @@ class Gallery(Gramplet):
self.top = Gtk.Box(spacing=3) self.top = Gtk.Box(spacing=3)
return self.top return self.top
def set_orientation(self, orientation):
"""
Called when the gramplet orientation changes.
"""
self.top.set_orientation(orientation)
def clear_images(self): def clear_images(self):
""" """
Remove all images from the Gramplet. Remove all images from the Gramplet.