# 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
def gtk_main(self, *args):
gtk.main()
+class Project(object):
+ def __init__(self, image, width, height):
+ 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):
super(NewProject, self).__init__('gzv.glade', 'new-project')
+ self.dialog = self.wid('new-project')
if parent:
- self.wid('new-project').set_transient_for(parent)
+ self.dialog.set_transient_for(parent)
+
+ def get_project(self):
+ fname = self.wid('image').get_filename()
+ width = self.wid('width').get_text()
+ height = self.wid('height').get_text()
+ return Project(fname, width, height)
+
+ def destroy(self):
+ self.dialog.destroy()
class Gzv(GladeLoader):
def __init__(self):
self.draw = self.wid('draw')
self.draw.connect('expose-event', self.expose_draw)
- # FIXME: Hardcoded.
- self.image = 'skol.jpg'
- self.balls = self.load_balls_from_file('xxx')
- self.load_balls_to_treeview()
+ # Starting with an empty project with no image loaded
+ self.project = None
+ self.image = None
- # this *MUST* be called *AFTER* load_balls_to_treeview
+ # This attr may be overriten, if so, call the method (load_balls_to_treeview)
+ self.balls = BallManager()
+
+ self.load_balls_to_treeview()
self.setup_treeview()
+ # drawing stuff
self.ball_width = Ball.DEFAULT_WIDTH
self.selecting = False
self.start_x = -1
print args
def new_project(self, button):
- dialog = NewProject(self.window).wid('new-project')
+ proj = NewProject(self.window)
# This '1' was defined in the glade file
- if dialog.run() == 1:
- pass
- dialog.destroy()
+ if proj.dialog.run() == 1:
+ self.load_project(proj.get_project())
+ proj.destroy()
- def open_file_chooser(self, button):
+ def open_project(self, *args):
fc = gtk.FileChooserDialog(_('Choose a gzv project'), self.window,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OK, gtk.RESPONSE_OK))
if fc.run() == gtk.RESPONSE_OK:
- self.image = fc.get_filename()
-
+ proj_file = fc.get_filename()
+ 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