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:
|
||||
geany src/*.py &
|
||||
geany src/GuiObjects/*.py &
|
||||
geany src/GuiObjects/*.py
|
||||
|
||||
clean:
|
||||
rm -rf src/*.pyc
|
||||
rm -rf src/*.pyo
|
||||
rm -rf src/*~
|
||||
rm -rf src/GuiObjects/*.pyc
|
||||
rm -rf src/GuiObjects/*.pyo
|
||||
rm -rf src/GuiObjects/*~
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
if func != None:
|
||||
self.connect("activate",func,text,func2)
|
||||
self.connect("activate",func,text,data)
|
||||
|
||||
# If there are any submenus, add them
|
||||
if subs != None:
|
||||
|
|
|
@ -6,12 +6,18 @@ from libdata import LibData
|
|||
from songInfo import SongInfo
|
||||
|
||||
|
||||
class Library():
|
||||
class Library:
|
||||
#def __init__(self,prnt):
|
||||
def __init__(self):
|
||||
#self.prnt = prnt
|
||||
self.data = LibData()
|
||||
#self.data = LibData()
|
||||
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
|
||||
#self.save = os.path.expanduser("~")
|
||||
#self.save = os.path.join(self.save,".ocarina")
|
||||
|
@ -25,30 +31,36 @@ class Library():
|
|||
|
||||
|
||||
# Begin a scan on dir
|
||||
def scan(self,dir):
|
||||
print dir
|
||||
self.data = LibData()
|
||||
self.data.path = os.path.expanduser(dir)
|
||||
if os.path.exists(self.data.path) == False:
|
||||
def scan(self,thread,dir):
|
||||
#self.data = LibData()
|
||||
#self.data.path = os.path.expanduser(dir)
|
||||
|
||||
self.files = []
|
||||
self.count = 0
|
||||
|
||||
self.path = os.path.expanduser(dir)
|
||||
if os.path.exists(self.path) == False:
|
||||
#self.prnt(["Directory not found: "+dir])
|
||||
print "Directory not found: %s" % dir
|
||||
return
|
||||
print "Scanning: "+self.data.path
|
||||
print "Scanning: "+self.path
|
||||
self.scanning = True
|
||||
self.traverse("")
|
||||
num = len(self.data.files)
|
||||
self.scanning = False
|
||||
#num = len(self.data.files)
|
||||
#self.prnt(["Found "+str(num)+" files!"])
|
||||
print "Found %s files!" % str(num)
|
||||
self.dump()
|
||||
print "Found %s files!" % str(self.count)
|
||||
#self.dump()
|
||||
|
||||
|
||||
# Traverse directorys
|
||||
def traverse(self,dir):
|
||||
# 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()
|
||||
for entry in contents:
|
||||
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
|
||||
if os.path.isdir(full):
|
||||
self.traverse(joined)
|
||||
|
@ -70,16 +82,11 @@ class Library():
|
|||
|
||||
# Add song to library
|
||||
def add(self,words,file):
|
||||
index = len(self.data.files)
|
||||
index = len(self.files)
|
||||
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
|
||||
|
||||
#use later for length
|
||||
#a = f.audioProperties()
|
||||
#info.length = a.length
|
||||
|
||||
#print file
|
||||
split = file.rsplit(os.sep)
|
||||
max = 3
|
||||
if len(split) < 3:
|
||||
|
@ -91,6 +98,30 @@ class Library():
|
|||
info.album = split[len(split)-2]
|
||||
else:
|
||||
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 s1,s2,s3
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ class main:
|
|||
print "Quitting..."
|
||||
#print self.window.get_size()
|
||||
self.data.size = self.window.get_size()
|
||||
self.data.divider = self.window.divider.get_position()
|
||||
self.data.dump()
|
||||
#self.library.dump()
|
||||
gtk.main_quit()
|
||||
|
|
|
@ -8,11 +8,16 @@ class SavedData:
|
|||
path = os.path.join(options.user,".ocarina")
|
||||
path = os.path.join(path,"ocarina-data.data")
|
||||
self.size = (800,600)
|
||||
self.divider = 150
|
||||
self.library = Library()
|
||||
self.path = 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
|
||||
|
@ -24,8 +29,11 @@ class SavedData:
|
|||
|
||||
|
||||
# Read user data from the file
|
||||
def load(self,path):
|
||||
print "User data found, loading..."
|
||||
def load(self,path,options):
|
||||
if options.verbose == True:
|
||||
print "User data found, loading..."
|
||||
p = pickle.Unpickler(open(path))
|
||||
data = p.load()
|
||||
self.size = data.size
|
||||
self.library = data.library
|
||||
self.divider = data.divider
|
||||
|
|
|
@ -4,10 +4,11 @@ class SongInfo:
|
|||
def __init__(self):
|
||||
self.id = 0
|
||||
self.filename = ""
|
||||
self.tags = dict()
|
||||
#self.tags = dict()
|
||||
self.count = 0
|
||||
self.banned = False
|
||||
#self.banned = False
|
||||
self.length = None
|
||||
self.duration = None
|
||||
self.title = ""
|
||||
self.album = ""
|
||||
self.artist = ""
|
||||
|
|
|
@ -7,6 +7,7 @@ import thread
|
|||
from kiwi.ui.objectlist import Column, ObjectList
|
||||
|
||||
from GuiObjects.menuItem import MenuItem
|
||||
from GuiObjects.libView import LibView
|
||||
|
||||
|
||||
class Window(gtk.Window):
|
||||
|
@ -20,11 +21,13 @@ class Window(gtk.Window):
|
|||
self.resize(self.data.size[0],self.data.size[1])
|
||||
self.set_title("Ocarina")
|
||||
self.connect("delete_event",onQuit)
|
||||
self.set_icon_from_file("images/ocarina.png")
|
||||
|
||||
self.mainLayout = gtk.VBox(False,0)
|
||||
self.mainLayout.show()
|
||||
|
||||
self.add(self.mainLayout)
|
||||
self.makeMenuBar()
|
||||
self.makeContentPane()
|
||||
'''
|
||||
self.song = song
|
||||
self.ops = ops
|
||||
|
@ -46,6 +49,7 @@ class Window(gtk.Window):
|
|||
self.makeControls()
|
||||
self.maximize()
|
||||
'''
|
||||
self.mainLayout.show()
|
||||
self.show()
|
||||
|
||||
|
||||
|
@ -262,12 +266,13 @@ class Window(gtk.Window):
|
|||
return check
|
||||
|
||||
|
||||
# Used to make the top row menu bar
|
||||
def makeMenuBar(self):
|
||||
# Make a menu bar
|
||||
bar = gtk.MenuBar()
|
||||
# This is the dropdown selections
|
||||
# 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])
|
||||
bar.append(library)
|
||||
|
||||
|
@ -281,21 +286,49 @@ class Window(gtk.Window):
|
|||
self.mainLayout.pack_start(bar,False,False,0)
|
||||
|
||||
|
||||
# Used to select a directory
|
||||
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.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
||||
response = None
|
||||
response = dirsel.run()
|
||||
file = ""
|
||||
#dirsel = None
|
||||
if response == gtk.RESPONSE_OK:
|
||||
#print dirsel.get_filename(),'selected'
|
||||
#dirsel.hide()
|
||||
file = dirsel.get_filename()
|
||||
#dirsel.hide()
|
||||
#dirsel = None
|
||||
#func(file)
|
||||
#else:
|
||||
dirsel.hide()
|
||||
dirsel.destroy()
|
||||
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