From 7358183fefbedebc50f3e93192c09b168bf1842d Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 30 Aug 2023 11:11:43 -0400 Subject: [PATCH] sidebar: Use the Gtk.ListView.scroll_to() function for scrolling Rather than activating an action through a GLib.Variant, we can use the newly added scroll_to() function to do most of the work for us. Signed-off-by: Anna Schumaker --- emmental/sidebar/section.py | 5 +---- tests/sidebar/test_section.py | 11 ++--------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/emmental/sidebar/section.py b/emmental/sidebar/section.py index 4c4f1fe..849c196 100644 --- a/emmental/sidebar/section.py +++ b/emmental/sidebar/section.py @@ -2,7 +2,6 @@ """A sidebar Header attached to a hidden ListView for selecting playlists.""" import typing from gi.repository import GObject -from gi.repository import GLib from gi.repository import Gtk from .. import db from .. import factory @@ -86,9 +85,7 @@ class Section(header.Header): def select_playlist(self, playlist: db.playlist.Playlist) -> None: """Select the requested playlist.""" if (index := self.playlist_index(playlist)) is not None: - self._selection.select_item(index, True) - self._listview.activate_action("list.scroll-to-item", - GLib.Variant.new_uint32(index)) + self._listview.scroll_to(index, Gtk.ListScrollFlags.SELECT) @GObject.Signal(arg_types=(db.playlist.Playlist,)) def playlist_activated(self, playlist: db.playlist.Playlist): diff --git a/tests/sidebar/test_section.py b/tests/sidebar/test_section.py index b084119..e7ef5a4 100644 --- a/tests/sidebar/test_section.py +++ b/tests/sidebar/test_section.py @@ -4,7 +4,6 @@ import emmental.db import emmental.sidebar.section import tests.util import unittest.mock -from gi.repository import GLib from gi.repository import Gtk @@ -105,18 +104,12 @@ class TestSection(tests.util.TestCase): def test_select_playlist(self): """Test selecting a specific playlist.""" self.section.do_get_subtitle = unittest.mock.Mock(return_value="") - - playlist_selected = unittest.mock.Mock() - self.section.connect("playlist-selected", playlist_selected) playlist = self.table.create("Test Playlist") - playlist_selected.assert_not_called() with unittest.mock.patch.object(self.section._listview, - "activate_action") as mock_action: + "scroll_to") as mock_scroll_to: self.section.select_playlist(playlist) - playlist_selected.assert_called_with(self.section, playlist) - mock_action.assert_called_with("list.scroll-to-item", - GLib.Variant.new_uint32(0)) + mock_scroll_to.assert_called_with(0, Gtk.ListScrollFlags.SELECT) def test_playlist_selected(self): """Test selecting a playlist in the list."""