From 84710dbd209d841fe23c117f6a6f3924f284319a Mon Sep 17 00:00:00 2001 From: bjschuma Date: Sat, 27 Jun 2009 04:32:43 +0000 Subject: [PATCH] Began reworking most code git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@28 1daee41c-8060-4895-b1f0-2197c00d777a --- trunk/Makefile | 1 + trunk/src/menuItem.py | 7 +++++++ trunk/src/ocarina.py | 26 ++++++++++++++++++++++---- trunk/src/options.py | 6 ++++++ trunk/src/saveddata.py | 30 ++++++++++++++++++++++++++++++ trunk/src/song.py | 4 ++-- trunk/src/window.py | 40 ++++++++++++++++++++++++++++++++++++---- 7 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 trunk/src/menuItem.py create mode 100644 trunk/src/options.py create mode 100644 trunk/src/saveddata.py diff --git a/trunk/Makefile b/trunk/Makefile index f2f049a0..62939ff3 100644 --- a/trunk/Makefile +++ b/trunk/Makefile @@ -1,6 +1,7 @@ open: geany src/*.py & + geany src/GuiObjects/*.py & clean: rm -rf src/*.pyc diff --git a/trunk/src/menuItem.py b/trunk/src/menuItem.py new file mode 100644 index 00000000..f3eafb2b --- /dev/null +++ b/trunk/src/menuItem.py @@ -0,0 +1,7 @@ +import gtk + +class MenuItem(gtk.MenuItem) + def __init__(self,label,func,text,func2): + gtk.MenuItem.__init__(self,label) + self.connect("activate",func,text,func2) + self.show() diff --git a/trunk/src/ocarina.py b/trunk/src/ocarina.py index cd2347b9..eb40c90e 100644 --- a/trunk/src/ocarina.py +++ b/trunk/src/ocarina.py @@ -7,6 +7,9 @@ import pygtk pygtk.require('2.0') import gtk +from options import Options +from saveddata import SavedData + from song import Song from duration import Duration from library import Library @@ -21,8 +24,17 @@ gobject.threads_init() class main: def __init__(self,argv): + # Parse options + self.options = Options() + if ("-v" in argv) == True: + self.options.verbose = True + # Load saved data (or create new data) + self.data = SavedData(self.options) + + self.window = Window(self.quit,self.options,self.data) + gtk.main() + ''' self.ops = Operations(self.quit) - self.library = Library() self.plist = Playlist() self.plist.insert(self.library.nonBanned()) @@ -53,15 +65,21 @@ class main: song = Song(info,self.next)#,self.commands.printLines) self.ops.song = song self.ops.next("","") + window.song = self.ops.song # Call gtk main gtk.main() + ''' # Eventually replace "delete_event" with this - def quit(self,widget,event,data=None): - print "Quitting..." - self.library.dump() + def quit(self,widgit,data): + if self.options.verbose == True: + print "Quitting..." + #print self.window.get_size() + self.data.size = self.window.get_size() + self.data.dump() + #self.library.dump() gtk.main_quit() return False diff --git a/trunk/src/options.py b/trunk/src/options.py new file mode 100644 index 00000000..212d1ea6 --- /dev/null +++ b/trunk/src/options.py @@ -0,0 +1,6 @@ +import os + +class Options: + def __init__(self): + self.verbose = False + self.user = os.path.expanduser("~") diff --git a/trunk/src/saveddata.py b/trunk/src/saveddata.py new file mode 100644 index 00000000..4e7d8917 --- /dev/null +++ b/trunk/src/saveddata.py @@ -0,0 +1,30 @@ +import os +import cPickle as pickle + + +class SavedData: + def __init__(self,options): + path = os.path.join(options.user,".ocarina") + path = os.path.join(path,"ocarina-data.data") + self.size = (800,600) + self.library = None + self.path = path + + if os.path.exists(path): + self.load(path) + + + # Dump user data to a file + def dump(self): + out = open(self.path,'w') + p = pickle.Pickler(out,1) + p.dump(self) + out.close() + + + # Read user data from the file + def load(self,path): + print "User data found, loading..." + p = pickle.Unpickler(open(path)) + data = p.load() + self.size = data.size diff --git a/trunk/src/song.py b/trunk/src/song.py index b2ea9e7d..f2f3287a 100644 --- a/trunk/src/song.py +++ b/trunk/src/song.py @@ -70,7 +70,7 @@ class Song(): # Change state to "playing" - def play(self): + def play(self,widgit,data): self.player.set_state(gst.STATE_PLAYING) # Start main loop and find duration (if this hasn't been done yet) while self.duration() == False: @@ -78,7 +78,7 @@ class Song(): # Change state to "paused" - def pause(self): + def pause(self,widgit,data): self.player.set_state(gst.STATE_PAUSED) diff --git a/trunk/src/window.py b/trunk/src/window.py index 1574080f..ca765396 100644 --- a/trunk/src/window.py +++ b/trunk/src/window.py @@ -6,11 +6,26 @@ import gtk import thread from kiwi.ui.objectlist import Column, ObjectList +import GuiObjects.* + class Window(gtk.Window): - def __init__(self,onQuit,ops): + #def __init__(self,onQuit,ops,song): + def __init__(self,onQuit,options,data): gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL) - print "Making window!" + 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() + self.makeMenuBar() + ''' + self.song = song self.ops = ops self.tree = None self.tooltip = gtk.Tooltips() @@ -29,6 +44,7 @@ class Window(gtk.Window): self.makeList() self.makeControls() self.maximize() + ''' self.show() @@ -179,8 +195,12 @@ class Window(gtk.Window): row = gtk.HBox(False,0) topRow = gtk.HBox(False,0) # Make top row buttons - self.makeButton("play","images/play.png",None,self.ops.play,topRow) - self.makeButton("pause","images/pause.png",None,self.ops.pause,topRow) + #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) + self.makeButton("stop","images/stop.png",None,self.ops.stop,topRow) self.makeButton("next","images/next.png",None,self.ops.next,topRow) self.makeButton("info",None,"Info",self.ops.info,topRow) @@ -242,6 +262,17 @@ class Window(gtk.Window): def makeMenuBar(self): + # Make a menu bar + bar = gtk.MenuBar() + # This is the dropdown selections + # Make a new library option + library = MenuItem("Library",None,None,None) + bar.append(library) + bar.show() + self.mainLayout.pack_start(bar,False,False,0) + + + ''' # Make menu bar bar = gtk.MenuBar() # This is the dropdown selections @@ -277,6 +308,7 @@ class Window(gtk.Window): # Add to main layout bar.show() self.mainLayout.pack_start(bar,False,False,0) + ''' def selectDir(self,func):