window: Replace the outer Gtk.Pane with a Layout widget
I keep the sidebar-size property for now, but it will be removed soon. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
d22a9b23a1
commit
97659f212d
|
@ -4,6 +4,7 @@ from gi.repository import GObject
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from gi.repository import Adw
|
from gi.repository import Adw
|
||||||
from .action import ActionEntry
|
from .action import ActionEntry
|
||||||
|
from . import layout
|
||||||
|
|
||||||
|
|
||||||
def _make_pane(orientation: Gtk.Orientation, position: int = 0,
|
def _make_pane(orientation: Gtk.Orientation, position: int = 0,
|
||||||
|
@ -12,7 +13,7 @@ def _make_pane(orientation: Gtk.Orientation, position: int = 0,
|
||||||
pane = Gtk.Paned(orientation=orientation, hexpand=True, vexpand=True,
|
pane = Gtk.Paned(orientation=orientation, hexpand=True, vexpand=True,
|
||||||
shrink_start_child=False, resize_start_child=False,
|
shrink_start_child=False, resize_start_child=False,
|
||||||
start_child=start_child, end_child=end_child,
|
start_child=start_child, end_child=end_child,
|
||||||
position=position)
|
position=position, margin_start=8)
|
||||||
pane.add_css_class("emmental-pane")
|
pane.add_css_class("emmental-pane")
|
||||||
return pane
|
return pane
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ class Window(Adw.Window):
|
||||||
header = GObject.Property(type=Gtk.Widget)
|
header = GObject.Property(type=Gtk.Widget)
|
||||||
sidebar = GObject.Property(type=Gtk.Widget)
|
sidebar = GObject.Property(type=Gtk.Widget)
|
||||||
sidebar_size = GObject.Property(type=int, default=300)
|
sidebar_size = GObject.Property(type=int, default=300)
|
||||||
|
show_sidebar = GObject.Property(type=bool, default=False)
|
||||||
now_playing = GObject.Property(type=Gtk.Widget)
|
now_playing = GObject.Property(type=Gtk.Widget)
|
||||||
now_playing_size = GObject.Property(type=int, default=250)
|
now_playing_size = GObject.Property(type=int, default=250)
|
||||||
tracklist = GObject.Property(type=Gtk.Widget)
|
tracklist = GObject.Property(type=Gtk.Widget)
|
||||||
|
@ -45,19 +47,17 @@ class Window(Adw.Window):
|
||||||
position=self.now_playing_size,
|
position=self.now_playing_size,
|
||||||
start_child=self.now_playing,
|
start_child=self.now_playing,
|
||||||
end_child=self.tracklist)
|
end_child=self.tracklist)
|
||||||
self._outer_pane = _make_pane(Gtk.Orientation.HORIZONTAL,
|
self._layout = layout.Layout(content=self._inner_pane,
|
||||||
position=self.sidebar_size,
|
sidebar=self.sidebar)
|
||||||
start_child=self.sidebar,
|
self._toast = Adw.ToastOverlay(child=self._layout)
|
||||||
end_child=self._inner_pane)
|
|
||||||
self._toast = Adw.ToastOverlay(child=self._outer_pane)
|
|
||||||
|
|
||||||
self._outer_pane.add_css_class("emmental-padding")
|
self._layout.add_css_class("emmental-padding")
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self.add_css_class("devel")
|
self.add_css_class("devel")
|
||||||
|
|
||||||
self.bind_property("header", self._header, "child")
|
self.bind_property("header", self._header, "child")
|
||||||
self.bind_property("sidebar", self._outer_pane, "start-child")
|
self.bind_property("sidebar", self._layout, "sidebar")
|
||||||
self.bind_property("sidebar-size", self._outer_pane, "position",
|
self.bind_property("show-sidebar", self._layout, "show-sidebar",
|
||||||
GObject.BindingFlags.BIDIRECTIONAL)
|
GObject.BindingFlags.BIDIRECTIONAL)
|
||||||
self.bind_property("now-playing", self._inner_pane, "start-child")
|
self.bind_property("now-playing", self._inner_pane, "start-child")
|
||||||
self.bind_property("now-playing-size", self._inner_pane, "position",
|
self.bind_property("now-playing-size", self._inner_pane, "position",
|
||||||
|
|
|
@ -22,8 +22,8 @@ class TestWindow(unittest.TestCase):
|
||||||
self.assertIsInstance(self.window, Adw.Window)
|
self.assertIsInstance(self.window, Adw.Window)
|
||||||
self.assertIsInstance(self.window._box, Gtk.Box)
|
self.assertIsInstance(self.window._box, Gtk.Box)
|
||||||
self.assertIsInstance(self.window._header, Adw.Bin)
|
self.assertIsInstance(self.window._header, Adw.Bin)
|
||||||
self.assertIsInstance(self.window._outer_pane, Gtk.Paned)
|
|
||||||
self.assertIsInstance(self.window._inner_pane, Gtk.Paned)
|
self.assertIsInstance(self.window._inner_pane, Gtk.Paned)
|
||||||
|
self.assertIsInstance(self.window._layout, emmental.layout.Layout)
|
||||||
self.assertIsInstance(self.window._toast, Adw.ToastOverlay)
|
self.assertIsInstance(self.window._toast, Adw.ToastOverlay)
|
||||||
self.assertTrue(self.window.has_css_class("devel"))
|
self.assertTrue(self.window.has_css_class("devel"))
|
||||||
|
|
||||||
|
@ -41,22 +41,19 @@ class TestWindow(unittest.TestCase):
|
||||||
self.window._header)
|
self.window._header)
|
||||||
self.assertEqual(self.window._header.get_next_sibling(),
|
self.assertEqual(self.window._header.get_next_sibling(),
|
||||||
self.window._toast)
|
self.window._toast)
|
||||||
self.assertEqual(self.window._toast.get_child(),
|
self.assertEqual(self.window._toast.get_child(), self.window._layout)
|
||||||
self.window._outer_pane)
|
self.assertEqual(self.window._layout.content, self.window._inner_pane)
|
||||||
self.assertEqual(self.window._outer_pane.get_end_child(),
|
self.assertTrue(self.window._layout.has_css_class(
|
||||||
self.window._inner_pane)
|
|
||||||
self.assertTrue(self.window._outer_pane.has_css_class(
|
|
||||||
"emmental-padding"))
|
"emmental-padding"))
|
||||||
|
|
||||||
subtests = [(self.window._outer_pane, Gtk.Orientation.HORIZONTAL),
|
self.assertEqual(self.window._inner_pane.get_orientation(),
|
||||||
(self.window._inner_pane, Gtk.Orientation.VERTICAL)]
|
Gtk.Orientation.VERTICAL)
|
||||||
for pane, orientation in subtests:
|
self.assertEqual(self.window._inner_pane.get_margin_start(), 8)
|
||||||
self.assertEqual(pane.get_orientation(), orientation)
|
self.assertFalse(self.window._inner_pane.get_shrink_start_child())
|
||||||
self.assertFalse(pane.get_shrink_start_child())
|
self.assertFalse(self.window._inner_pane.get_resize_start_child())
|
||||||
self.assertFalse(pane.get_resize_start_child())
|
self.assertTrue(self.window._inner_pane.get_hexpand())
|
||||||
self.assertTrue(pane.get_hexpand())
|
self.assertTrue(self.window._inner_pane.get_vexpand())
|
||||||
self.assertTrue(pane.get_vexpand())
|
self.assertTrue(self.window._inner_pane.has_css_class("emmental-pane"))
|
||||||
self.assertTrue(pane.has_css_class("emmental-pane"))
|
|
||||||
|
|
||||||
def test_header(self):
|
def test_header(self):
|
||||||
"""Check setting a widget to the header area."""
|
"""Check setting a widget to the header area."""
|
||||||
|
@ -72,26 +69,29 @@ class TestWindow(unittest.TestCase):
|
||||||
"""Check setting a widget to the sidebar area."""
|
"""Check setting a widget to the sidebar area."""
|
||||||
self.assertIsNone(self.window.sidebar)
|
self.assertIsNone(self.window.sidebar)
|
||||||
self.window.sidebar = Gtk.Label()
|
self.window.sidebar = Gtk.Label()
|
||||||
self.assertEqual(self.window._outer_pane.get_start_child(),
|
self.assertEqual(self.window._layout.sidebar, self.window.sidebar)
|
||||||
self.window.sidebar)
|
|
||||||
|
|
||||||
window2 = emmental.window.Window(version="1.2.3", sidebar=Gtk.Label())
|
window2 = emmental.window.Window(version="1.2.3", sidebar=Gtk.Label())
|
||||||
self.assertIsInstance(window2.sidebar, Gtk.Label)
|
self.assertIsInstance(window2.sidebar, Gtk.Label)
|
||||||
self.assertEqual(window2._outer_pane.get_start_child(),
|
self.assertEqual(window2._layout.sidebar, window2.sidebar)
|
||||||
window2.sidebar)
|
|
||||||
|
def test_show_sidebar(self):
|
||||||
|
"""Check setting the show-sidebar property."""
|
||||||
|
self.assertFalse(self.window.show_sidebar)
|
||||||
|
self.assertFalse(self.window._layout.show_sidebar)
|
||||||
|
|
||||||
|
self.window.show_sidebar = True
|
||||||
|
self.assertTrue(self.window._layout.show_sidebar)
|
||||||
|
|
||||||
|
self.window._layout.show_sidebar = False
|
||||||
|
self.assertFalse(self.window.show_sidebar)
|
||||||
|
|
||||||
def test_sidebar_size(self):
|
def test_sidebar_size(self):
|
||||||
"""Check setting the size of the sidebar area."""
|
"""Check setting the size of the sidebar area."""
|
||||||
self.assertEqual(self.window.sidebar_size, 300)
|
self.assertEqual(self.window.sidebar_size, 300)
|
||||||
self.assertEqual(self.window._outer_pane.get_position(), 300)
|
|
||||||
|
|
||||||
self.window.sidebar_size = 100
|
self.window.sidebar_size = 100
|
||||||
self.assertEqual(self.window.sidebar_size, 100)
|
self.assertEqual(self.window.sidebar_size, 100)
|
||||||
self.assertEqual(self.window._outer_pane.get_position(), 100)
|
|
||||||
|
|
||||||
self.window._outer_pane.set_position(200)
|
|
||||||
self.assertEqual(self.window.sidebar_size, 200)
|
|
||||||
self.assertEqual(self.window._outer_pane.get_position(), 200)
|
|
||||||
|
|
||||||
def test_now_playing(self):
|
def test_now_playing(self):
|
||||||
"""Check setting a widget to the now_playing area."""
|
"""Check setting a widget to the now_playing area."""
|
||||||
|
|
Loading…
Reference in New Issue