2009-06-05 12:51:18 -04:00
|
|
|
import gobject
|
2009-06-26 18:33:15 -04:00
|
|
|
import pango
|
2009-06-05 12:51:18 -04:00
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
2009-06-26 18:33:15 -04:00
|
|
|
import thread
|
2009-06-26 20:05:50 -04:00
|
|
|
from kiwi.ui.objectlist import Column, ObjectList
|
2009-06-05 12:51:18 -04:00
|
|
|
|
2009-06-27 01:31:07 -04:00
|
|
|
from GuiObjects.menuItem import MenuItem
|
2009-06-27 00:32:43 -04:00
|
|
|
|
2009-06-05 12:51:18 -04:00
|
|
|
|
|
|
|
class Window(gtk.Window):
|
2009-06-27 00:32:43 -04:00
|
|
|
#def __init__(self,onQuit,ops,song):
|
|
|
|
def __init__(self,onQuit,options,data):
|
2009-06-05 12:51:18 -04:00
|
|
|
gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL)
|
2009-06-27 00:32:43 -04:00
|
|
|
self.data = data
|
|
|
|
self.options = options
|
|
|
|
if self.options.verbose == True:
|
|
|
|
print "Making window!"
|
|
|
|
self.resize(self.data.size[0],self.data.size[1])
|
|
|
|
self.set_title("Ocarina")
|
|
|
|
self.connect("delete_event",onQuit)
|
|
|
|
|
|
|
|
self.mainLayout = gtk.VBox(False,0)
|
|
|
|
self.mainLayout.show()
|
2009-06-27 01:31:07 -04:00
|
|
|
self.add(self.mainLayout)
|
2009-06-27 00:32:43 -04:00
|
|
|
self.makeMenuBar()
|
|
|
|
'''
|
|
|
|
self.song = song
|
2009-06-05 12:51:18 -04:00
|
|
|
self.ops = ops
|
2009-06-14 23:54:59 -04:00
|
|
|
self.tree = None
|
2009-06-05 12:51:18 -04:00
|
|
|
self.tooltip = gtk.Tooltips()
|
|
|
|
self.tagLabels = dict()
|
|
|
|
self.set_title("Ocarina")
|
|
|
|
# Call quit function when closed
|
|
|
|
self.connect("delete_event",onQuit)
|
|
|
|
self.set_icon_from_file("images/ocarina.png")
|
|
|
|
|
|
|
|
self.mainLayout = gtk.VBox(False,0)
|
|
|
|
self.add(self.mainLayout)
|
|
|
|
self.mainLayout.show()
|
|
|
|
|
|
|
|
self.makeMenuBar()
|
|
|
|
self.makeInfoPane()
|
2009-06-14 23:54:59 -04:00
|
|
|
self.makeList()
|
2009-06-05 12:51:18 -04:00
|
|
|
self.makeControls()
|
2009-06-14 23:54:59 -04:00
|
|
|
self.maximize()
|
2009-06-27 00:32:43 -04:00
|
|
|
'''
|
2009-06-05 12:51:18 -04:00
|
|
|
self.show()
|
|
|
|
|
|
|
|
|
|
|
|
# Make initial info pane
|
|
|
|
def makeInfoPane(self):
|
2009-06-08 21:45:44 -04:00
|
|
|
self.infoFrame = gtk.Frame("Current Song:")
|
2009-06-05 12:51:18 -04:00
|
|
|
box = gtk.VBox(False,0)
|
2009-06-08 21:45:44 -04:00
|
|
|
self.infoFrame.add(box)
|
2009-06-26 18:33:15 -04:00
|
|
|
attr = pango.AttrList()
|
|
|
|
attr.insert(pango.AttrSize(12000, 0, -1))
|
|
|
|
self.tagLabels["title"] = self.makeLabel("Title: ?",box,attr)
|
|
|
|
self.tagLabels["artist"] = self.makeLabel("Artist: ?",box,attr)
|
|
|
|
self.tagLabels["album"] = self.makeLabel("Album: ?",box,attr)
|
2009-06-05 12:51:18 -04:00
|
|
|
box.show()
|
2009-06-08 21:45:44 -04:00
|
|
|
self.infoFrame.show()
|
2009-06-14 23:54:59 -04:00
|
|
|
#self.mainLayout.add(self.infoFrame)
|
|
|
|
self.mainLayout.pack_start(self.infoFrame,False,False,0)
|
2009-06-05 12:51:18 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Set up a new label, add to container
|
|
|
|
# Goes into a HBox so that it is left justified
|
2009-06-26 18:33:15 -04:00
|
|
|
def makeLabel(self,text,container,attr):
|
2009-06-05 12:51:18 -04:00
|
|
|
box = gtk.HBox(False,0)
|
|
|
|
label = gtk.Label(text)
|
2009-06-14 23:54:59 -04:00
|
|
|
s = label.get_style().copy()
|
2009-06-05 12:51:18 -04:00
|
|
|
self.tooltip.set_tip(label,text,tip_private=None)
|
2009-06-08 21:45:44 -04:00
|
|
|
#label.set_max_width_chars(35)
|
2009-06-26 18:33:15 -04:00
|
|
|
label.set_attributes(attr)
|
2009-06-05 12:51:18 -04:00
|
|
|
label.show()
|
|
|
|
box.pack_start(label,False,False,0)
|
|
|
|
box.show()
|
|
|
|
container.pack_start(box,False,False,0)
|
|
|
|
return label
|
|
|
|
|
|
|
|
|
|
|
|
# Change label info
|
|
|
|
def changeInfo(self,tags):
|
|
|
|
keys = tags.keys()
|
|
|
|
labels = self.tagLabels.keys()
|
|
|
|
for key in keys:
|
|
|
|
if (key in labels) == True:
|
|
|
|
str = key.title()+": "+tags[key]
|
|
|
|
self.tagLabels[key].set_label(str)
|
|
|
|
self.tooltip.set_tip(self.tagLabels[key],str,tip_private=None)
|
|
|
|
self.tagLabels[key].show()
|
|
|
|
|
|
|
|
|
2009-06-08 21:45:44 -04:00
|
|
|
def changeFrameTitle(self,label):
|
|
|
|
self.infoFrame.set_label(label+"Current Track:")
|
|
|
|
|
|
|
|
|
2009-06-05 12:51:18 -04:00
|
|
|
# Reset label info
|
|
|
|
def resetInfo(self):
|
|
|
|
labels = self.tagLabels.keys()
|
|
|
|
for key in labels:
|
|
|
|
self.tagLabels[key].set_label(key.title()+": ?")
|
|
|
|
self.tooltip.set_tip(self.tagLabels[key],key.title()+": ?")
|
|
|
|
self.tagLabels[key].show()
|
|
|
|
|
2009-06-14 23:54:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
def makeList(self):
|
2009-06-26 20:05:50 -04:00
|
|
|
title = Column('title')
|
|
|
|
title.expand = True
|
|
|
|
title.searchable = True
|
|
|
|
artist = Column('artist')
|
|
|
|
artist.expand = True
|
|
|
|
artist.searchable = True
|
|
|
|
album = Column('album')
|
|
|
|
album.expand = True
|
|
|
|
album.searchable = True
|
|
|
|
count = Column('count')
|
|
|
|
count.expand = True
|
|
|
|
#count.searchable = True
|
|
|
|
length = Column('length')
|
|
|
|
length.expand = True
|
|
|
|
#length.searchable = True
|
|
|
|
self.list = ObjectList([title,artist,album,count,length])
|
|
|
|
for num in self.ops.plist.list:
|
|
|
|
#print self.ops.plist.translate(num)
|
|
|
|
self.list.append(self.ops.plist.translate(num))
|
|
|
|
#self.list.append(num)
|
|
|
|
self.list.sort_by_attribute('artist')
|
|
|
|
self.list.connect("row-activated",self.ops.plist.selectSong,"clicked",self.list)
|
|
|
|
self.list.show()
|
|
|
|
self.mainLayout.add(self.list)
|
|
|
|
'''
|
2009-06-14 23:54:59 -04:00
|
|
|
# Make scrolled window, add to window
|
|
|
|
scroll = gtk.ScrolledWindow()
|
|
|
|
scroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
|
|
|
|
#self.mainLayout.pack_start(scroll,False,False,0)
|
|
|
|
self.mainLayout.add(scroll)
|
|
|
|
# Make and populate list
|
|
|
|
self.list = gtk.ListStore(int,str,str,str,int)
|
|
|
|
for num in self.ops.plist.list:
|
|
|
|
self.list.append(self.ops.plist.translate(num))
|
|
|
|
# Make treeview from list
|
|
|
|
if self.tree:
|
|
|
|
self.tree = None
|
|
|
|
self.tree = gtk.TreeView(self.list)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
cols = ["Id","Title","Artist","Album","Count"]
|
|
|
|
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)
|
|
|
|
self.tree.append_column(col)
|
|
|
|
self.tree.connect("row-activated",self.ops.plist.selectSong,"clicked",self.list)
|
2009-06-26 18:33:15 -04:00
|
|
|
self.tree.connect("button_press_event",self.ops.click,"clicked",self.list,self.tree.get_selection())
|
2009-06-14 23:54:59 -04:00
|
|
|
self.tree.set_grid_lines(True)
|
|
|
|
scroll.add(self.tree)
|
|
|
|
self.tree.columns_autosize()
|
|
|
|
self.tree.show()
|
|
|
|
scroll.show()
|
|
|
|
#self.gotoCurSong()
|
2009-06-26 20:05:50 -04:00
|
|
|
'''
|
2009-06-14 23:54:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
def gotoCurSong(self):
|
2009-06-26 20:05:50 -04:00
|
|
|
#return
|
2009-06-26 18:33:15 -04:00
|
|
|
if len(self.list) == 0:
|
|
|
|
return
|
|
|
|
#print self.list[0][0]
|
|
|
|
#print len(self.list)
|
2009-06-14 23:54:59 -04:00
|
|
|
selrow = 0
|
|
|
|
row = 0
|
|
|
|
for i in range(len(self.list)):
|
|
|
|
#print i
|
2009-06-26 20:05:50 -04:00
|
|
|
if self.list[i].id == self.ops.plist.curSong:
|
2009-06-14 23:54:59 -04:00
|
|
|
if i > 10:
|
|
|
|
selrow = i - 10
|
|
|
|
row = i
|
|
|
|
break
|
2009-06-26 20:05:50 -04:00
|
|
|
self.list.select(self.list[row],True)
|
2009-06-14 23:54:59 -04:00
|
|
|
#selrow = self.ops.plist.curSong - 10
|
|
|
|
#if selrow < 0:
|
|
|
|
# selrow = 0
|
2009-06-26 18:33:15 -04:00
|
|
|
#print selrow,row
|
2009-06-26 20:05:50 -04:00
|
|
|
#self.tree.scroll_to_cell(selrow,None,True,0,0)
|
|
|
|
#treesel = self.tree.get_selection()
|
|
|
|
#treesel.select_path(row)
|
2009-06-14 23:54:59 -04:00
|
|
|
|
|
|
|
|
2009-06-05 12:51:18 -04:00
|
|
|
# Use to make play/pause/next/etc buttons
|
|
|
|
def makeControls(self):
|
|
|
|
#controls = gtk.VBox(False,0)
|
2009-06-14 23:54:59 -04:00
|
|
|
row = gtk.HBox(False,0)
|
2009-06-05 12:51:18 -04:00
|
|
|
topRow = gtk.HBox(False,0)
|
|
|
|
# Make top row buttons
|
2009-06-27 00:32:43 -04:00
|
|
|
#self.makeButton("play","images/play.png",None,self.ops.play,topRow)
|
|
|
|
self.makeButton("play","images/play.png",None,self.song.play,topRow)
|
|
|
|
|
|
|
|
#self.makeButton("pause","images/pause.png",None,self.ops.pause,topRow)
|
|
|
|
self.makeButton("pause","images/pause.png",None,self.song.pause,topRow)
|
|
|
|
|
2009-06-08 21:45:44 -04:00
|
|
|
self.makeButton("stop","images/stop.png",None,self.ops.stop,topRow)
|
2009-06-05 12:51:18 -04:00
|
|
|
self.makeButton("next","images/next.png",None,self.ops.next,topRow)
|
|
|
|
self.makeButton("info",None,"Info",self.ops.info,topRow)
|
2009-06-14 23:54:59 -04:00
|
|
|
#self.makeButton("plist",None,"Plist",self.ops.plist.showWindow,topRow)
|
2009-06-05 12:51:18 -04:00
|
|
|
|
|
|
|
test = gtk.VBox(False,0)
|
|
|
|
self.makeCheck("Random",self.ops.random,self.ops.plist.random,True,topRow)
|
|
|
|
topRow.show()
|
2009-06-14 23:54:59 -04:00
|
|
|
row.pack_end(topRow,False,False,0)
|
|
|
|
row.show()
|
|
|
|
#self.mainLayout.pack_start(topRow,False,False,0)
|
|
|
|
self.mainLayout.pack_start(row,False,False,0)
|
2009-06-05 12:51:18 -04:00
|
|
|
# Make progress bar, add below top row
|
|
|
|
pbar = gtk.ProgressBar()
|
|
|
|
pbar.set_fraction(0)
|
|
|
|
gobject.timeout_add(1000,self.ops.markProgress,pbar,"progress")
|
|
|
|
pbar.show()
|
|
|
|
self.mainLayout.pack_start(pbar,False,False,0)
|
|
|
|
# Show completed controls
|
|
|
|
#controls.show()
|
|
|
|
#self.add(controls)
|
|
|
|
|
|
|
|
|
|
|
|
# Make buttons and add to container
|
|
|
|
# Path is to an image
|
|
|
|
# Text is label text
|
|
|
|
# Func is callback function
|
|
|
|
def makeButton(self,name,path,text,func,container):
|
|
|
|
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()
|
|
|
|
container.pack_start(button,False,False,0)
|
|
|
|
return button
|
|
|
|
|
|
|
|
|
|
|
|
# Make a checkbox and add to container
|
|
|
|
# Active is variable to check, status is value it has to mark as active
|
|
|
|
def makeCheck(self,name,func,active,status,container):
|
|
|
|
check = gtk.CheckButton(label=name)
|
|
|
|
if active == status:
|
|
|
|
check.set_active(1)
|
|
|
|
check.connect("toggled",func,name)
|
|
|
|
check.show()
|
|
|
|
container.pack_start(check,False,False,0)
|
|
|
|
return check
|
|
|
|
|
|
|
|
|
|
|
|
def makeMenuBar(self):
|
2009-06-27 00:32:43 -04:00
|
|
|
# Make a menu bar
|
|
|
|
bar = gtk.MenuBar()
|
|
|
|
# This is the dropdown selections
|
|
|
|
# Make a new library option
|
2009-06-27 01:31:07 -04:00
|
|
|
newLib = MenuItem("New Library",self.selectDir,None,self.data.library.scan,None)
|
|
|
|
library = MenuItem("Library",None,None,None,[newLib])
|
2009-06-27 00:32:43 -04:00
|
|
|
bar.append(library)
|
|
|
|
|
2009-06-27 01:31:07 -04:00
|
|
|
# Replace first 'None' with after track functions
|
|
|
|
pafter = MenuItem("Pause After Current Track",None,"pafter",self.changeFrameTitle,None)
|
|
|
|
qafter = MenuItem("Quit After Current Track",None,"qafter",self.changeFrameTitle,None)
|
|
|
|
playback = MenuItem("Playback",None,None,None,[pafter,qafter])
|
2009-06-05 12:51:18 -04:00
|
|
|
bar.append(playback)
|
2009-06-27 01:31:07 -04:00
|
|
|
|
2009-06-05 12:51:18 -04:00
|
|
|
bar.show()
|
|
|
|
self.mainLayout.pack_start(bar,False,False,0)
|
|
|
|
|
|
|
|
|
2009-06-27 01:31:07 -04:00
|
|
|
def selectDir(self,widgit,data,func):
|
2009-06-05 12:51:18 -04:00
|
|
|
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 = dirsel.run()
|
2009-06-14 23:54:59 -04:00
|
|
|
file = ""
|
2009-06-08 21:45:44 -04:00
|
|
|
#dirsel = None
|
2009-06-05 12:51:18 -04:00
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
#print dirsel.get_filename(),'selected'
|
2009-06-08 21:45:44 -04:00
|
|
|
#dirsel.hide()
|
|
|
|
file = dirsel.get_filename()
|
2009-06-14 23:54:59 -04:00
|
|
|
#dirsel.hide()
|
|
|
|
#dirsel = None
|
|
|
|
#func(file)
|
|
|
|
#else:
|
|
|
|
dirsel.hide()
|
|
|
|
dirsel.destroy()
|
2009-06-26 18:33:15 -04:00
|
|
|
dirsel = None
|
|
|
|
thread.start_new_thread(func,("name",file))
|