window: Add a "user-editing" property

I use the current focus widget to set the "user-editing" property, which
can be used to enable or disable accelerator actions.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2023-06-08 11:38:59 -04:00
parent 2b5cdaa197
commit eb162154b5
2 changed files with 18 additions and 0 deletions

View File

@ -32,6 +32,7 @@ class Window(Adw.Window):
now_playing = GObject.Property(type=Gtk.Widget)
now_playing_size = GObject.Property(type=int, default=250)
tracklist = GObject.Property(type=Gtk.Widget)
user_editing = GObject.Property(type=bool, default=False)
def __init__(self, version: str, **kwargs):
"""Initialize our Window."""
@ -62,10 +63,16 @@ class Window(Adw.Window):
GObject.BindingFlags.BIDIRECTIONAL)
self.bind_property("tracklist", self._inner_pane, "end-child")
self.connect("notify::focus-widget", self.__notify_focus_widget)
self._box.append(self._header)
self._box.append(self._toast)
self.set_content(self._box)
def __notify_focus_widget(self, win: Gtk.Window, param) -> None:
self.user_editing = isinstance(win.get_property("focus-widget"),
Gtk.Editable)
def close(self, *args) -> None:
"""Close the window."""
super().close()

View File

@ -132,6 +132,17 @@ class TestWindow(unittest.TestCase):
self.assertEqual(window2._inner_pane.get_end_child(),
window2.tracklist)
def test_user_editing(self):
"""Test the 'user-editing' property."""
self.window.header = Gtk.Entry()
self.window.tracklist = Gtk.Button()
self.assertFalse(self.window.user_editing)
self.window.set_focus(self.window.header)
self.assertTrue(self.window.user_editing)
self.window.set_focus(self.window.tracklist)
self.assertFalse(self.window.user_editing)
def test_post_toast(self):
"""Test posting a Toast message to the window."""
toast = self.window.post_toast("Test Toast")