Get_attrs current source
The generic get_attrs() function now works correctly. I had to introduce a "get_cur_id()" function for each source to get this working.
This commit is contained in:
parent
9cef85a0e9
commit
1089b85e88
|
@ -1,44 +1,35 @@
|
|||
# Bryan Schumaker (8/8/2010)
|
||||
|
||||
__all__ = ["collection"]
|
||||
|
||||
import libsaria
|
||||
call = libsaria.event.call
|
||||
exists = libsaria.path.exists
|
||||
expand = libsaria.path.expand
|
||||
prefs = None
|
||||
|
||||
import library
|
||||
import playlist
|
||||
|
||||
reset = library.reset
|
||||
inc_score = library.inc_score
|
||||
inc_count = library.inc_count
|
||||
|
||||
controls = libsaria.controls
|
||||
|
||||
sources = dict()
|
||||
cur_source = None
|
||||
class Source:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.get_attrs = None
|
||||
#self.reset = None
|
||||
#self.load = None
|
||||
#self.walk = None
|
||||
#self.filter = None
|
||||
#self.is_visible = None
|
||||
#self.num_visible = None
|
||||
sources[name] = self
|
||||
self.name = name
|
||||
self.get_attrs = None
|
||||
self.get_cur_id = None
|
||||
sources[name] = self
|
||||
|
||||
def load_file(self, path):
|
||||
ret = controls.load(path)
|
||||
global cur_source
|
||||
# I should probably get a lock here...
|
||||
cur_source = self.name
|
||||
return ret
|
||||
return controls.load(path)
|
||||
|
||||
def get_attrs(*attrs):
|
||||
return sources[cur_source].get_attrs(attrs)
|
||||
|
||||
# I should probably get a lock here...
|
||||
src = sources[cur_source]
|
||||
id = src.get_cur_id()
|
||||
return src.get_attrs(id, *attrs)
|
||||
|
||||
def new_source(path, bg=True):
|
||||
global library
|
||||
|
|
|
@ -19,6 +19,7 @@ locations = None
|
|||
size = None
|
||||
visible = None
|
||||
source = None
|
||||
ttable = None
|
||||
|
||||
cur_id = -1
|
||||
lib_lock = threads.get_mutex("library")
|
||||
|
@ -28,6 +29,8 @@ badfiles = set()
|
|||
|
||||
def init():
|
||||
global source
|
||||
global ttable
|
||||
|
||||
import string
|
||||
ttable = dict()
|
||||
for s in string.punctuation:
|
||||
|
@ -36,7 +39,8 @@ def init():
|
|||
ttable[ord(s)] = ord(s) - 32
|
||||
|
||||
source = libsaria.sources.Source("library")
|
||||
source.get_attrs = get_attrs
|
||||
source.get_attrs = get_attrs
|
||||
source.get_cur_id = get_cur_id
|
||||
|
||||
def reset():
|
||||
from libsaria.trees import FSTree, DLFSTree, DLValTree
|
||||
|
@ -138,12 +142,10 @@ def song_id(artist, album, title):
|
|||
title = alb[title]
|
||||
return title.keys()[0]
|
||||
|
||||
def get_attrs(*attrs):
|
||||
if attrs[0].__class__ != str:
|
||||
id = attrs[0]
|
||||
attrs = attrs[1:]
|
||||
else:
|
||||
id = cur_id
|
||||
def get_cur_id():
|
||||
return cur_id
|
||||
|
||||
def get_attrs(id, *attrs):
|
||||
res = []
|
||||
rec = tracks.get(id, None)
|
||||
if rec == None:
|
||||
|
|
|
@ -40,7 +40,8 @@ def init():
|
|||
import library
|
||||
import random as rand
|
||||
source = libsaria.sources.Source("playlist")
|
||||
source.get_attrs = library.get_attrs
|
||||
source.get_attrs = library.get_attrs
|
||||
source.get_cur_id = get_cur_id
|
||||
|
||||
def reset():
|
||||
global song_list
|
||||
|
@ -114,6 +115,9 @@ def num_visible():
|
|||
return len(visible)
|
||||
return len(song_list)
|
||||
|
||||
def get_cur_id():
|
||||
return song_list[cur_index]
|
||||
|
||||
def seq_next():
|
||||
global cur_index
|
||||
global song_list
|
||||
|
|
|
@ -23,7 +23,6 @@ def filler():
|
|||
lib_page.init(filter, is_visible, right_click, library.play_id, reset)
|
||||
menu.add_lib_menu_item("Add to playlist", add_selected_to_playlist)
|
||||
lib_page.fill(library.walk, True)
|
||||
lib_page.goto()
|
||||
|
||||
def filter(text):
|
||||
library.filter(text)
|
||||
|
|
|
@ -20,7 +20,6 @@ def filler():
|
|||
plist_page.init(filter, is_visible, right_click, playlist.play_id, reset)
|
||||
menu.add_plist_menu_item("Remove from playlist", rm_selected_from_playlist)
|
||||
plist_page.fill(playlist.walk, True)
|
||||
plist_page.goto()
|
||||
|
||||
def filter(text):
|
||||
playlist.filter(text)
|
||||
|
|
|
@ -96,7 +96,7 @@ class ListView(gtk.TreeView):
|
|||
gtk.gdk.threads_leave()
|
||||
|
||||
def goto(self, *args):
|
||||
id = sources.cur_lib_id
|
||||
id = sources.get_attrs("id")
|
||||
if id == -1:
|
||||
return
|
||||
for index, row in enumerate(self.filter_model):
|
||||
|
|
Loading…
Reference in New Issue
Block a user