Can choose files, can stop (pause + seek to beginning)
This commit is contained in:
parent
36f95d7736
commit
a9a9c3e642
|
@ -22,19 +22,45 @@ player.add(volume)
|
|||
volume.set_property("volume", 1.0)
|
||||
|
||||
|
||||
|
||||
def getstate():
|
||||
global player
|
||||
state = player.get_state()[1]
|
||||
write("Gstreamer state: "+str(state), 3)
|
||||
return player.get_state()[1]
|
||||
|
||||
|
||||
def play():
|
||||
global player
|
||||
player.set_state(gst.STATE_PLAYING)
|
||||
if getstate() != gst.STATE_PLAYING:
|
||||
ocarina.events.stop("ocarina-play")
|
||||
|
||||
|
||||
def pause():
|
||||
global player
|
||||
player.set_state(gst.STATE_PAUSED)
|
||||
if getstate() != gst.STATE_PAUSED:
|
||||
ocarina.events.stop("ocarina-pause")
|
||||
|
||||
|
||||
def load(song):
|
||||
song = path.expand(song)
|
||||
if path.exists(song) == False:
|
||||
write("Path does not exist: " + song)
|
||||
return
|
||||
|
||||
curstate = getstate()
|
||||
pause()
|
||||
write("Loading file: " + song, 1)
|
||||
global player
|
||||
player.set_state(gst.STATE_NULL)
|
||||
player.set_property("uri", "file://" + song)
|
||||
if ocarina.vars["$playonload"] == True:
|
||||
player.set_state(gst.STATE_PLAYING)
|
||||
if ocarina.vars["$playonload"]==True or curstate==gst.STATE_PLAYING:
|
||||
play()
|
||||
else:
|
||||
player.set_state(gst.STATE_PAUSED)
|
||||
pause()
|
||||
#player.set_state(gst.STATE_PAUSED)
|
||||
|
||||
|
||||
def uninit():
|
||||
|
@ -51,25 +77,6 @@ def init():
|
|||
load(song)
|
||||
|
||||
|
||||
def getstate():
|
||||
global player
|
||||
state = player.get_state()[1]
|
||||
write("Gstreamer state: "+str(state), 1)
|
||||
return player.get_state()[1]
|
||||
|
||||
|
||||
def play():
|
||||
global player
|
||||
player.set_state(gst.STATE_PLAYING)
|
||||
if getstate() != gst.STATE_PLAYING:
|
||||
ocarina.events.stop("ocarina-play")
|
||||
|
||||
|
||||
def pause():
|
||||
global player
|
||||
player.set_state(gst.STATE_PAUSED)
|
||||
if getstate() != gst.STATE_PAUSED:
|
||||
ocarina.events.stop("ocarina-pause")
|
||||
|
||||
|
||||
def onMessage(bus, message):
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#! /usr/bin/python
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Mar 18, 2010 12:16:07 AM$"
|
||||
|
||||
import ocarina
|
||||
|
||||
from ct import plugin
|
||||
from ct.message import write
|
||||
from ct import cmd
|
||||
import gstreamer
|
||||
|
||||
class Plugin(plugin.Plugin):
|
||||
def __init__(self):
|
||||
plugin.Plugin.__init__(self)
|
||||
|
||||
|
||||
def run(self,args):
|
||||
cmd.run("pause")
|
||||
gstreamer.seek(0)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
__author__="bjschuma"
|
||||
__date__ ="$Mar 14, 2010 9:53:12 PM$"
|
||||
|
||||
__all__ = ["times", "xm"]
|
||||
__all__ = ["db", "sql", "times", "xm"]
|
|
@ -0,0 +1,150 @@
|
|||
#! /usr/bin/python
|
||||
|
||||
# To change this template, choose Tools | Templates
|
||||
# and open the template in the editor.
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Jan 27, 2010 6:21:27 PM$"
|
||||
|
||||
|
||||
from bt.message import write
|
||||
from sqlite3 import *
|
||||
from bt import sql
|
||||
import settings
|
||||
|
||||
|
||||
def init():
|
||||
if sql.dbexists() == True:
|
||||
return
|
||||
|
||||
table = sql.CTable("library")
|
||||
table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT")
|
||||
table.addcol("name","TEXT","UNIQUE")
|
||||
table.addcol("path","TEXT","UNIQUE")
|
||||
table.execute()
|
||||
|
||||
table = sql.CTable("artist")
|
||||
table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT")
|
||||
table.addcol("name","TEXT","UNIQUE")
|
||||
table.execute()
|
||||
|
||||
table = sql.CTable("album")
|
||||
table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT")
|
||||
table.addcol("name","TEXT","UNIQUE")
|
||||
table.execute()
|
||||
|
||||
table = sql.CTable("track")
|
||||
table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT")
|
||||
table.addcol("artist","INTEGER")
|
||||
table.addcol("album","INTEGER")
|
||||
table.addcol("count","INTEGER")
|
||||
table.addcol("length","INTEGER")
|
||||
table.addcol("name","TEXT")
|
||||
table.addcol("path","TEXT","UNIQUE")
|
||||
table.execute()
|
||||
|
||||
table = sql.CTable("libtrack")
|
||||
table.addcol("library","INTEGER")
|
||||
table.addcol("track","INTEGER")
|
||||
table.execute()
|
||||
|
||||
|
||||
|
||||
def newlib(name,path):
|
||||
try:
|
||||
ins = sql.Insert('library',[None,name,path])
|
||||
ins.execute()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def rmtrk(trid):
|
||||
# Get the artist and album of the track
|
||||
sel = sql.Select("artist,album","track","id="+str(trid))
|
||||
(arid,alid) = sel.execute().fetchone()
|
||||
|
||||
rm = sql.Remove("track","id="+str(trid))
|
||||
rm.execute()
|
||||
|
||||
# Remove artist if no other tracks are using this artist
|
||||
sel = sql.Select("count(*)","track","artist="+str(arid))
|
||||
count = sel.execute().fetchone()[0]
|
||||
if count == 0:
|
||||
rm = sql.Remove("artist","id="+str(arid))
|
||||
rm.execute()
|
||||
|
||||
# Remove album if no other tracks are using this album
|
||||
sel = sql.Select("count(*)","track","album="+str(alid))
|
||||
count = sel.execute().fetchone()[0]
|
||||
if count == 0:
|
||||
rm = sql.Remove("album","id="+str(alid))
|
||||
rm.execute()
|
||||
|
||||
|
||||
def rmlib(name):
|
||||
sel = sql.Select("id,name","library","name='"+name+"'")
|
||||
result = sel.execute().fetchone()
|
||||
if result == []:
|
||||
return
|
||||
libid = result[0]
|
||||
name = result[1]
|
||||
|
||||
sel = sql.Select("track","libtrack","library="+str(libid))
|
||||
result = sel.execute().fetchall()
|
||||
|
||||
for track in result:
|
||||
where = "track="+str(track[0])+" AND library!="+str(libid)
|
||||
sel = sql.Select("track,library","libtrack",where )
|
||||
r = sel.execute().fetchall()
|
||||
# If track is not in any other library, it can be removed
|
||||
if r == []:
|
||||
rmtrk(track[0])
|
||||
|
||||
rm = sql.Remove("library","name='"+name+"'")
|
||||
rm.execute()
|
||||
|
||||
rm = sql.Remove("libtrack","library="+str(libid))
|
||||
rm.execute()
|
||||
write("Removed library: "+name)
|
||||
|
||||
|
||||
def libid(libname):
|
||||
sel = sql.Select("id","library","name='"+libname+"'")
|
||||
result = sel.execute().fetchone()
|
||||
if result == None:
|
||||
return None
|
||||
return result[0]
|
||||
|
||||
|
||||
def countlib(libid):
|
||||
lib = str( libid )
|
||||
sel = sql.Select("count(*)","libtrack","library="+lib)
|
||||
count = sel.execute().fetchone()[0]
|
||||
return count
|
||||
|
||||
|
||||
def listlib():
|
||||
sel = sql.Select("*","library")
|
||||
result = sel.execute().fetchall()
|
||||
id = settings.get("curlib")
|
||||
curname = ""
|
||||
write("Id Name Count Path")
|
||||
write("---------------------------")
|
||||
for row in result:
|
||||
if row[0] == id:
|
||||
curname = row[1]
|
||||
count = str( countlib(row[0]) )
|
||||
write( str(row[0]) + " " +
|
||||
row[1] + " " + count + " " + row[2] )
|
||||
write("Current: "+curname)
|
||||
|
||||
|
||||
def getpath(dbid):
|
||||
curlib = str( settings.get("curlib") )
|
||||
|
||||
selr = sql.Select("path","library","id="+curlib)
|
||||
root = selr.execute().fetchone()[0]
|
||||
|
||||
selt = sql.Select("path","track","id="+str(dbid))
|
||||
track = selt.execute().fetchone()[0]
|
||||
return root+track
|
|
@ -0,0 +1,136 @@
|
|||
import os.path
|
||||
#! /usr/bin/python
|
||||
|
||||
# To change this template, choose Tools | Templates
|
||||
# and open the template in the editor.
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Jan 23, 2010 8:40:03 PM$"
|
||||
|
||||
import sqlite3
|
||||
import settings
|
||||
from ct.path import *
|
||||
import ocarina
|
||||
|
||||
|
||||
def getdb():
|
||||
return join(ocarina.vars["$ocarina"]+"ocarina.db")
|
||||
|
||||
|
||||
def dbexists():
|
||||
return exists(getdb())
|
||||
|
||||
|
||||
def connect():
|
||||
path = getdb()
|
||||
con = sqlite3.connect(path)
|
||||
con.text_factory = str
|
||||
return con
|
||||
|
||||
|
||||
def disconnect(con):
|
||||
con.commit()
|
||||
con.close()
|
||||
|
||||
|
||||
|
||||
|
||||
class Statement():
|
||||
def __init__(self):
|
||||
self.statement = ""
|
||||
self.con = connect()
|
||||
self.commit = True
|
||||
|
||||
def __del__(self):
|
||||
self.con.close()
|
||||
|
||||
def commitdb(self):
|
||||
self.con.commit()
|
||||
|
||||
def execute(self,vals=None):
|
||||
if self.statement == "":
|
||||
return
|
||||
if vals==None:
|
||||
result = self.con.execute(self.statement)
|
||||
else:
|
||||
result = self.con.execute(self.statement,vals)
|
||||
|
||||
if self.commit == True:
|
||||
self.commitdb()
|
||||
return result
|
||||
|
||||
|
||||
|
||||
|
||||
class CTable(Statement):
|
||||
def __init__(self,name):
|
||||
Statement.__init__(self)
|
||||
self.name = name
|
||||
self.cols = []
|
||||
|
||||
def addcol(self,name,type,params=""):
|
||||
self.cols += [(name,type,params)]
|
||||
|
||||
def execute(self):
|
||||
self.statement = "CREATE TABLE "+self.name + " ("
|
||||
for index,col in enumerate(self.cols):
|
||||
if not index == 0:
|
||||
self.statement += ", "
|
||||
self.statement += " " + col[0] + " " + col[1] + " " + col[2]
|
||||
self.statement += " );"
|
||||
return Statement.execute(self)
|
||||
|
||||
|
||||
|
||||
|
||||
class Select(Statement):
|
||||
def __init__(self,What,From,Where=None):
|
||||
Statement.__init__(self)
|
||||
self.commit = False
|
||||
self.What = What
|
||||
self.From = From
|
||||
self.Where = Where
|
||||
|
||||
def execute(self):
|
||||
self.statement = "SELECT " + self.What
|
||||
self.statement += " FROM " + self.From
|
||||
if not self.Where==None:
|
||||
self.statement += " WHERE " + self.Where
|
||||
return Statement.execute(self)
|
||||
|
||||
|
||||
|
||||
|
||||
class Insert(Statement):
|
||||
def __init__(self,table,values=[]):
|
||||
Statement.__init__(self)
|
||||
self.table = table
|
||||
self.values = values
|
||||
|
||||
def addval(self,val):
|
||||
self.values += [val]
|
||||
|
||||
def execute(self):
|
||||
self.statement = "INSERT INTO "+ self.table + " VALUES("
|
||||
qs = ""
|
||||
for i in range(len(self.values)):
|
||||
if not i == 0:
|
||||
qs+=","
|
||||
qs+="?"
|
||||
#self.values[i] = str(self.values[i])
|
||||
self.statement+=qs + ")"
|
||||
Statement.execute(self, self.values)
|
||||
|
||||
|
||||
|
||||
class Remove(Statement):
|
||||
def __init__(self,table,where=""):
|
||||
Statement.__init__(self)
|
||||
self.table = table
|
||||
self.where = where
|
||||
|
||||
def execute(self):
|
||||
self.statement = "DELETE FROM " + self.table
|
||||
if not self.where=="":
|
||||
self.statement += " WHERE "+self.where
|
||||
Statement.execute(self)
|
|
@ -21,6 +21,17 @@ global buildFunc
|
|||
buildFunc = None
|
||||
|
||||
|
||||
def buildMenu(node,menu):
|
||||
global buildFunc
|
||||
for child in xm.children(node):
|
||||
item = buildFunc(child)
|
||||
if item!=None:
|
||||
if node.nodeName == "menubar":
|
||||
menu.append(item)
|
||||
elif node.nodeName == "menuitem":
|
||||
menu.addSubMenu(item)
|
||||
|
||||
|
||||
def setPacking(old,newVals):
|
||||
for field in newVals:
|
||||
if (field=="expand") or (field=="fill"):
|
||||
|
@ -70,6 +81,8 @@ def build(node):
|
|||
part = parts[tag](xm.attributes(node))
|
||||
if (tag=="hbox") or (tag=="vbox") or (tag=="window"):
|
||||
fill(node,part)
|
||||
elif (tag=="menubar") or (tag=="menuitem"):
|
||||
buildMenu(node,part)
|
||||
return part
|
||||
|
||||
|
||||
|
|
|
@ -2,4 +2,5 @@ __author__="bjschuma"
|
|||
__date__ ="$Mar 14, 2010 10:21:40 PM$"
|
||||
|
||||
|
||||
__all__ = ["box", "button", "label", "playButton", "progbar", "songInfo", "window"]
|
||||
__all__ = ["box", "button", "label", "label", "menu",
|
||||
"progbar", "songInfo", "window"]
|
|
@ -5,6 +5,7 @@ __date__ ="$Mar 14, 2010 11:13:03 PM$"
|
|||
|
||||
import gtk
|
||||
import ocarina
|
||||
import guibuilder
|
||||
from ct import cmd
|
||||
|
||||
class Button(gtk.Button):
|
||||
|
@ -42,8 +43,67 @@ class Button(gtk.Button):
|
|||
cmd.run(self.command)
|
||||
|
||||
|
||||
|
||||
class ButtonImage(gtk.Button):
|
||||
def __init__(self,attrs,stock,cmd=""):
|
||||
gtk.Button.__init__(self)
|
||||
size = gtk.ICON_SIZE_BUTTON
|
||||
show = None
|
||||
hide = None
|
||||
shownow = True
|
||||
self.cmd = ""
|
||||
for a in attrs:
|
||||
if a=="size":
|
||||
if attrs[a] == "large":
|
||||
size = gtk.ICON_SIZE_DIALOG
|
||||
elif a=="show":
|
||||
show = attrs[a]
|
||||
elif a=="hide":
|
||||
hide = attrs[a]
|
||||
elif a=="shownow" and attrs[a]=="false":
|
||||
shownow = False
|
||||
elif a=="cmd":
|
||||
self.cmd = attrs[a]
|
||||
|
||||
img = gtk.image_new_from_stock(stock,size)
|
||||
img.show()
|
||||
self.add( img )
|
||||
|
||||
if shownow==True:
|
||||
self.show()
|
||||
|
||||
if hide!=None:
|
||||
ocarina.events.invite(hide, self.hide)
|
||||
if show!=None:
|
||||
ocarina.events.invite(show, self.show)
|
||||
self.connect("clicked",self.onclick)
|
||||
|
||||
def onclick(self,button):
|
||||
cmd.run(self.cmd)
|
||||
|
||||
|
||||
|
||||
def make_button(attrs):return Button(attrs)
|
||||
|
||||
def make_buttonplay(attrs):
|
||||
attrs["show"] = "ocarina-pause"
|
||||
attrs["hide"] = "ocarina-play"
|
||||
attrs["cmd"] = "play"
|
||||
return ButtonImage(attrs,gtk.STOCK_MEDIA_PLAY)
|
||||
|
||||
import guibuilder
|
||||
guibuilder.parts["button"] = make_button
|
||||
def make_buttonpause(attrs):
|
||||
attrs["show"] = "ocarina-play"
|
||||
attrs["hide"] = "ocarina-pause"
|
||||
attrs["cmd"] = "pause"
|
||||
attrs["shownow"] = "false"
|
||||
return ButtonImage(attrs,gtk.STOCK_MEDIA_PAUSE)
|
||||
|
||||
def make_buttonstop(attrs):
|
||||
attrs["cmd"] = "stop"
|
||||
return ButtonImage(attrs,gtk.STOCK_MEDIA_STOP)
|
||||
|
||||
|
||||
guibuilder.parts["button"] = make_button
|
||||
guibuilder.parts["buttonplay"] = make_buttonplay
|
||||
guibuilder.parts["buttonpause"] = make_buttonpause
|
||||
guibuilder.parts["buttonstop"] = make_buttonstop
|
|
@ -0,0 +1,123 @@
|
|||
#! /usr/bin/python
|
||||
|
||||
# To change this template, choose Tools | Templates
|
||||
# and open the template in the editor.
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Jan 14, 2010 10:39:29 PM$"
|
||||
|
||||
import gtk
|
||||
|
||||
import ocarina
|
||||
import guibuilder
|
||||
from ct import cmd
|
||||
|
||||
|
||||
class MenuBar(gtk.MenuBar):
|
||||
def __init__(self):
|
||||
gtk.MenuBar.__init__(self)
|
||||
self.show()
|
||||
|
||||
|
||||
class MenuItem(gtk.MenuItem):
|
||||
def __init__(self,attrs=None):
|
||||
name = "New Menu"
|
||||
cmd = ""
|
||||
for a in attrs:
|
||||
if a == "name":
|
||||
name = attrs[a]
|
||||
elif a== "cmd":
|
||||
cmd = attrs[a]
|
||||
|
||||
gtk.MenuItem.__init__(self,name)
|
||||
self.show()
|
||||
self.menu = None
|
||||
self.cmd = cmd
|
||||
self.connect("activate",self.clicked)
|
||||
|
||||
|
||||
def addSubMenu(self,submenu):
|
||||
if self.menu == None:
|
||||
self.menu = gtk.Menu()
|
||||
self.set_submenu(self.menu)
|
||||
self.menu.append(submenu)
|
||||
|
||||
|
||||
def clicked(self,a):
|
||||
if self.cmd != "":
|
||||
print self.cmd
|
||||
cmd.run(self.cmd)
|
||||
|
||||
|
||||
|
||||
class MenuPlay(gtk.ImageMenuItem):
|
||||
def __init__(self):
|
||||
gtk.ImageMenuItem.__init__(self,gtk.STOCK_MEDIA_PLAY)
|
||||
ocarina.events.invite("ocarina-play",self.hide)
|
||||
ocarina.events.invite("ocarina-pause",self.show)
|
||||
self.connect("activate",self.clicked)
|
||||
self.show()
|
||||
|
||||
def clicked(self,item):
|
||||
cmd.run("play")
|
||||
|
||||
|
||||
|
||||
class MenuPause(gtk.ImageMenuItem):
|
||||
def __init__(self):
|
||||
gtk.ImageMenuItem.__init__(self,gtk.STOCK_MEDIA_PAUSE)
|
||||
ocarina.events.invite("ocarina-pause",self.hide)
|
||||
ocarina.events.invite("ocarina-play",self.show)
|
||||
self.connect("activate",self.clicked)
|
||||
|
||||
def clicked(self,item):
|
||||
cmd.run("pause")
|
||||
|
||||
|
||||
|
||||
class MenuStop(gtk.ImageMenuItem):
|
||||
def __init__(self):
|
||||
gtk.ImageMenuItem.__init__(self,gtk.STOCK_MEDIA_STOP)
|
||||
self.connect("activate",self.clicked)
|
||||
self.show()
|
||||
|
||||
def clicked(self,item):
|
||||
cmd.run("stop")
|
||||
|
||||
|
||||
|
||||
class MenuSongSelect(gtk.MenuItem):
|
||||
def __init__(self):
|
||||
gtk.MenuItem.__init__(self,"Play File")
|
||||
self.connect("activate",self.onclick)
|
||||
self.show()
|
||||
|
||||
def onclick(self,menu):
|
||||
buttons = (gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)
|
||||
chooser = gtk.FileChooserDialog("Select a song",None,action=gtk.FILE_CHOOSER_ACTION_OPEN,buttons=buttons)
|
||||
response = chooser.run()
|
||||
chooser.hide()
|
||||
file = ""
|
||||
if response == gtk.RESPONSE_OK:
|
||||
file = chooser.get_filename()
|
||||
#chooser.hide()
|
||||
if response != gtk.RESPONSE_OK:
|
||||
return
|
||||
|
||||
cmd.run("load "+file)
|
||||
|
||||
|
||||
|
||||
def make_menubar(attrs=None):return MenuBar()
|
||||
def make_menuitem(attrs=None):return MenuItem(attrs)
|
||||
def make_menuplay(attrs=None):return MenuPlay()
|
||||
def make_menupause(attrs=None):return MenuPause()
|
||||
def make_menustop(attrs=None):return MenuStop()
|
||||
def make_menusongsel(attrs=None):return MenuSongSelect()
|
||||
|
||||
guibuilder.parts["menubar"] = make_menubar
|
||||
guibuilder.parts["menuitem"] = make_menuitem
|
||||
guibuilder.parts["menuplay"] = make_menuplay
|
||||
guibuilder.parts["menupause"] = make_menupause
|
||||
guibuilder.parts["menustop"] = make_menustop
|
||||
guibuilder.parts["menusongsel"] = make_menusongsel
|
|
@ -1,54 +0,0 @@
|
|||
#! /usr/bin/python
|
||||
|
||||
# To change this template, choose Tools | Templates
|
||||
# and open the template in the editor.
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Mar 15, 2010 11:47:24 PM$"
|
||||
|
||||
|
||||
import guibuilder
|
||||
import ocarina
|
||||
import gtk
|
||||
from ct import cmd
|
||||
|
||||
class PlayButton(gtk.HBox):
|
||||
def __init__(self,attrs):
|
||||
gtk.HBox.__init__(self,False,0)
|
||||
size = gtk.ICON_SIZE_BUTTON
|
||||
for a in attrs:
|
||||
if a=="size":
|
||||
if attrs[a] == "large":
|
||||
size = gtk.ICON_SIZE_DIALOG
|
||||
|
||||
self.play = self.getButton(gtk.STOCK_MEDIA_PLAY, size)
|
||||
self.pause = self.getButton(gtk.STOCK_MEDIA_PAUSE, size)
|
||||
|
||||
self.play.show()
|
||||
self.show()
|
||||
|
||||
ocarina.events.invite("ocarina-play", self.play.hide)
|
||||
ocarina.events.invite("ocarina-play", self.pause.show)
|
||||
ocarina.events.invite("ocarina-pause",self.play.show)
|
||||
ocarina.events.invite("ocarina-pause",self.pause.hide)
|
||||
|
||||
|
||||
def getButton(self,stock,size):
|
||||
img = gtk.image_new_from_stock(stock,size)
|
||||
button = gtk.Button()
|
||||
button.add(img)
|
||||
img.show()
|
||||
button.connect("clicked",self.onclick)
|
||||
self.pack_start(button, False)
|
||||
return button
|
||||
|
||||
|
||||
def onclick(self,button):
|
||||
if button == self.play:
|
||||
cmd.run("play")
|
||||
else:
|
||||
cmd.run("pause")
|
||||
|
||||
|
||||
def make_playbutton(attrs=None):return PlayButton(attrs)
|
||||
guibuilder.parts["playbutton"] = make_playbutton
|
|
@ -0,0 +1,136 @@
|
|||
import os.path
|
||||
#! /usr/bin/python
|
||||
|
||||
# To change this template, choose Tools | Templates
|
||||
# and open the template in the editor.
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Jan 23, 2010 8:40:03 PM$"
|
||||
|
||||
from bt.file import checkPath
|
||||
import sqlite3
|
||||
import settings
|
||||
from bt.file import *
|
||||
|
||||
|
||||
def getdb():
|
||||
return join(settings.get("appdir"), settings.get("appname")+".db")
|
||||
|
||||
|
||||
def dbexists():
|
||||
return checkPath(getdb())
|
||||
|
||||
|
||||
def connect():
|
||||
path = getdb()
|
||||
con = sqlite3.connect(path)
|
||||
con.text_factory = str
|
||||
return con
|
||||
|
||||
|
||||
def disconnect(con):
|
||||
con.commit()
|
||||
con.close()
|
||||
|
||||
|
||||
|
||||
|
||||
class Statement():
|
||||
def __init__(self):
|
||||
self.statement = ""
|
||||
self.con = connect()
|
||||
self.commit = True
|
||||
|
||||
def __del__(self):
|
||||
self.con.close()
|
||||
|
||||
def commitdb(self):
|
||||
self.con.commit()
|
||||
|
||||
def execute(self,vals=None):
|
||||
if self.statement == "":
|
||||
return
|
||||
if vals==None:
|
||||
result = self.con.execute(self.statement)
|
||||
else:
|
||||
result = self.con.execute(self.statement,vals)
|
||||
|
||||
if self.commit == True:
|
||||
self.commitdb()
|
||||
return result
|
||||
|
||||
|
||||
|
||||
|
||||
class CTable(Statement):
|
||||
def __init__(self,name):
|
||||
Statement.__init__(self)
|
||||
self.name = name
|
||||
self.cols = []
|
||||
|
||||
def addcol(self,name,type,params=""):
|
||||
self.cols += [(name,type,params)]
|
||||
|
||||
def execute(self):
|
||||
self.statement = "CREATE TABLE "+self.name + " ("
|
||||
for index,col in enumerate(self.cols):
|
||||
if not index == 0:
|
||||
self.statement += ", "
|
||||
self.statement += " " + col[0] + " " + col[1] + " " + col[2]
|
||||
self.statement += " );"
|
||||
return Statement.execute(self)
|
||||
|
||||
|
||||
|
||||
|
||||
class Select(Statement):
|
||||
def __init__(self,What,From,Where=None):
|
||||
Statement.__init__(self)
|
||||
self.commit = False
|
||||
self.What = What
|
||||
self.From = From
|
||||
self.Where = Where
|
||||
|
||||
def execute(self):
|
||||
self.statement = "SELECT " + self.What
|
||||
self.statement += " FROM " + self.From
|
||||
if not self.Where==None:
|
||||
self.statement += " WHERE " + self.Where
|
||||
return Statement.execute(self)
|
||||
|
||||
|
||||
|
||||
|
||||
class Insert(Statement):
|
||||
def __init__(self,table,values=[]):
|
||||
Statement.__init__(self)
|
||||
self.table = table
|
||||
self.values = values
|
||||
|
||||
def addval(self,val):
|
||||
self.values += [val]
|
||||
|
||||
def execute(self):
|
||||
self.statement = "INSERT INTO "+ self.table + " VALUES("
|
||||
qs = ""
|
||||
for i in range(len(self.values)):
|
||||
if not i == 0:
|
||||
qs+=","
|
||||
qs+="?"
|
||||
#self.values[i] = str(self.values[i])
|
||||
self.statement+=qs + ")"
|
||||
Statement.execute(self, self.values)
|
||||
|
||||
|
||||
|
||||
class Remove(Statement):
|
||||
def __init__(self,table,where=""):
|
||||
Statement.__init__(self)
|
||||
self.table = table
|
||||
self.where = where
|
||||
|
||||
def execute(self):
|
||||
self.statement = "DELETE FROM " + self.table
|
||||
if not self.where=="":
|
||||
self.statement += " WHERE "+self.where
|
||||
Statement.execute(self)
|
|
@ -2,8 +2,26 @@
|
|||
<window width="400" height="150" close="ocarina-stop" title="Ocarina 3.0">
|
||||
<add>
|
||||
<vbox>
|
||||
<menubar>
|
||||
<menuitem name="Library">
|
||||
<menuitem name="New Library"/>
|
||||
<!--<menuitem name="Select Library">
|
||||
<menuitem name="Library 1"/>
|
||||
</menuitem>-->
|
||||
</menuitem>
|
||||
<menuitem name="Playback">
|
||||
<menuplay/>
|
||||
<menupause/>
|
||||
<menustop/>
|
||||
<menusongsel/>
|
||||
</menuitem>
|
||||
</menubar>
|
||||
<songinfo/>
|
||||
<playbutton size="large"/>
|
||||
<hbox>
|
||||
<buttonplay size="large"/>
|
||||
<buttonpause size="large"/>
|
||||
<buttonstop size="large"/>
|
||||
</hbox>
|
||||
<progbar/>
|
||||
</vbox>
|
||||
</add>
|
||||
|
|
Loading…
Reference in New Issue