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 <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
c195e68216
commit
7358183fef
|
@ -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):
|
||||
|
|
|
@ -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."""
|
||||
|
|
Loading…
Reference in New Issue