# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
+import os
import gtk
import gtk.glade
import math
import cairo
+from ConfigParser import ConfigParser
_ = lambda x:x
self.image = image
self.width = width
self.height = height
+ self.focus_points_file = None
+
+ def save_to_file(self, path):
+ bn = os.path.basename(path)
+ name = os.path.splitext(bn)[0]
+
+ cp = ConfigParser()
+ cp.set('Project', 'image', self.image)
+ cp.set('Project', 'width', self.width)
+ cp.set('Project', 'height', self.height)
+
+ cp.write(open(path, 'w'))
+
+ @staticmethod
+ def parse_file(path):
+ cp = ConfigParser()
+ cp.read(path)
+
+ image = cp.get('Project', 'image')
+ width = cp.getint('Project', 'width')
+ height = cp.getint('Project', 'height')
+ x = cp.getint('Project', 'height')
+
+ proj = Project(image, width, height)
+ proj.focus_points_file = cp.get('Project', 'focus_points')
+
+ return proj
class NewProject(GladeLoader):
def __init__(self, parent=None):
# This '1' was defined in the glade file
if proj.dialog.run() == 1:
- self.load_new_project(proj.get_project())
+ self.load_project(proj.get_project())
proj.destroy()
def open_project(self, *args):
gtk.STOCK_OK, gtk.RESPONSE_OK))
if fc.run() == gtk.RESPONSE_OK:
proj_file = fc.get_filename()
- self.balls = self.load_balls_from_file(proj_file)
-
+ self.load_project(Project.parse_file(proj_file))
fc.destroy()
+ def load_project(self, project):
+ self.balls = self.load_balls_from_file(project.focus_points_file)
+ self.image = project.image
+ self.load_balls_to_treeview()
+
def load_balls_to_treeview(self):
model = self.treeview.get_model()
for i in self.balls:
def load_balls_from_file(self, fname):
balls = BallManager()
+ if not os.path.exists(fname):
+ return balls
+
for index, line in enumerate(file(fname)):
if not line:
continue