ui: Convert Pane code into a class
This lets us create a new instance for each test we do, so we don't need to keep resetting a single static instance. Implements: #21 (Convert ui.pane.Pane into a class) Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
7979cb1a4a
commit
b05ef737f2
32
ui/pane.py
32
ui/pane.py
|
@ -1,21 +1,25 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from lib import settings
|
||||
from gi.repository import Gtk
|
||||
import audio
|
||||
import lib
|
||||
import playlist
|
||||
import sidebar
|
||||
from gi.repository import Gtk
|
||||
|
||||
Pane = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL)
|
||||
class Pane(Gtk.Paned):
|
||||
def __init__(self):
|
||||
Gtk.Paned.__init__(self)
|
||||
|
||||
def initialize():
|
||||
settings.initialize("sidebar.width", 200)
|
||||
initialize()
|
||||
# Suppress some warnings during testing
|
||||
if sidebar.Box.get_parent(): sidebar.Box.unparent()
|
||||
if playlist.Box.get_parent(): playlist.Box.unparent()
|
||||
|
||||
Pane.set_position(settings.get_int("sidebar.width"))
|
||||
Pane.set_start_child(sidebar.Box)
|
||||
Pane.set_end_child(playlist.Box)
|
||||
Pane.set_vexpand(True)
|
||||
self.set_shrink_start_child(False)
|
||||
self.set_start_child(sidebar.Box)
|
||||
self.set_end_child(playlist.Box)
|
||||
self.set_vexpand(True)
|
||||
|
||||
def on_change_position(pane, position):
|
||||
settings.set("sidebar.width", pane.get_position())
|
||||
Pane.connect("notify::position", on_change_position)
|
||||
lib.settings.initialize("sidebar.width", 250)
|
||||
self.set_position(lib.settings.get_int("sidebar.width"))
|
||||
self.connect("notify::position", self.change_position)
|
||||
|
||||
def change_position(self, pane, param):
|
||||
lib.settings.set("sidebar.width", self.get_position())
|
||||
|
|
|
@ -1,25 +1,29 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from lib import settings
|
||||
from . import pane
|
||||
from gi.repository import Gtk
|
||||
import audio
|
||||
import lib
|
||||
import playlist
|
||||
import sidebar
|
||||
import unittest
|
||||
from gi.repository import Gtk
|
||||
from . import pane
|
||||
|
||||
class TestUIPane(unittest.TestCase):
|
||||
def setUpClass():
|
||||
pane.initialize()
|
||||
class TestPane(unittest.TestCase):
|
||||
def setUp(self):
|
||||
lib.settings.reset()
|
||||
|
||||
def test_pane_init(self):
|
||||
self.assertIsInstance(pane.Pane, Gtk.Paned)
|
||||
self.assertEqual(pane.Pane.get_start_child(), sidebar.Box)
|
||||
self.assertEqual(pane.Pane.get_end_child(), playlist.Box)
|
||||
self.assertTrue(pane.Pane.get_vexpand())
|
||||
def test_init(self):
|
||||
paned = pane.Pane()
|
||||
|
||||
self.assertEqual(pane.Pane.get_position(), 200)
|
||||
self.assertEqual(settings.get_int("sidebar.width"), 200)
|
||||
self.assertIsInstance(paned, Gtk.Paned)
|
||||
self.assertEqual(paned.get_orientation(), Gtk.Orientation.HORIZONTAL)
|
||||
self.assertEqual(paned.get_start_child(), sidebar.Box)
|
||||
self.assertEqual(paned.get_end_child(), playlist.Box)
|
||||
self.assertFalse(paned.get_shrink_start_child())
|
||||
self.assertTrue(paned.get_vexpand())
|
||||
|
||||
pane.Pane.set_position(100)
|
||||
self.assertEqual(pane.Pane.get_position(), 100)
|
||||
self.assertEqual(settings.get_int("sidebar.width"), 100)
|
||||
def test_position(self):
|
||||
paned = pane.Pane()
|
||||
self.assertEqual(paned.get_position(), 250)
|
||||
self.assertEqual(lib.settings.get_int("sidebar.width"), 250)
|
||||
|
||||
paned.set_position(100)
|
||||
self.assertEqual(lib.settings.get_int("sidebar.width"), 100)
|
||||
|
|
|
@ -23,8 +23,10 @@ class TestUIWindow(unittest.TestCase):
|
|||
self.assertIsInstance(window.Window.get_titlebar(), audio.Header)
|
||||
self.assertIsInstance(window.Box, Gtk.Box)
|
||||
|
||||
self.assertIn(sidebar.Switcher, window.Box)
|
||||
self.assertIn(pane.Pane, window.Box)
|
||||
child = window.Box.get_first_child()
|
||||
self.assertEqual(child, sidebar.Switcher)
|
||||
child = child.get_next_sibling()
|
||||
self.assertIsInstance(child, pane.Pane)
|
||||
|
||||
self.assertEqual(window.Window.get_child(), window.Box)
|
||||
window.Window.present()
|
||||
|
|
|
@ -19,7 +19,7 @@ def initialize():
|
|||
initialize()
|
||||
|
||||
Box.append(sidebar.Switcher)
|
||||
Box.append(pane.Pane)
|
||||
Box.append(pane.Pane())
|
||||
|
||||
Window.add_controller(keyboard.Event)
|
||||
Window.set_title(version.string())
|
||||
|
|
Loading…
Reference in New Issue