ocarina/src/extra/oGtk/list.py

137 lines
3.3 KiB
Python

#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Mar 21, 2010 1:06:27 PM$"
import gtk
import guibuilder
import db
import ocarina
from et import needle
import re
import index
from et import times
from ct.call import *
class SongList(gtk.TreeView):
def __init__(self):
gtk.TreeView.__init__(self)
self.countvar = None
ocarina.events.invite("ocarina-filter-start",self.filter)
self.list = gtk.ListStore(int,str,str,str,str,int)
self.set_reorderable(True)
cell = gtk.CellRendererText()
cols = ["Id","Title","Length","Artist","Album","Play Count"]
for i in range(len(cols)):
col = gtk.TreeViewColumn(cols[i],cell)
col.add_attribute(cell,'text',i)
col.set_resizable(True)
col.set_sort_column_id(i)
col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
col.set_min_width(2)
col.set_max_width(700)
col.set_fixed_width(150)
col.set_sort_indicator(True)
if cols[i] != "Id":
self.append_column(col)
self.set_rules_hint(True)
self.connect("row-activated",self.doubleClick)
#self.tree.connect("button_release_event",self.clicked)
self.sel = self.get_selection()
self.sel.set_mode(gtk.SELECTION_MULTIPLE)
#self.list.set_sort_column_id(self.data.sortedCol,gtk.SORT_ASCENDING)
self.cols = self.get_columns()
#self.loadCols()
#self.tree.show()
#self.add(self.tree)
self.filter = self.list.filter_new()
self.filter.set_visible_func(self.setvisible)
self.sort = gtk.TreeModelSort(self.filter)
self.set_model(self.sort)
#self.set_model(self.filter)
#self.set_model(self.list)
#self.show_all()
# Add a row to the list
def insert(self,trackid):
file = list(db.gettrack(trackid))
file[2] = times.ftime(file[2])
self.list.append(file)
#self.list.insert(len(self.list),file)
if self.countvar != None:
ocarina.vars[self.countvar] += 1
def filter(self):
text = ocarina.vars["$filterText"]
self.results = index.search(ocarina.vars["$filterText"])
if self.countvar != None:
c = len(self.results)
if c == 0:
ocarina.vars[self.countvar] = len(self.list)
else:
ocarina.vars[self.countvar] = c
self.filter.refilter()
def setvisible(self,list,iter):
if ocarina.vars["$filterText"] == "":
return True
if (list[iter][0] in self.results) == True:
return True
return False
def doubleClick(self,tree,index,col):
trid = self.sort[index][0]
path = db.getpath(trid)
load(path)
play()
#cmd.run("load "+path)
#cmd.run("play")
#print self.sort[index][1],self.sort[index][0]
class LibraryList(SongList):
def __init__(self):
SongList.__init__(self)
self.countvar = "$libcount"
ocarina.vars["$libcount"] = 0
ocarina.events.invite("ocarina-gui-done",self.populate)
def populate(self):
thread = needle.Needle(self.insertLibrary)
thread.start()
#self.insertLibrary()
def insertLibrary(self):
try:
libid = db.libid("Music")
ocarina.events.start("ocarina-filter-start")
for track in db.getsongs(libid):
self.insert(track[1])
except Exception,e:
print e
self.show_all()
def make_songlist(attrs=None):return SongList()
def make_librarylist(attrs=None):return LibraryList()
guibuilder.parts["songlist"] = make_songlist
guibuilder.parts["librarylist"] = make_librarylist