Library scanning, displaying library, resizing library pane
git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@30 1daee41c-8060-4895-b1f0-2197c00d777a
This commit is contained in:
parent
972d0ccd77
commit
fd4cbf0a83
|
@ -1,12 +1,12 @@
|
||||||
|
|
||||||
open:
|
open:
|
||||||
geany src/*.py &
|
geany src/*.py &
|
||||||
geany src/GuiObjects/*.py &
|
geany src/GuiObjects/*.py
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf src/*.pyc
|
rm -rf src/*.pyo
|
||||||
rm -rf src/*~
|
rm -rf src/*~
|
||||||
rm -rf src/GuiObjects/*.pyc
|
rm -rf src/GuiObjects/*.pyo
|
||||||
rm -rf src/GuiObjects/*~
|
rm -rf src/GuiObjects/*~
|
||||||
rm *~
|
rm *~
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
|
|
||||||
__all__ = ['menuItem']
|
__all__ = ['menuItem','libView']
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import gobject
|
||||||
|
import pygtk
|
||||||
|
pygtk.require('2.0')
|
||||||
|
import gtk
|
||||||
|
|
||||||
|
|
||||||
|
class LibView(gtk.ScrolledWindow):
|
||||||
|
def __init__(self,library):
|
||||||
|
gtk.ScrolledWindow.__init__(self)
|
||||||
|
self.library = library
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
|
||||||
|
# Use to update the library pane
|
||||||
|
def update(self):
|
||||||
|
tree = gtk.TreeStore(str)
|
||||||
|
for artist in self.library.artAlb.keys():
|
||||||
|
ariter = tree.append(None,[artist])
|
||||||
|
for album in self.library.artAlb[artist]:
|
||||||
|
aliter = tree.append(ariter,[album])
|
||||||
|
for track in self.library.albTrk[album]:
|
||||||
|
tree.append(aliter,[track])
|
||||||
|
treeview = gtk.TreeView(tree)
|
||||||
|
col = gtk.TreeViewColumn('Library')
|
||||||
|
treeview.append_column(col)
|
||||||
|
cell = gtk.CellRendererText()
|
||||||
|
col.pack_start(cell,True)
|
||||||
|
col.add_attribute(cell,'text',0)
|
||||||
|
treeview.set_rules_hint(True)
|
||||||
|
treeview.show()
|
||||||
|
self.add(treeview)
|
|
@ -1,11 +1,12 @@
|
||||||
import gtk
|
import gtk
|
||||||
|
|
||||||
class MenuItem(gtk.MenuItem):
|
class MenuItem(gtk.MenuItem):
|
||||||
def __init__(self,lbl,func,text,func2,subs):
|
#
|
||||||
|
def __init__(self,lbl,func,text,data,subs):
|
||||||
gtk.MenuItem.__init__(self,label=lbl)
|
gtk.MenuItem.__init__(self,label=lbl)
|
||||||
|
|
||||||
if func != None:
|
if func != None:
|
||||||
self.connect("activate",func,text,func2)
|
self.connect("activate",func,text,data)
|
||||||
|
|
||||||
# If there are any submenus, add them
|
# If there are any submenus, add them
|
||||||
if subs != None:
|
if subs != None:
|
||||||
|
|
|
@ -6,12 +6,18 @@ from libdata import LibData
|
||||||
from songInfo import SongInfo
|
from songInfo import SongInfo
|
||||||
|
|
||||||
|
|
||||||
class Library():
|
class Library:
|
||||||
#def __init__(self,prnt):
|
#def __init__(self,prnt):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
#self.prnt = prnt
|
#self.prnt = prnt
|
||||||
self.data = LibData()
|
#self.data = LibData()
|
||||||
self.goodTypes = ["ogg","mp3"]#,"wma"]
|
self.goodTypes = ["ogg","mp3"]#,"wma"]
|
||||||
|
self.files = []
|
||||||
|
self.count = 0
|
||||||
|
self.path = ""
|
||||||
|
self.scanning = False
|
||||||
|
self.artAlb = dict()
|
||||||
|
self.albTrk = dict()
|
||||||
# Build up directory if library save
|
# Build up directory if library save
|
||||||
#self.save = os.path.expanduser("~")
|
#self.save = os.path.expanduser("~")
|
||||||
#self.save = os.path.join(self.save,".ocarina")
|
#self.save = os.path.join(self.save,".ocarina")
|
||||||
|
@ -25,30 +31,36 @@ class Library():
|
||||||
|
|
||||||
|
|
||||||
# Begin a scan on dir
|
# Begin a scan on dir
|
||||||
def scan(self,dir):
|
def scan(self,thread,dir):
|
||||||
print dir
|
#self.data = LibData()
|
||||||
self.data = LibData()
|
#self.data.path = os.path.expanduser(dir)
|
||||||
self.data.path = os.path.expanduser(dir)
|
|
||||||
if os.path.exists(self.data.path) == False:
|
self.files = []
|
||||||
|
self.count = 0
|
||||||
|
|
||||||
|
self.path = os.path.expanduser(dir)
|
||||||
|
if os.path.exists(self.path) == False:
|
||||||
#self.prnt(["Directory not found: "+dir])
|
#self.prnt(["Directory not found: "+dir])
|
||||||
print "Directory not found: %s" % dir
|
print "Directory not found: %s" % dir
|
||||||
return
|
return
|
||||||
print "Scanning: "+self.data.path
|
print "Scanning: "+self.path
|
||||||
|
self.scanning = True
|
||||||
self.traverse("")
|
self.traverse("")
|
||||||
num = len(self.data.files)
|
self.scanning = False
|
||||||
|
#num = len(self.data.files)
|
||||||
#self.prnt(["Found "+str(num)+" files!"])
|
#self.prnt(["Found "+str(num)+" files!"])
|
||||||
print "Found %s files!" % str(num)
|
print "Found %s files!" % str(self.count)
|
||||||
self.dump()
|
#self.dump()
|
||||||
|
|
||||||
|
|
||||||
# Traverse directorys
|
# Traverse directorys
|
||||||
def traverse(self,dir):
|
def traverse(self,dir):
|
||||||
# List and sort contents
|
# List and sort contents
|
||||||
contents = os.listdir(os.path.join(self.data.path,dir))
|
contents = os.listdir(os.path.join(self.path,dir))
|
||||||
contents.sort()
|
contents.sort()
|
||||||
for entry in contents:
|
for entry in contents:
|
||||||
joined = os.path.join(dir,entry)
|
joined = os.path.join(dir,entry)
|
||||||
full = os.path.join(self.data.path,joined)
|
full = os.path.join(self.path,joined)
|
||||||
# Call traverse on directorys
|
# Call traverse on directorys
|
||||||
if os.path.isdir(full):
|
if os.path.isdir(full):
|
||||||
self.traverse(joined)
|
self.traverse(joined)
|
||||||
|
@ -70,16 +82,11 @@ class Library():
|
||||||
|
|
||||||
# Add song to library
|
# Add song to library
|
||||||
def add(self,words,file):
|
def add(self,words,file):
|
||||||
index = len(self.data.files)
|
index = len(self.files)
|
||||||
info = SongInfo()
|
info = SongInfo()
|
||||||
info.filename = os.path.join(self.data.path,file)
|
info.filename = os.path.join(self.path,file)
|
||||||
|
self.files += [info.filename]
|
||||||
info.count = 0
|
info.count = 0
|
||||||
|
|
||||||
#use later for length
|
|
||||||
#a = f.audioProperties()
|
|
||||||
#info.length = a.length
|
|
||||||
|
|
||||||
#print file
|
|
||||||
split = file.rsplit(os.sep)
|
split = file.rsplit(os.sep)
|
||||||
max = 3
|
max = 3
|
||||||
if len(split) < 3:
|
if len(split) < 3:
|
||||||
|
@ -91,6 +98,30 @@ class Library():
|
||||||
info.album = split[len(split)-2]
|
info.album = split[len(split)-2]
|
||||||
else:
|
else:
|
||||||
info.artist = split[len(split)-3]
|
info.artist = split[len(split)-3]
|
||||||
|
self.files+=[info]
|
||||||
|
|
||||||
|
if (info.artist in self.artAlb.keys()) == False:
|
||||||
|
self.artAlb[info.artist] = [info.album]
|
||||||
|
elif (info.album in self.artAlb[info.artist]) == False:
|
||||||
|
self.artAlb[info.artist] += [info.album]
|
||||||
|
|
||||||
|
if (info.album in self.albTrk.keys()) == False:
|
||||||
|
self.albTrk[info.album] = [info.title]
|
||||||
|
#elif (info.title in self.albTrk[self.info.album]) == False:
|
||||||
|
else:
|
||||||
|
self.albTrk[info.album] += [info.title]
|
||||||
|
|
||||||
|
self.count += 1
|
||||||
|
#print self.count
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
#use later for length
|
||||||
|
#a = f.audioProperties()
|
||||||
|
#info.length = a.length
|
||||||
|
|
||||||
|
#print file
|
||||||
|
|
||||||
#print info.artist,",", info.title,",", info.album
|
#print info.artist,",", info.title,",", info.album
|
||||||
#print s1,s2,s3
|
#print s1,s2,s3
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ class main:
|
||||||
print "Quitting..."
|
print "Quitting..."
|
||||||
#print self.window.get_size()
|
#print self.window.get_size()
|
||||||
self.data.size = self.window.get_size()
|
self.data.size = self.window.get_size()
|
||||||
|
self.data.divider = self.window.divider.get_position()
|
||||||
self.data.dump()
|
self.data.dump()
|
||||||
#self.library.dump()
|
#self.library.dump()
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
|
|
|
@ -8,11 +8,16 @@ class SavedData:
|
||||||
path = os.path.join(options.user,".ocarina")
|
path = os.path.join(options.user,".ocarina")
|
||||||
path = os.path.join(path,"ocarina-data.data")
|
path = os.path.join(path,"ocarina-data.data")
|
||||||
self.size = (800,600)
|
self.size = (800,600)
|
||||||
|
self.divider = 150
|
||||||
self.library = Library()
|
self.library = Library()
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
self.load(path)
|
try:
|
||||||
|
self.load(path,options)
|
||||||
|
except:
|
||||||
|
if options.verbose == True:
|
||||||
|
print "Error loading user data"
|
||||||
|
|
||||||
|
|
||||||
# Dump user data to a file
|
# Dump user data to a file
|
||||||
|
@ -24,8 +29,11 @@ class SavedData:
|
||||||
|
|
||||||
|
|
||||||
# Read user data from the file
|
# Read user data from the file
|
||||||
def load(self,path):
|
def load(self,path,options):
|
||||||
print "User data found, loading..."
|
if options.verbose == True:
|
||||||
|
print "User data found, loading..."
|
||||||
p = pickle.Unpickler(open(path))
|
p = pickle.Unpickler(open(path))
|
||||||
data = p.load()
|
data = p.load()
|
||||||
self.size = data.size
|
self.size = data.size
|
||||||
|
self.library = data.library
|
||||||
|
self.divider = data.divider
|
||||||
|
|
|
@ -4,10 +4,11 @@ class SongInfo:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.id = 0
|
self.id = 0
|
||||||
self.filename = ""
|
self.filename = ""
|
||||||
self.tags = dict()
|
#self.tags = dict()
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.banned = False
|
#self.banned = False
|
||||||
self.length = None
|
self.length = None
|
||||||
|
self.duration = None
|
||||||
self.title = ""
|
self.title = ""
|
||||||
self.album = ""
|
self.album = ""
|
||||||
self.artist = ""
|
self.artist = ""
|
||||||
|
|
|
@ -7,6 +7,7 @@ import thread
|
||||||
from kiwi.ui.objectlist import Column, ObjectList
|
from kiwi.ui.objectlist import Column, ObjectList
|
||||||
|
|
||||||
from GuiObjects.menuItem import MenuItem
|
from GuiObjects.menuItem import MenuItem
|
||||||
|
from GuiObjects.libView import LibView
|
||||||
|
|
||||||
|
|
||||||
class Window(gtk.Window):
|
class Window(gtk.Window):
|
||||||
|
@ -20,11 +21,13 @@ class Window(gtk.Window):
|
||||||
self.resize(self.data.size[0],self.data.size[1])
|
self.resize(self.data.size[0],self.data.size[1])
|
||||||
self.set_title("Ocarina")
|
self.set_title("Ocarina")
|
||||||
self.connect("delete_event",onQuit)
|
self.connect("delete_event",onQuit)
|
||||||
|
self.set_icon_from_file("images/ocarina.png")
|
||||||
|
|
||||||
self.mainLayout = gtk.VBox(False,0)
|
self.mainLayout = gtk.VBox(False,0)
|
||||||
self.mainLayout.show()
|
|
||||||
self.add(self.mainLayout)
|
self.add(self.mainLayout)
|
||||||
self.makeMenuBar()
|
self.makeMenuBar()
|
||||||
|
self.makeContentPane()
|
||||||
'''
|
'''
|
||||||
self.song = song
|
self.song = song
|
||||||
self.ops = ops
|
self.ops = ops
|
||||||
|
@ -46,6 +49,7 @@ class Window(gtk.Window):
|
||||||
self.makeControls()
|
self.makeControls()
|
||||||
self.maximize()
|
self.maximize()
|
||||||
'''
|
'''
|
||||||
|
self.mainLayout.show()
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
|
@ -262,12 +266,13 @@ class Window(gtk.Window):
|
||||||
return check
|
return check
|
||||||
|
|
||||||
|
|
||||||
|
# Used to make the top row menu bar
|
||||||
def makeMenuBar(self):
|
def makeMenuBar(self):
|
||||||
# Make a menu bar
|
# Make a menu bar
|
||||||
bar = gtk.MenuBar()
|
bar = gtk.MenuBar()
|
||||||
# This is the dropdown selections
|
# This is the dropdown selections
|
||||||
# Make a new library option
|
# Make a new library option
|
||||||
newLib = MenuItem("New Library",self.selectDir,None,self.data.library.scan,None)
|
newLib = MenuItem("New Library",self.selectDir,"ScanLib",self.data.library.scan,None)
|
||||||
library = MenuItem("Library",None,None,None,[newLib])
|
library = MenuItem("Library",None,None,None,[newLib])
|
||||||
bar.append(library)
|
bar.append(library)
|
||||||
|
|
||||||
|
@ -281,21 +286,49 @@ class Window(gtk.Window):
|
||||||
self.mainLayout.pack_start(bar,False,False,0)
|
self.mainLayout.pack_start(bar,False,False,0)
|
||||||
|
|
||||||
|
|
||||||
|
# Used to select a directory
|
||||||
def selectDir(self,widgit,data,func):
|
def selectDir(self,widgit,data,func):
|
||||||
dirsel = gtk.FileChooserDialog(None,action=gtk.FILE_CHOOSER_ACTION_OPEN,buttons =(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
dirsel = gtk.FileChooserDialog(None,action=gtk.FILE_CHOOSER_ACTION_OPEN,buttons =(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
||||||
dirsel.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
dirsel.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
||||||
|
response = None
|
||||||
response = dirsel.run()
|
response = dirsel.run()
|
||||||
file = ""
|
file = ""
|
||||||
#dirsel = None
|
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
#print dirsel.get_filename(),'selected'
|
|
||||||
#dirsel.hide()
|
|
||||||
file = dirsel.get_filename()
|
file = dirsel.get_filename()
|
||||||
#dirsel.hide()
|
|
||||||
#dirsel = None
|
|
||||||
#func(file)
|
|
||||||
#else:
|
|
||||||
dirsel.hide()
|
dirsel.hide()
|
||||||
dirsel.destroy()
|
dirsel.destroy()
|
||||||
dirsel = None
|
dirsel = None
|
||||||
thread.start_new_thread(func,("name",file))
|
#thread.start_new_thread(func,(data,file))
|
||||||
|
func(data,file)
|
||||||
|
|
||||||
|
|
||||||
|
def makeContentPane(self):
|
||||||
|
self.contentPane = gtk.HBox(False,0)
|
||||||
|
self.divider = gtk.HPaned()
|
||||||
|
self.divider.set_position(self.data.divider)
|
||||||
|
self.contentPane.add(self.divider)
|
||||||
|
self.divider.show()
|
||||||
|
|
||||||
|
libview = LibView(self.data.library)
|
||||||
|
libview.show()
|
||||||
|
self.divider.add1(libview)
|
||||||
|
|
||||||
|
tracks = gtk.TreeStore(str)
|
||||||
|
for file in self.data.library.files:
|
||||||
|
tracks.append(None,[file.title])
|
||||||
|
|
||||||
|
trackview = gtk.TreeView(tracks)
|
||||||
|
title = gtk.TreeViewColumn('filename')
|
||||||
|
trackview.append_column(title)
|
||||||
|
cell = gtk.CellRendererText()
|
||||||
|
title.pack_start(cell,True)
|
||||||
|
title.add_attribute(cell,'text',0)
|
||||||
|
trackview.set_rules_hint(True)
|
||||||
|
trackview.show()
|
||||||
|
trackscroll = gtk.ScrolledWindow()
|
||||||
|
trackscroll.add(trackview)
|
||||||
|
trackscroll.show()
|
||||||
|
self.divider.add2(trackscroll)
|
||||||
|
|
||||||
|
self.contentPane.show()
|
||||||
|
self.mainLayout.add(self.contentPane)
|
||||||
|
|
Loading…
Reference in New Issue