If picture does no exist, warn and exit
[cascardo/movie.git] / gzv.py
diff --git a/gzv.py b/gzv.py
index 664b7f9..ac4dce3 100644 (file)
--- a/gzv.py
+++ b/gzv.py
@@ -1,5 +1,5 @@
 # -*- coding: utf-8; -*-
-# gzv.py - an user interface to generate-zooming-video
+# gzv.py - an user interface to select people in a picture
 #
 # Copyright (C) 2008  Lincoln de Sousa <lincoln@minaslivre.org>
 #
@@ -234,7 +234,6 @@ class Gzv(GladeLoader):
             self.balls.save_to_file(self.project.focus_points_file)
         fc.destroy()
 
-
     def load_project(self, project):
         self.project = project
         self.balls = self.load_balls_from_file(project.focus_points_file)
@@ -257,12 +256,19 @@ class Gzv(GladeLoader):
 
         self.draw.set_from_pixbuf(pixbuf)
         self.load_balls_to_treeview()
+        self.set_widgets_sensitivity(True)
 
     def unload_project(self):
         self.project = None
         self.image = None
         self.balls = BallManager()
         self.draw.queue_draw()
+        self.set_widgets_sensitivity(False)
+
+    def set_widgets_sensitivity(self, sensitive):
+        for i in 'toolbutton1', 'toolbutton5', 'scrolledwindow1', \
+                'hbox2', 'imagemenuitem3':
+            self.wid(i).set_sensitive(sensitive)
 
     def load_balls_to_treeview(self):
         self.model.clear()
@@ -305,6 +311,16 @@ class Gzv(GladeLoader):
                 i.selected = False
             ball.selected = True
 
+            # available space to the image
+            w = self.evtbox.get_allocation().width
+            h = self.evtbox.get_allocation().height
+
+            # point begining from the left image border
+            wib = self.point_with_border(ball)
+
+            #self.wid('viewport').get_vadjustment().value = wib.x # + (w / 2)
+            #self.wid('viewport').get_hadjustment().value = wib.y # + (h / 2)
+
             self.draw.queue_draw()
 
     def select_fp_from_image(self, ball):
@@ -339,6 +355,40 @@ class Gzv(GladeLoader):
 
         self.balls.save_to_file(self.project.focus_points_file)
 
+    def move_fp_up(self, *args):
+        selection = self.treeview.get_selection()
+        model, path = selection.get_selected()
+        if not path:
+            return
+
+        pos = model[path][0]
+        newpos = max(pos - 1, 0)
+        self.balls.insert(newpos, self.balls.pop(pos))
+
+        # normalizing the position of elements.
+        for index, item in enumerate(self.balls):
+            item.position = index
+
+        self.load_balls_to_treeview()
+        selection.select_path(str(newpos))
+
+    def move_fp_down(self, *args):
+        selection = self.treeview.get_selection()
+        model, path = selection.get_selected()
+        if not path:
+            return
+
+        pos = model[path][0]
+        newpos = min(pos + 1, len(self.balls))
+        self.balls.insert(newpos, self.balls.pop(pos))
+
+        # normalizing the position of elements.
+        for index, item in enumerate(self.balls):
+            item.position = index
+
+        self.load_balls_to_treeview()
+        selection.select_path(str(newpos))
+
     def expose_draw(self, draw, event):
         if not self.image:
             return
@@ -355,7 +405,7 @@ class Gzv(GladeLoader):
 
         return False
 
-    def ball_width_border(self, ball):
+    def point_with_border(self, ball):
         iw, ih = self.draw.size_request()
         w = self.draw.get_allocation().width
         h = self.draw.get_allocation().height
@@ -375,8 +425,8 @@ class Gzv(GladeLoader):
 
     def draw_ball(self, ball):
         ctx = self.draw.window.cairo_create()
-        ctx.arc(self.ball_width_border(ball).x,
-                self.ball_width_border(ball).y,
+        ctx.arc(self.point_with_border(ball).x,
+                self.point_with_border(ball).y,
                 ball.radius, 0, 64*math.pi)
         ctx.set_source_rgba(0.0, 0.0, 0.5, 0.4)
         ctx.fill()
@@ -384,8 +434,8 @@ class Gzv(GladeLoader):
         if ball.selected:
             ctx.set_source_rgba(0.0, 0.5, 0.0, 0.4)
             ctx.set_line_width(5)
-            ctx.arc(self.ball_width_border(ball).x,
-                    self.ball_width_border(ball).y,
+            ctx.arc(self.point_with_border(ball).x,
+                    self.point_with_border(ball).y,
                     ball.radius+1, 0, 64*math.pi)
             ctx.stroke()
 
@@ -398,7 +448,7 @@ class Gzv(GladeLoader):
         if event.button == 1:
             for i in self.balls:
                 p1 = Point(event.x, event.y)
-                p2 = self.ball_width_border(i)
+                p2 = self.point_with_border(i)
                 if Point.pythagorean(p1, p2) < i.radius:
                     self.last_x = event.x - i.p.x
                     self.last_y = event.y - i.p.y