ocarina/trunk/src/saveddata.py

54 lines
1.1 KiB
Python

import os
import cPickle as pickle
from library import Library
from song import Song
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.divider = 150
self.library = Library()
self.curList = []
self.colSizes = [110,110,110,110,110]
self.sortedCol = 3
self.updateList = False
self.path = path
self.song = None
if os.path.exists(path):
try:
self.load(path,options)
except:
if options.verbose == True:
print "Error loading user data"
# Dump user data to a file
def dump(self):
out = open(self.path,'w')
p = pickle.Pickler(out,1)
p.dump(self)
out.close()
def clearSong(self):
self.song.close()
self.song = None
return
# Read user data from the file
def load(self,path,options):
if options.verbose == True:
print "User data found, loading..."
p = pickle.Unpickler(open(path))
data = p.load()
self.size = data.size
self.library = data.library
self.divider = data.divider
self.curList = data.curList
self.colSizes = data.colSizes