Began redoing library view, removed GuiObjects directory

git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@46 1daee41c-8060-4895-b1f0-2197c00d777a
This commit is contained in:
bjschuma 2009-07-14 03:17:53 +00:00
parent 5b752c95e8
commit 396631bc3d
23 changed files with 498 additions and 148 deletions

View File

@ -1,25 +1,18 @@
open:
geany &
geany src/GuiObjects/*.py
geany src/*.py
geany src/*.py &
clean:
rm -rf src/*.pyo
rm -rf src/*.pyc
rm -rf src/*~
rm -rf src/*.c
rm -rf src/*.o
rm -rf src/*.so
rm -rf src/GuiObjects/*.pyo
rm -rf src/GuiObjects/*~
rm -rf src/GuiObjects/*.c
rm -rf src/GuiObjects/*.o
rm -rf src/GuiObjects/*.so
rm *~
compile:
cd src && ./cythonize
cd src/GuiObjects && ./cythonize
install:
# mkdir ~/bin/ocarina-bin

View File

@ -1,3 +0,0 @@
# Used for initializing things in the GuiObjects directory
__all__ = ['button','check','controlPanel','image','scrobbler','menuItem','libView','infoView','plistView']

View File

@ -1,8 +0,0 @@
import gtk
class Image(gtk.Image):
def __init__(self,path):
gtk.Image.__init__(self)
self.set_from_file(path)
self.show()

View File

@ -1,42 +0,0 @@
import pango
import gtk
class InfoView(gtk.VBox):
def __init__(self,data):
gtk.VBox.__init__(self,False,0)
self.data = data
self.title = self.makeLabel("",13000,700)
self.album = self.makeLabel("",10000,400)
self.artist = self.makeLabel("",10000,400)
self.changeLabels()
self.show()
# Called when the song changes
def changeLabels(self):
title = ""
album = ""
artist = ""
if self.data.song:
title = self.data.song.info.title
album = "from "+self.data.song.info.album
artist = "by "+self.data.song.info.artist
self.title.set_text(title)
self.album.set_text(album)
self.artist.set_text(artist)
# Set the text, font, and weight of a label
def makeLabel(self,text,size,weight):
label = gtk.Label(text)
align = gtk.Alignment(0,1,0,0)
attr = pango.AttrList()
attr.insert(pango.AttrSize(size,0,-1))
attr.insert(pango.AttrWeight(weight,0,-1))
label.set_attributes(attr)
align.add(label)
self.pack_start(align,False,False,0)
label.show()
align.show()
return label

33
trunk/src/contentPane.py Normal file
View File

@ -0,0 +1,33 @@
import gtk
from libView import LibView
from scrobbler import Scrobbler
from plistView import PlistView
from controlPanel import ControlPanel
from rightPane import RightPane
class ContentPane(gtk.HBox):
def __init__(self,data):
gtk.HBox.__init__(self,False,0)
self.data = data
self.divider = gtk.HPaned()
self.divider.set_position(self.data.divider)
self.divider.show()
self.add(self.divider)
self.makeLeftSide()
self.makeRightSide()
self.show()
def makeLeftSide(self):
self.data.scrobbler = Scrobbler(self.data)
self.divider.add1(self.data.scrobbler)
def makeRightSide(self):
self.right = RightPane(self.data)
self.divider.add2(self.right)

View File

@ -3,7 +3,7 @@ import cPickle as pickle
from library import Library
class SavedData:
class Data:
def __init__(self,options):
path = os.path.join(options.user,".ocarina")
self.updateQ = False

11
trunk/src/image.py Normal file
View File

@ -0,0 +1,11 @@
import gtk
class Image(gtk.Image):
def __init__(self,path,stock):
gtk.Image.__init__(self)
if path:
self.set_from_file(path)
else:
self.set_from_stock(stock,gtk.ICON_SIZE_SMALL_TOOLBAR)
self.show()

18
trunk/src/label.py Normal file
View File

@ -0,0 +1,18 @@
import gtk
import pango
class Label(gtk.Alignment):
def __init__(self,text,size,weight):
gtk.Alignment.__init__(self,0,1,0,0)
self.show()
self.label = gtk.Label(text)
self.label.show()
attr = pango.AttrList()
attr.insert(pango.AttrSize(size,0,-1))
attr.insert(pango.AttrWeight(weight,0,-1))
self.label.set_attributes(attr)
self.add(self.label)
def set_text(self,text):
self.label.set_text(text)

36
trunk/src/liblist.py Normal file
View File

@ -0,0 +1,36 @@
import gtk
import gobject
from list import List
class LibList(List):
def __init__(self,data):
List.__init__(self,data,"Library")
self.pbar = gtk.ProgressBar()
self.pbaralign = gtk.Alignment(0,0,0,0)
self.pbaralign.add(self.pbar)
self.pbaralign.show()
for file in self.data.library.files:
self.insert(file)
self.filterRows("")
def updates(self):
self.pbar.show()
self.updating = True
gobject.timeout_add(500,self.updateLibview)
def stopUpdates(self):
self.updating = False
self.pbar.hide()
self.data.dump()
def updateLibview(self):
self.makeLabel()
self.pbar.pulse()
self.timeText()
return self.updating

View File

@ -25,11 +25,8 @@ class Library:
if os.path.exists(self.path) == False:
#print "Directory not found: %s" % dir
return
#print "Scanning: "+self.path
self.traverse("")
self.libview.stopUpdates()
#self.scanning = False
#print "Found %s files!" % str(self.count)
def reset(self):
@ -59,12 +56,9 @@ class Library:
song = SongInfo()
song.filename = os.path.join(self.path,joined)
self.files+=[song]
thread.start_new_thread(self.add,(self.hash(joined),self.count))
#self.add(self.hash(joined),self.count)
#thread.start_new_thread(self.add,(self.hash(joined),self.count))
self.add(self.hash(joined),self.count)
self.count += 1
#self.add(self.hash(joined),joined)
#else:
# self.notAdded.write(os.path.join(self.path,joined)+"\n")
# Hash a file and return list of words
@ -109,9 +103,6 @@ class Library:
print info.filename
#print "here"
#info.title = info.title.lower()
#info.album = info.album.lower()
#info.artist = info.artist.lower()
artist = info.artist.lower()
info.artistl = artist
album = info.album.lower()
@ -145,7 +136,7 @@ class Library:
for i in range(len(album)-1):
str = album[i]+album[i+1]
info.double[str] = True
self.libview.insertSong(info)
self.libview.insert(info)
# Return true if file is in the library

166
trunk/src/list.py Normal file
View File

@ -0,0 +1,166 @@
import gtk
import re
class List(gtk.ScrolledWindow):
def __init__(self,data,text):
gtk.ScrolledWindow.__init__(self)
self.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
self.text = text
self.count = 0
self.seconds = 0
self.list = gtk.ListStore(int,str,str,str,str,int)
self.tree = gtk.TreeView(self.list)
self.data = data
cell = gtk.CellRendererText()
cols = ["Id","Title","Length","Artist","Album","#"]
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_sort_indicator(False)
if cols[i] != "Id":
self.tree.append_column(col)
col.set_fixed_width(self.data.colSizes[i-1])
self.tree.set_rules_hint(True)
self.tree.connect("row-activated",self.selectSong,"cliked",list)
self.sel = self.tree.get_selection()
self.sel.set_mode(gtk.SELECTION_MULTIPLE)
self.list.set_sort_column_id(self.data.sortedCol,gtk.SORT_ASCENDING)
self.tree.show()
self.add(self.tree)
self.show()
self.resizeCols()
self.label = gtk.Label()
self.makeLabel()
self.align = gtk.Alignment(1,0,0,0)
self.timeLabel = gtk.Label("")
self.timeLabel.show()
self.align.add(self.timeLabel)
self.timeText()
self.string = ""
self.filter = self.list.filter_new()
self.filter.set_visible_func(self.hideRows,"")
self.sort = gtk.TreeModelSort(self.filter)
self.tree.set_model(self.sort)
#self.align.show()
def selectSong(self):
print "song selected"
def resizeCols(self):
print "resize cols"
def insert(self,file):
self.list.insert(self.count,[file.id,file.title,file.length,file.artist,file.album,file.count])
self.makeLabel()
self.timeText()
def makeLabel(self):
self.label.set_text(self.text+" ("+str(self.count)+")")
def timeText(self):
day = 0
hour = 0
min = 0
sec = self.seconds
day = sec/86500
sec = sec - (day*86500)
hour = sec/3600
sec = sec - (hour*3600)
min = sec/60
sec = sec - min*60
string = ""
string = self.toStr(day,"day")+self.toStr(hour,"hour")
string += self.toStr(min,"minute")+self.toStr(sec,"second")
self.timeLabel.set_text(string)
def toStr(self,time,label):
if time > 0:
string = str(time) + " " + label
if time > 1:
string+="s"
string+=" "
return string
return ""
def drop(self):
if len(self.list) == 0:
return
iter = self.list.get_iter(0)
while iter:
if self.remove(iter) == False:
self.makeLabel()
self.timeText()
return
def remove(self,iter):
self.count -= 1
self.seconds -= self.data.library.files[self.list[iter][0]].duration
return self.list.remove(iter)
def filterRows(self,string):
self.string = string
self.seconds = 0
self.count = 0
self.filter.refilter()
for row in self.filter:
#file = self.data.library.files[row[0]]
self.seconds+=self.data.library.files[row[0]].duration
self.count+=1
self.makeLabel()
self.timeText()
def hideRows(self,list,iter,string):
file = self.data.library.files[list[iter][0]]
if self.string == "":
self.visibleSong(file)
return True
elif len(self.string) == 1:
try:
file.single[self.string]
self.visibleSong(file)
return True
except:
return False
elif len(self.string) == 2:
try:
file.double[self.string]
self.visibleSong(file)
return True
except:
return False
if re.search(self.string,file.titlel):
self.visibleSong(file)
return True
elif re.search(self.string,file.artistl):
self.visibleSong(file)
return True
elif re.search(self.string,file.albuml):
self.visibleSong(file)
return True
return False
def visibleSong(self,file):
self.seconds += file.duration
self.count+=1

View File

@ -3,7 +3,7 @@ import gtk
import gobject
from options import Options
from saveddata import SavedData
from data import Data
from window import Window
@ -17,7 +17,7 @@ class main:
if ("-v" in argv) == True:
self.options.verbose = True
# Load saved data (or create new data)
self.data = SavedData(self.options)
self.data = Data(self.options)
#self.data.song = Song(self.quit)
self.data.quit = None
@ -31,8 +31,8 @@ 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.window.plistview.saveCols()
self.data.divider = self.window.contentPane.divider.get_position()
#self.window.contentPane.plistview.saveCols()
#self.data.clearSong()
self.data.dump()
#self.library.dump()

7
trunk/src/playlist.py Normal file
View File

@ -0,0 +1,7 @@
from list import List
class Playlist(List):
def __init__(self,data):
List.__init__(self,data,"Playlist")
print "playlist"

View File

@ -6,6 +6,8 @@ import re
from menuItem import MenuItem
from song import Song
from list import List
CONTINUE = 0
PAFTER = 1
@ -345,8 +347,6 @@ class PlistView(gtk.Notebook):
return True
except:
return False
#if self.search in self.data.library.files[list[iter][0]].letters == True:
# return True
file = self.data.library.files[list[iter][0]]
if re.search(self.search,file.titlel):
return True

6
trunk/src/queue.py Normal file
View File

@ -0,0 +1,6 @@
from list import List
class Queue(List):
def __init__(self,data):
List.__init__(self,data,"Queue")
print "Making queue"

192
trunk/src/rightPane.py Normal file
View File

@ -0,0 +1,192 @@
import gtk
import gobject
from label import Label
from playlist import Playlist
from queue import Queue
from liblist import LibList
from button import Button
from check import CheckButton
from image import Image
class RightPane(gtk.VBox):
def __init__(self,data):
gtk.VBox.__init__(self,False,0)
self.show()
self.data = data
self.title = Label("",13000,700)
self.album = Label("",10000,400)
self.artist = Label("",10000,400)
self.setLabels()
self.pack_start(self.title,False,False,0)
self.pack_start(self.album,False,False,0)
self.searchBar = gtk.Entry()
self.searchBar.connect("changed",self.textTyped)
self.searchBar.show()
artsearch = gtk.HBox(False,0)
artsearch.show()
artsearch.pack_start(self.artist,False,False,0)
artsearch.pack_end(self.searchBar,False,False,0)
self.pack_start(artsearch,False,False,0)
self.makeTabs()
self.makeControls()
hbox = gtk.HBox(False,0)
hbox.pack_start(self.library.pbaralign,False,False,0)
hbox.pack_end(self.playlist.align,False,False,0)
hbox.pack_end(self.queue.align,False,False,0)
hbox.pack_end(self.library.align,False,False,0)
self.pack_start(hbox,False,False,0)
hbox.show()
self.curTab = 0
self.changedTab(None,None,0)
def setLabels(self):
title = "a"
album = "b"
artist = "c"
if self.data.song:
title = self.data.song.info.title
album = "from "+self.data.song.info.album
artist = "by "+self.data.song.info.artist
self.title.set_text(title)
self.album.set_text(album)
self.artist.set_text(artist)
def makeTabs(self):
self.tabs = gtk.Notebook()
self.add(self.tabs)
self.tabs.show()
self.tabs.connect("switch-page",self.changedTab)
self.playlist = Playlist(self.data)
self.queue = Queue(self.data)
self.library = LibList(self.data)
self.data.library.libview = self.library
self.tabs.append_page(self.playlist,self.playlist.label)
self.tabs.append_page(self.queue,self.queue.label)
self.tabs.append_page(self.library,self.library.label)
def makeControls(self):
box = gtk.HBox(False,0)
box.show()
self.pauseImg = Image(None,gtk.STOCK_MEDIA_PAUSE)#Image(os.path.join("images","pause"))
box.pack_start(CheckButton("Random",self.toggleRand,self.data.random),False,False,0)
hbox = gtk.VBox()
hbox.show()
pbar = gtk.ProgressBar()
pbar.show()
pbar.set_fraction(0)
event = gtk.EventBox()
event.show()
event.add(pbar)
hbox.pack_start(event,True,False,0)
event.connect("button_release_event",self.pbarclick,pbar)
box.pack_start(hbox,True,True,0)
gobject.timeout_add(500,self.updatePBar,pbar)
(self.playImg,self.plauseBtn) = self.makeButton("plause",gtk.STOCK_MEDIA_PLAY,self.plause,box)
(self.stopImg,self.stopBtn) = self.makeButton("stop",gtk.STOCK_MEDIA_STOP,self.stop,box)
(self.nextImg,self.nextBtn) = self.makeButton("next",gtk.STOCK_MEDIA_NEXT,self.next,box)
self.pack_start(box,False,False,0)
def makeButton(self,name,img,func,box):
image = Image(None,img)
button = Button(name,image,None,func)
box.pack_start(button,False,False,0)
return image,button
def toggleRand(self,widgit):
self.data.random = not self.data.random
def pbarclick(self,widgit,data,pbar):
if data.button==1:
prcnt = float(data.x) / float(pbar.get_allocation()[2])
self.data.song.seek(int(prcnt * self.data.song.info.duration * 1000000000))
def updatePBar(self,pbar):
time = 0
if not self.data.song:
return True
try:
time = self.data.song.curTime()
except:
time = 0
if self.data.song.info.duration > 0:
pbar.set_fraction(float(time)/self.data.song.info.duration)
pbar.set_text(self.data.song.info.fixTime(time) + " / " + self.data.song.info.length)
return True
def plause(self,widgit,data):
self.data.song.plause()
self.changeImg()
def stop(self,widgit,data):
self.data.song.stop()
self.changeImg()
def next(self,widgit,data):
print "next song"
def changeImg(self):
self.plauseBtn.set_image(self.playImg)
if self.data.song.playing == True:
self.plauseBtn.set_image(self.pauseImg)
def changedTab(self,widgit,page,pagenum):
self.playlist.align.hide()
self.queue.align.hide()
self.library.align.hide()
self.curTab = pagenum
if pagenum == 0:
self.playlist.align.show()
elif pagenum == 1:
self.queue.align.show()
else:
self.library.align.show()
self.filter(self.searchBar.get_text().lower())
def dumpLib(self):
self.library.drop()
self.playlist.drop()
self.queue.drop()
def textTyped(self,entry):
search = entry.get_text().lower()
self.filter(search)
#print self.curTab
def filter(self,search):
if self.curTab == 0:
self.playlist.filterRows(search)
elif self.curTab == 1:
self.queue.filterRows(search)
else:
self.library.filterRows(search)

View File

@ -57,7 +57,7 @@ class Scrobbler(gtk.VBox):
self.pack_start(passwd,False,False,0)
self.pack_start(password,False,False,0)
else:
self.handshake()
#self.handshake()
#self.labels = [gtk.Label("")]*10
self.similar = []
for i in range(10):
@ -113,6 +113,8 @@ class Scrobbler(gtk.VBox):
# print line.strip()
def nowPlaying(self,info):
if self.session == None:
self.handshake()
vals = {"s":self.session,
"a":info.artist.title(),
"t":info.title.title(),

View File

@ -1,12 +1,14 @@
import gtk
import thread
from GuiObjects.menuItem import MenuItem
from GuiObjects.libView import LibView
from GuiObjects.plistView import PlistView
from GuiObjects.controlPanel import ControlPanel
from GuiObjects.infoView import InfoView
from GuiObjects.scrobbler import Scrobbler
from contentPane import ContentPane
from menuItem import MenuItem
from libView import LibView
from plistView import PlistView
from controlPanel import ControlPanel
#from infoView import InfoView
from scrobbler import Scrobbler
class Window(gtk.Window):
@ -57,9 +59,10 @@ class Window(gtk.Window):
def deleteLib(self,widgit,data,other=None):
self.contentPane.right.dumpLib()
self.data.library.reset()
self.libview.update()
self.clearPlist(None,None)
#self.libview.update()
#self.clearPlist(None,None)
def clearPlist(self,widgit,data,other=None):
@ -75,9 +78,8 @@ class Window(gtk.Window):
# Used to select a directory
def selectDir(self,widgit,data,func):
self.deleteLib(None,None)
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,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 = ""
if response == gtk.RESPONSE_OK:
@ -85,64 +87,10 @@ class Window(gtk.Window):
dirsel.hide()
if response != gtk.RESPONSE_OK:
return
self.libview.updates()
self.contentPane.right.library.updates()
thread.start_new_thread(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()
leftPane = gtk.Notebook()
leftPane.show()
leftPane.set_tab_pos(gtk.POS_LEFT)
self.libview = LibView(self.data)
self.libview.show()
libLabel = gtk.Label("Library")
libLabel.set_angle(90)
leftPane.append_page(self.libview,libLabel)
scrobbler = Scrobbler(self.data)
scrobLabel = gtk.Label("Last.fm")
scrobLabel.set_angle(90)
leftPane.append_page(scrobbler,scrobLabel)
self.data.scrobbler = scrobbler
self.divider.add1(leftPane)
rightPane=gtk.VBox(False,0)
topRight = gtk.HBox(False,0)
topRight.show()
infoview = InfoView(self.data)
topRight.pack_start(infoview,False,False,0)
rightPane.pack_start(topRight,False,False,0)
self.plistview = PlistView(self.data,infoview)
topRight.pack_end(self.plistview.searchBar,False,False,0)
rightPane.add(self.plistview)
self.makeBottomRow(rightPane)
rightPane.show()
self.libview.plist = self.plistview
self.divider.add2(rightPane)
self.contentPane.show()
self.contentPane = ContentPane(self.data)
self.mainLayout.add(self.contentPane)
def makeBottomRow(self,vbox):
box = gtk.HBox(False,0)
box.show()
controls = ControlPanel(self.data,self.plistview)
self.plistview.controls = controls
vbox.pack_start(controls,False,False,0)
box.pack_end(self.plistview.label)
align = gtk.Alignment(1,1,0,0)
align.add(box)
align.show()
vbox.pack_start(align,False,False,0)