Began using gtk for a gui
git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@11 1daee41c-8060-4895-b1f0-2197c00d777a
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 894 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 740 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 894 B |
After Width: | Height: | Size: 1.5 KiB |
|
@ -6,9 +6,9 @@ from songInfo import SongInfo
|
|||
|
||||
|
||||
class Library():
|
||||
def __init__(self,prnt):
|
||||
#def __init__(self):
|
||||
self.prnt = prnt
|
||||
#def __init__(self,prnt):
|
||||
def __init__(self):
|
||||
#self.prnt = prnt
|
||||
self.data = LibData()
|
||||
self.goodTypes = ["ogg","mp3","wma"]
|
||||
# Build up directory if library save
|
||||
|
@ -17,7 +17,8 @@ class Library():
|
|||
self.save = os.path.join(self.save,"library.pickle")
|
||||
# Load existing library
|
||||
if os.path.exists(self.save):
|
||||
self.prnt(["Library found, loading..."])
|
||||
#self.prnt(["Library found, loading..."])
|
||||
print "Library found, loading..."
|
||||
p = pickle.Unpickler(open(self.save))
|
||||
self.data = p.load()
|
||||
|
||||
|
@ -27,12 +28,14 @@ class Library():
|
|||
self.data = LibData()
|
||||
self.data.path = os.path.expanduser(dir)
|
||||
if os.path.exists(self.data.path) == False:
|
||||
self.prnt(["Directory not found: "+dir])
|
||||
#self.prnt(["Directory not found: "+dir])
|
||||
print "Directory not found: %s" % dir
|
||||
return
|
||||
self.prnt(["Scanning: "+self.data.path])
|
||||
self.traverse("")
|
||||
num = len(self.data.files)
|
||||
self.prnt(["Found "+str(num)+" files!"])
|
||||
#self.prnt(["Found "+str(num)+" files!"])
|
||||
print "Found %s files!" % str(num)
|
||||
self.dump()
|
||||
|
||||
|
||||
|
|
144
trunk/ocarina.py
|
@ -3,24 +3,25 @@ import os
|
|||
import sys
|
||||
import thread
|
||||
|
||||
import pygtk
|
||||
pygtk.require('2.0')
|
||||
import gtk
|
||||
|
||||
from song import Song
|
||||
from cline import CLine
|
||||
from duration import Duration
|
||||
from library import Library
|
||||
from playlist import Playlist
|
||||
from songInfo import SongInfo
|
||||
#import cmnds
|
||||
|
||||
#gtk.gdk.threads_init()
|
||||
gobject.threads_init()
|
||||
|
||||
class main:
|
||||
def __init__(self,argv):
|
||||
#if len(argv) == 0:
|
||||
# print "python ocarina.py /path/to/song/"
|
||||
# return
|
||||
self.commands = CLine()
|
||||
self.registerCmnds()
|
||||
self.makeWindow()
|
||||
|
||||
self.library = Library(self.commands.printLines)
|
||||
self.plist = Playlist(self.commands.printLines)
|
||||
self.library = Library()
|
||||
self.plist = Playlist()
|
||||
self.plist.insert(self.library.nonBanned())
|
||||
|
||||
self.song = None
|
||||
|
@ -37,43 +38,88 @@ class main:
|
|||
if os.path.exists(file):
|
||||
info = SongInfo()
|
||||
info.filename = file
|
||||
self.song = Song(info,self.next,self.commands.printLines)
|
||||
self.next("")
|
||||
self.song = Song(info,self.next)#,self.commands.printLines)
|
||||
self.next("","")
|
||||
|
||||
# Start main loop as a thread so we can get bus calls and use command line
|
||||
gobject.threads_init()
|
||||
mainloop = gobject.MainLoop()
|
||||
thread.start_new_thread(mainloop.run,())
|
||||
#gobject.idle_add(self.markProgress,self.pbar,"progress")
|
||||
|
||||
|
||||
# Register commands for use in command line
|
||||
def registerCmnds(self):
|
||||
self.commands.register("quit",self.quit,"Exit ocarina")
|
||||
self.commands.register("exit",self.quit,"Exit ocarina")
|
||||
self.commands.register("play",self.play,"Play current song")
|
||||
self.commands.register("pause",self.pause,"Pause current song")
|
||||
self.commands.register("time",self.time,"Display running time")
|
||||
self.commands.register("info",self.info,"Display detailed info about current song")
|
||||
self.commands.register("this",self.this,"Display basic info about current song")
|
||||
self.commands.register("lib",self.scanLib,"Create a library based on the directory passed in")
|
||||
self.commands.register("next",self.next,"Advance to the next song")
|
||||
self.commands.register("random",self.random,"Toggle shuffle")
|
||||
# Call gtk main
|
||||
gtk.main()
|
||||
|
||||
# Quit program
|
||||
def quit(self,unused):
|
||||
self.commands.quit()
|
||||
self.library.dump()
|
||||
|
||||
# Make the main window
|
||||
def makeWindow(self):
|
||||
# Make window
|
||||
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||
self.window.set_title("Ocarina")
|
||||
self.window.connect("delete_event",self.delete_event)
|
||||
self.window.set_border_width(0)
|
||||
self.window.set_icon_from_file("images/ocarina.png")
|
||||
# Make a control box for buttons
|
||||
self.control = gtk.HBox(False,0)
|
||||
self.window.add(self.control)
|
||||
# Make buttons
|
||||
self.playButton = self.makeButton("playButton","images/play.png",None,self.play)
|
||||
self.pauseButton = self.makeButton("pauseButton","images/pause.png",None,self.pause)
|
||||
self.nextButton = self.makeButton("nextButton","images/next.png",None,self.next)
|
||||
self.thisButton = self.makeButton("thisButton",None,"This",self.this)
|
||||
self.infoButton = self.makeButton("infoButton",None,"Info",self.info)
|
||||
# Add buttons to window
|
||||
self.control.pack_start(self.playButton,False,False,3)
|
||||
self.control.pack_start(self.pauseButton,False,False,3)
|
||||
self.control.pack_start(self.nextButton,False,False,3)
|
||||
self.control.pack_start(self.thisButton,False,False,3)
|
||||
self.control.pack_start(self.infoButton,False,False,3)
|
||||
|
||||
self.pbar = gtk.ProgressBar()
|
||||
self.pbar.set_fraction(0)
|
||||
self.pbar.show()
|
||||
# Update the progress bar every 100 ms
|
||||
gobject.timeout_add(100,self.markProgress,self.pbar,"progress")
|
||||
self.control.pack_start(self.pbar,False,False,3)
|
||||
|
||||
self.control.show()
|
||||
self.window.show()
|
||||
|
||||
# Called before exiting
|
||||
def delete_event(self,widget,event,data=None):
|
||||
print "Quitting..."
|
||||
sys.exit(0)
|
||||
self.library.dump()
|
||||
gtk.main_quit()
|
||||
return False
|
||||
|
||||
|
||||
# Use this to make a button
|
||||
# Give the name, image path, text, and callback function
|
||||
def makeButton(self,name,path,text,func):
|
||||
button = gtk.Button()
|
||||
box = gtk.HBox(False,0)
|
||||
box.set_border_width(1)
|
||||
if path != None:
|
||||
image = gtk.Image()
|
||||
image.set_from_file(path)
|
||||
image.show()
|
||||
box.pack_start(image,False,False,0)
|
||||
if text != None:
|
||||
label = gtk.Label(text)
|
||||
label.show()
|
||||
box.pack_start(label,False,False,0)
|
||||
box.show()
|
||||
button.add(box)
|
||||
button.connect("clicked",func,name)
|
||||
button.show()
|
||||
return button
|
||||
|
||||
|
||||
# Begin playback
|
||||
def play(self,unused):
|
||||
if self.song == None:
|
||||
def play(self,widget,data):
|
||||
if self.song == None:
|
||||
return
|
||||
self.song.play()
|
||||
|
||||
# Pause music
|
||||
def pause(self,unused):
|
||||
def pause(self,widget,data):
|
||||
if self.song == None:
|
||||
return
|
||||
self.song.pause()
|
||||
|
@ -87,48 +133,49 @@ class main:
|
|||
self.commands.printLine(cur.toStr()+" / "+tot.toStr())
|
||||
|
||||
# Show detailed song info
|
||||
def info(self,unused):
|
||||
def info(self,widget,data):
|
||||
# Return if no song found
|
||||
if self.song == None:
|
||||
return
|
||||
# Return if no tags found
|
||||
if self.song.info.tags == None:
|
||||
self.commands.printLine("Could not find any tags")
|
||||
print "Could not find any tags"
|
||||
return
|
||||
for tag in self.song.info.tags.keys():
|
||||
self.commands.printLine(tag+": "+str(self.song.info.tags[tag]))
|
||||
self.commands.printLine(self.song.info.filename)
|
||||
print tag+":",self.song.info.tags[tag]
|
||||
print self.song.info.filename
|
||||
|
||||
# Show basic song info
|
||||
def this(self,unused):
|
||||
#def this(self,unused):
|
||||
def this(self,widget,data):
|
||||
# Return if no song found
|
||||
if self.song == None:
|
||||
return
|
||||
# Return if no tags found
|
||||
if self.song.info.tags == None:
|
||||
self.commands.printLine("Could not find any tags")
|
||||
print "Could not find any tags"
|
||||
return
|
||||
fields = ["title","artist","track-number","track-count","album"]
|
||||
for field in fields:
|
||||
if (field in self.song.info.tags.keys()) == True:
|
||||
self.commands.printLine(field+": "+str(self.song.info.tags[field]))
|
||||
print field+":",self.song.info.tags[field]
|
||||
|
||||
|
||||
def scanLib(self,dir):
|
||||
if dir == "":
|
||||
self.commands.printLine("Please include a library directory")
|
||||
print "Please include a library directory"
|
||||
return
|
||||
self.library.scan(dir)
|
||||
|
||||
|
||||
def next(self,unused):
|
||||
def next(self,widget,data):
|
||||
if self.song != None:
|
||||
self.song.close()
|
||||
index = self.plist.next()
|
||||
if index > -1:
|
||||
self.song = None
|
||||
info = self.library.data.files[index]
|
||||
self.song = Song(info,self.next,self.commands.printLines)
|
||||
self.song = Song(info,self.next)#self.commands.printLines)
|
||||
if index > -2:
|
||||
self.song.play()
|
||||
|
||||
|
@ -136,4 +183,11 @@ class main:
|
|||
def random(self,unused):
|
||||
self.plist.random = not self.plist.random
|
||||
|
||||
|
||||
def markProgress(self,widget,data):
|
||||
self.song.curTime()
|
||||
self.pbar.set_fraction(float(self.song.current)/float(self.song.total))
|
||||
#print float(self.song.current)/float(self.song.total)
|
||||
return True
|
||||
|
||||
if __name__=='__main__':main(sys.argv[1:])
|
||||
|
|
|
@ -2,8 +2,9 @@ import Queue
|
|||
import random
|
||||
|
||||
class Playlist:
|
||||
def __init__(self,prnt):
|
||||
self.prnt = prnt
|
||||
#def __init__(self,prnt):
|
||||
def __init__(self):
|
||||
#self.prnt = prnt
|
||||
self.list = []
|
||||
self.queue = Queue.Queue()
|
||||
self.curSong = 0
|
||||
|
|
|
@ -7,9 +7,10 @@ import gst
|
|||
from duration import Duration
|
||||
|
||||
class Song():
|
||||
def __init__(self,info,exitFunc,prnt):
|
||||
#def __init__(self,info,exitFunc,prnt):
|
||||
def __init__(self,info,exitFunc):
|
||||
self.quit=exitFunc
|
||||
self.prnt=prnt
|
||||
#self.prnt=prnt
|
||||
self.info = info
|
||||
# initialize player pipeline
|
||||
self.player = gst.Pipeline("player")
|
||||
|
@ -38,12 +39,12 @@ class Song():
|
|||
#print "End of stream"
|
||||
#self.prnt(["End of stream"])
|
||||
if self.quit != None:
|
||||
self.quit("")
|
||||
self.quit("","")
|
||||
elif t == gst.MESSAGE_ERROR:
|
||||
err, debug = message.parse_error()
|
||||
if self.prnt != None:
|
||||
self.prnt(["Error: "+ str(err) + " " +str(debug)])
|
||||
#print "Error: %s" % err, debug
|
||||
#if self.prnt != None:
|
||||
# self.prnt(["Error: "+ str(err) + " " +str(debug)])
|
||||
print "Error: %s" % err, debug
|
||||
#if self.quit != None:
|
||||
# self.quit("")
|
||||
elif t == gst.MESSAGE_TAG:
|
||||
|
@ -74,6 +75,7 @@ class Song():
|
|||
def duration(self):
|
||||
self.info.length = Duration()
|
||||
length = self.player.query_duration(self.time_format,None)[0]
|
||||
self.total = length
|
||||
self.info.length.setTime(length)
|
||||
#self.length.disp(self.prnt)
|
||||
|
||||
|
@ -81,6 +83,7 @@ class Song():
|
|||
# Print out current running time
|
||||
def curTime(self):
|
||||
length = self.player.query_position(self.time_format,None)[0]
|
||||
self.current = length
|
||||
dur = Duration()
|
||||
dur.setTime(length)
|
||||
return dur
|
||||
|
|