rind: Only allow selecting playlists in the sidebar
Selecting a playlist during scanning caused a segmentation fault so I had to push row-changed signals into the main thread through the use of an idle task. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
e4755aae6d
commit
014f2c89ab
|
@ -1,7 +1,8 @@
|
|||
# Copyright 2019 (c) Anna Schumaker.
|
||||
from . import gtk
|
||||
import curds
|
||||
from gi.repository import GObject, Gtk
|
||||
import threading
|
||||
from gi.repository import GObject, Gtk, GLib
|
||||
|
||||
toplevel = [ "Collection", None, "Library" ]
|
||||
|
||||
|
@ -11,6 +12,13 @@ class ManagerModel(GObject.GObject, Gtk.TreeModel):
|
|||
curds.Notify.notify_me("add-track", self.on_add_track)
|
||||
curds.Notify.notify_me("new-library-playlist", self.on_new_library)
|
||||
|
||||
self.update_lock = threading.Lock()
|
||||
self.update_queue = [ ]
|
||||
|
||||
def can_select_path(self, selection, model, path, current):
|
||||
plist = self.iter_playlist(self.get_iter(path))
|
||||
return isinstance(plist, curds.Playlist)
|
||||
|
||||
def do_get_column_type(self, col):
|
||||
return str
|
||||
|
||||
|
@ -96,9 +104,17 @@ class ManagerModel(GObject.GObject, Gtk.TreeModel):
|
|||
return None
|
||||
|
||||
def on_add_track(self, plist, track):
|
||||
iter = self.find_playlist(plist)
|
||||
if iter != None:
|
||||
with self.update_lock:
|
||||
if not plist in self.update_queue:
|
||||
self.update_queue.append(plist)
|
||||
GLib.idle_add(self.on_idle, priority=GLib.PRIORITY_DEFAULT)
|
||||
|
||||
def on_idle(self, *args):
|
||||
with self.update_lock:
|
||||
plist = self.update_queue.pop(0)
|
||||
iter = self.find_playlist(plist)
|
||||
self.row_changed(self.get_path(iter), iter)
|
||||
return GLib.SOURCE_REMOVE
|
||||
|
||||
def on_new_library(self, plist):
|
||||
iter = self.find_playlist(plist)
|
||||
|
@ -107,9 +123,10 @@ class ManagerModel(GObject.GObject, Gtk.TreeModel):
|
|||
if len(curds.PlaylistManager["Library"]) == 1:
|
||||
parent = self.iter_parent(iter)
|
||||
self.row_has_child_toggled(self.get_path(parent), parent)
|
||||
Treeview.expand_to_path(self.get_path(parent))
|
||||
|
||||
|
||||
MgrModel = ManagerModel()
|
||||
Treeview = gtk.Builder.get_object("manager_treeview")
|
||||
Treeview.set_model(MgrModel)
|
||||
Treeview.expand_all()
|
||||
Treeview.get_selection().set_select_function(MgrModel.can_select_path)
|
||||
|
|
|
@ -4,7 +4,7 @@ from . import manager
|
|||
import curds
|
||||
import os
|
||||
import unittest
|
||||
from gi.repository import Gtk, GObject
|
||||
from gi.repository import Gtk, GObject, GLib
|
||||
|
||||
plist_mgr = curds.PlaylistManager
|
||||
test_album = os.path.abspath("./trier/Test Library/Test Artist 02/Test Album 1")
|
||||
|
@ -18,6 +18,8 @@ class TestManager(unittest.TestCase):
|
|||
curds.PlaylistManager["Collection"].list.clear()
|
||||
curds.PlaylistManager["Library"].clear()
|
||||
curds.Notify.notify_me("new-track", curds.PlaylistManager["Collection"].add)
|
||||
curds.Notify.notify_me("add-track", manager.MgrModel.on_add_track)
|
||||
curds.Notify.notify_me("new-library-playlist", manager.MgrModel.on_new_library)
|
||||
if not curds.playlist.library.library_thread.is_alive():
|
||||
curds.playlist.library.library_thread = curds.ThreadQueue()
|
||||
|
||||
|
@ -120,3 +122,28 @@ class TestManager(unittest.TestCase):
|
|||
curds.playlist.library.library_thread.join()
|
||||
self.assertEqual(model.get_value(child, 0), "folder-music")
|
||||
self.assertEqual(model.get_value(child, 1), f"{test_album}\n10 Tracks")
|
||||
|
||||
def test_manager_selection(self):
|
||||
selection = manager.Treeview.get_selection()
|
||||
model = manager.MgrModel
|
||||
iter = model.find_playlist(plist_mgr["Collection"])
|
||||
path = model.get_path(iter)
|
||||
|
||||
plist = plist_mgr["Library"].add(test_album)
|
||||
curds.playlist.library.library_thread.join()
|
||||
|
||||
self.assertIsInstance(selection, Gtk.TreeSelection)
|
||||
selection.select_path(path)
|
||||
self.assertTrue(selection.path_is_selected(path))
|
||||
|
||||
path.next()
|
||||
selection.select_path(path)
|
||||
self.assertFalse(selection.path_is_selected(path))
|
||||
|
||||
path.next()
|
||||
selection.select_path(path)
|
||||
self.assertFalse(selection.path_is_selected(path))
|
||||
|
||||
path.down()
|
||||
selection.select_path(path)
|
||||
self.assertTrue(selection.path_is_selected(path))
|
||||
|
|
Loading…
Reference in New Issue