curds: Rename PlaylistNode.lock -> PlaylistNode.node_lock
I want to have a separate playlist lock named "lock", so this frees up the name. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
4586577cc5
commit
3dd2e428f1
|
@ -12,7 +12,7 @@ class NewPlaylist(playlist.Playlist):
|
|||
notify.register("new-track", self.add)
|
||||
|
||||
def __getstate__(self):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
state = node.PlaylistNode.__getstate__(self)
|
||||
state["list"] = [ ]
|
||||
state["current"] = -1
|
||||
|
|
|
@ -8,7 +8,7 @@ import unicodedata
|
|||
class PlaylistNode(tree.ETree):
|
||||
def __init__(self, name="", icon=""):
|
||||
tree.ETree.__init__(self, name, icon)
|
||||
self.lock = threading.RLock()
|
||||
self.node_lock = threading.RLock()
|
||||
self.__init_common__()
|
||||
|
||||
def __init_common__(self):
|
||||
|
@ -16,12 +16,12 @@ class PlaylistNode(tree.ETree):
|
|||
|
||||
def __getstate__(self):
|
||||
state = tree.ETree.__getstate__(self)
|
||||
del state["lock"]
|
||||
del state["node_lock"]
|
||||
return state
|
||||
|
||||
def __setstate__(self, state):
|
||||
tree.ETree.__setstate__(self, state)
|
||||
self.lock = threading.RLock()
|
||||
self.node_lock = threading.RLock()
|
||||
self.__init_common__()
|
||||
|
||||
def append_child(self, child):
|
||||
|
@ -29,6 +29,6 @@ class PlaylistNode(tree.ETree):
|
|||
return self.__insert__(len(self.children), child)
|
||||
|
||||
def reset(self):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
self.children.clear()
|
||||
self.__init_common__()
|
||||
|
|
|
@ -4,6 +4,7 @@ from .. import notify
|
|||
from .. import sort
|
||||
from .. import trak
|
||||
import random
|
||||
import threading
|
||||
from gi.repository import GLib
|
||||
|
||||
class Playlist(node.PlaylistNode):
|
||||
|
@ -19,19 +20,19 @@ class Playlist(node.PlaylistNode):
|
|||
node.PlaylistNode.__init__(self, name, icon)
|
||||
|
||||
def __getitem__(self, i):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
if i < len(self.list):
|
||||
return self.list[i]
|
||||
return None
|
||||
|
||||
def __getstate__(self):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
state = node.PlaylistNode.__getstate__(self)
|
||||
state["list"] = [ t.path for t in self.list ]
|
||||
return state
|
||||
|
||||
def __len__(self):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
return len(self.list)
|
||||
|
||||
def __setstate__(self, state):
|
||||
|
@ -46,7 +47,7 @@ class Playlist(node.PlaylistNode):
|
|||
self.visible = False
|
||||
|
||||
def add(self, track):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
if track == None:
|
||||
return
|
||||
if len(self.sort_order) == 0:
|
||||
|
@ -67,7 +68,7 @@ class Playlist(node.PlaylistNode):
|
|||
notify.notify("save-playlists")
|
||||
|
||||
def contains(self, track):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
return track in self.list
|
||||
|
||||
def get_markup(self):
|
||||
|
@ -76,7 +77,7 @@ class Playlist(node.PlaylistNode):
|
|||
return f"{t}\n{l} Track{'s' if l != 1 else ''}"
|
||||
|
||||
def index(self, track):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
if track != None:
|
||||
if len(self.sort_order) == 0:
|
||||
for i, t in enumerate(self.list):
|
||||
|
@ -90,7 +91,7 @@ class Playlist(node.PlaylistNode):
|
|||
return None
|
||||
|
||||
def move(self, track, new):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
old = self.index(track)
|
||||
if old == None:
|
||||
return
|
||||
|
@ -109,7 +110,7 @@ class Playlist(node.PlaylistNode):
|
|||
self.current -= 1
|
||||
|
||||
def next(self):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
max = len(self) - 1
|
||||
if max == -1:
|
||||
return None
|
||||
|
@ -128,7 +129,7 @@ class Playlist(node.PlaylistNode):
|
|||
return self.list[self.current]
|
||||
|
||||
def peek(self, n):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
cur = self.current
|
||||
res = [ ]
|
||||
|
||||
|
@ -142,7 +143,7 @@ class Playlist(node.PlaylistNode):
|
|||
return res
|
||||
|
||||
def remove(self, track):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
pos = self.index(track)
|
||||
if pos != None:
|
||||
self.list.remove(track)
|
||||
|
@ -151,7 +152,7 @@ class Playlist(node.PlaylistNode):
|
|||
self.track_removed(track, pos)
|
||||
|
||||
def reset(self):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
self.list.clear()
|
||||
self.current = -1
|
||||
self.loop = False
|
||||
|
@ -159,7 +160,7 @@ class Playlist(node.PlaylistNode):
|
|||
node.PlaylistNode.reset(self)
|
||||
|
||||
def runtime(self):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
m, s = divmod(sum([ track.length for track in self.list ]), 60)
|
||||
h, m = divmod(m, 60)
|
||||
d, h = divmod(h, 24)
|
||||
|
@ -181,7 +182,7 @@ class Playlist(node.PlaylistNode):
|
|||
return self.random
|
||||
|
||||
def sort(self, field):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
if field in self.sort_order:
|
||||
self.sort_order.remove(field)
|
||||
else:
|
||||
|
|
|
@ -8,7 +8,7 @@ class PreviousPlaylist(playlist.Playlist):
|
|||
playlist.Playlist.__init__(self, "Previous", "edit-undo", [ ], can_loop=False, can_random=False)
|
||||
|
||||
def __getstate__(self):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
state = node.PlaylistNode.__getstate__(self)
|
||||
state["list"] = [ ]
|
||||
state["current"] = -1
|
||||
|
|
|
@ -48,14 +48,14 @@ class PlaylistRoot(node.PlaylistNode):
|
|||
self.current[0].changed()
|
||||
|
||||
def lookup(self, name):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
for node in self.children:
|
||||
if node.sort_key() == sort.key(name):
|
||||
return node
|
||||
return None
|
||||
|
||||
def next(self):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
old = self.current[0]
|
||||
|
||||
self.track = self.current[0].next()
|
||||
|
@ -69,7 +69,7 @@ class PlaylistRoot(node.PlaylistNode):
|
|||
return self.track
|
||||
|
||||
def peek(self, n):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
state = random.getstate()
|
||||
res = [ ]
|
||||
|
||||
|
@ -88,14 +88,14 @@ class PlaylistRoot(node.PlaylistNode):
|
|||
return self.track
|
||||
|
||||
def reset(self):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
for plist in self.children:
|
||||
plist.reset()
|
||||
self.current = [ self.lookup("Collection") ]
|
||||
self.track = None
|
||||
|
||||
def select(self, plist):
|
||||
with self.lock:
|
||||
with self.node_lock:
|
||||
old = self.current[0]
|
||||
|
||||
if plist == self.lookup("Collection"):
|
||||
|
|
Loading…
Reference in New Issue