157 lines
4.3 KiB
Python
157 lines
4.3 KiB
Python
import gobject
|
|
import os
|
|
import sys
|
|
import thread
|
|
|
|
import pygtk
|
|
pygtk.require('2.0')
|
|
import gtk
|
|
|
|
from song import Song
|
|
from duration import Duration
|
|
from library import Library
|
|
from operations import Operations
|
|
from playlist import Playlist
|
|
from songInfo import SongInfo
|
|
|
|
#gtk.gdk.threads_init()
|
|
gobject.threads_init()
|
|
|
|
|
|
class main:
|
|
def __init__(self,argv):
|
|
self.ops = Operations()
|
|
self.makeWindow()
|
|
|
|
self.library = Library()
|
|
self.plist = Playlist()
|
|
self.plist.insert(self.library.nonBanned())
|
|
self.ops.plist = self.plist
|
|
self.ops.library = self.library
|
|
|
|
#self.ops.plist.random = True
|
|
if self.ops.plist.random==True:
|
|
# Toggle random status because set_active toggles it back
|
|
self.ops.random(None,None)
|
|
self.randomButton.set_active(1)
|
|
|
|
song = None
|
|
# If we were given a song as input, check that it exists and begin playback
|
|
if len(argv) > 0:
|
|
split = argv[0].split(self.library.data.path)
|
|
if len(split) > 0:
|
|
index = self.library.has(split[len(split)-1])
|
|
#if index != -1:
|
|
#info = self.library.data.files[index]
|
|
self.plist.queueSong(index)
|
|
if index==-1:
|
|
file = os.path.expanduser(argv[0])
|
|
if os.path.exists(file):
|
|
info = SongInfo()
|
|
info.filename = file
|
|
song = Song(info,self.next)#,self.commands.printLines)
|
|
self.ops.song = song
|
|
self.ops.next("","")
|
|
|
|
#gobject.idle_add(self.markProgress,self.pbar,"progress")
|
|
|
|
# Call gtk main
|
|
gtk.main()
|
|
|
|
|
|
# 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.VBox(False,0)
|
|
|
|
self.infoFrame = gtk.Frame("Song Info Goes Here")
|
|
infoLabel = gtk.Label("test")
|
|
self.infoFrame.add(infoLabel)
|
|
infoLabel.show()
|
|
self.infoFrame.show()
|
|
|
|
|
|
self.inside = gtk.HBox(False,0)
|
|
self.window.add(self.control)
|
|
# Make buttons
|
|
self.randomButton = gtk.CheckButton(label="Random")
|
|
self.randomButton.connect("toggled",self.ops.random,"randomButton")
|
|
# Start with random enabled
|
|
self.randomButton.show()
|
|
self.playButton = self.makeButton("playButton","images/play.png",None,self.ops.play)
|
|
self.pauseButton = self.makeButton("pauseButton","images/pause.png",None,self.ops.pause)
|
|
self.nextButton = self.makeButton("nextButton","images/next.png",None,self.ops.next)
|
|
self.thisButton = self.makeButton("thisButton",None,"This",self.ops.this)
|
|
self.infoButton = self.makeButton("infoButton",None,"Info",self.ops.info)
|
|
# Add buttons to window
|
|
self.inside.pack_start(self.playButton,False,False,0)
|
|
self.inside.pack_start(self.pauseButton,False,False,0)
|
|
self.inside.pack_start(self.nextButton,False,False,0)
|
|
self.inside.pack_start(self.thisButton,False,False,0)
|
|
self.inside.pack_start(self.infoButton,False,False,0)
|
|
self.inside.pack_start(self.randomButton,False,False,0)
|
|
self.inside.show()
|
|
# Top row
|
|
self.control.pack_start(self.infoFrame,False,False,0)
|
|
self.control.pack_start(self.inside,False,False,0)
|
|
self.pbar = gtk.ProgressBar()
|
|
self.pbar.set_fraction(0)
|
|
self.pbar.show()
|
|
# Update the progress bar every 100 ms
|
|
gobject.timeout_add(100,self.ops.markProgress,self.pbar,"progress")
|
|
self.control.pack_start(self.pbar,False,False,0)
|
|
|
|
# Tray
|
|
#self.statusIcon = gtk.StatusIcon()
|
|
#self.statusIcon.set_from_file("images/ocarina.png")
|
|
#self.statusIcon.set_tooltip("Ocarina")
|
|
#self.statusIcon.show()
|
|
|
|
self.control.show()
|
|
self.window.show()
|
|
|
|
# Called before exiting
|
|
def delete_event(self,widget,event,data=None):
|
|
print "Quitting..."
|
|
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(0)
|
|
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
|
|
|
|
|
|
def scanLib(self,dir):
|
|
if dir == "":
|
|
print "Please include a library directory"
|
|
return
|
|
self.library.scan(dir)
|
|
|
|
|
|
if __name__=='__main__':main(sys.argv[1:])
|