From fd4cbf0a835d8ab4436924aec90c6befb401c078 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Sat, 27 Jun 2009 21:56:33 +0000 Subject: [PATCH] Library scanning, displaying library, resizing library pane git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@30 1daee41c-8060-4895-b1f0-2197c00d777a --- trunk/Makefile | 6 +-- trunk/src/GuiObjects/__init__.py | 2 +- trunk/src/GuiObjects/libView.py | 31 ++++++++++++++ trunk/src/GuiObjects/menuItem.py | 5 ++- trunk/src/library.py | 73 +++++++++++++++++++++++--------- trunk/src/ocarina.py | 1 + trunk/src/saveddata.py | 14 ++++-- trunk/src/songInfo.py | 5 ++- trunk/src/window.py | 53 ++++++++++++++++++----- 9 files changed, 148 insertions(+), 42 deletions(-) create mode 100644 trunk/src/GuiObjects/libView.py diff --git a/trunk/Makefile b/trunk/Makefile index 1d516dab..d4fb8998 100644 --- a/trunk/Makefile +++ b/trunk/Makefile @@ -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 *~ diff --git a/trunk/src/GuiObjects/__init__.py b/trunk/src/GuiObjects/__init__.py index c14251ba..3ffd5cd5 100644 --- a/trunk/src/GuiObjects/__init__.py +++ b/trunk/src/GuiObjects/__init__.py @@ -1,2 +1,2 @@ -__all__ = ['menuItem'] +__all__ = ['menuItem','libView'] diff --git a/trunk/src/GuiObjects/libView.py b/trunk/src/GuiObjects/libView.py new file mode 100644 index 00000000..0f01c5bd --- /dev/null +++ b/trunk/src/GuiObjects/libView.py @@ -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) diff --git a/trunk/src/GuiObjects/menuItem.py b/trunk/src/GuiObjects/menuItem.py index dc431206..eb9b3e3c 100644 --- a/trunk/src/GuiObjects/menuItem.py +++ b/trunk/src/GuiObjects/menuItem.py @@ -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: diff --git a/trunk/src/library.py b/trunk/src/library.py index ad858d8c..055ebb2b 100644 --- a/trunk/src/library.py +++ b/trunk/src/library.py @@ -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 diff --git a/trunk/src/ocarina.py b/trunk/src/ocarina.py index eb40c90e..72947713 100644 --- a/trunk/src/ocarina.py +++ b/trunk/src/ocarina.py @@ -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() diff --git a/trunk/src/saveddata.py b/trunk/src/saveddata.py index 309135f3..9acbe5da 100644 --- a/trunk/src/saveddata.py +++ b/trunk/src/saveddata.py @@ -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 diff --git a/trunk/src/songInfo.py b/trunk/src/songInfo.py index 2f0f6e58..6c8082d5 100644 --- a/trunk/src/songInfo.py +++ b/trunk/src/songInfo.py @@ -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 = "" diff --git a/trunk/src/window.py b/trunk/src/window.py index 650dbd02..e577ccd6 100644 --- a/trunk/src/window.py +++ b/trunk/src/window.py @@ -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)