From 1454083e7f91852aea6fd92f3da29897a395a28d Mon Sep 17 00:00:00 2001 From: Lincoln de Sousa Date: Tue, 12 Aug 2008 04:41:45 -0300 Subject: [PATCH] Adding the attribute button-press-event' in the main treeview to the method Gzv.select_fp that gets the position of the selected ball and set the selected attribute to the selected ball. Gzv.draw_ball: drawing a border in the balls with the selected attribute set to True. Gzv.load_project: Loading a pixbuf before creating the draw image. --- gzv.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/gzv.py b/gzv.py index b927dc0..0bccbff 100644 --- a/gzv.py +++ b/gzv.py @@ -25,8 +25,9 @@ _ = lambda x:x class Ball(object): DEFAULT_WIDTH = 10 - def __init__(self, x, y, r, name='', position=0): + def __init__(self, x, y, r, name='', position=0, selected=False): self.position = position + self.selected = selected self.x = int(x) self.y = int(y) self.radius = int(r) @@ -140,6 +141,7 @@ class Gzv(GladeLoader): self.model = gtk.ListStore(int, str) self.treeview = self.wid('treeview') self.treeview.set_model(self.model) + self.treeview.connect('button-press-event', self.select_fp) self.draw = self.wid('draw') self.draw.connect_after('expose-event', self.expose_draw) @@ -216,10 +218,10 @@ class Gzv(GladeLoader): self.balls = self.load_balls_from_file(project.focus_points_file) self.image = project.image - # loading the picture image and getting some useful - # information to draw it in the widget's background + # I'm loading a pixbuf first because I need to get its + # dimensions this with a pixbuf is easier than with an image. try: - self.draw.set_from_file(project.image) + pixbuf = gtk.gdk.pixbuf_new_from_file(project.image) except gobject.GError: msg = _("Couldn't recognize the image file format.") dialog = gtk.MessageDialog(self.window, @@ -231,6 +233,7 @@ class Gzv(GladeLoader): dialog.destroy() return self.unload_project() + self.draw.set_from_pixbuf(pixbuf) self.load_balls_to_treeview() def unload_project(self): @@ -268,6 +271,20 @@ class Gzv(GladeLoader): del model[path] self.draw.queue_draw() + def select_fp(self, treeview, event): + path, column, x, y = \ + self.treeview.get_path_at_pos(int(event.x), int(event.y)) + if path: + model = self.treeview.get_model() + ball = self.balls[model[path][0]] + + # making sure that only one ball is selected + for i in self.balls: + i.selected = False + ball.selected = True + + self.draw.queue_draw() + def save_fp_list(self, *args): assert self.project is not None @@ -301,9 +318,15 @@ class Gzv(GladeLoader): def draw_ball(self, ball): ctx = self.draw.window.cairo_create() ctx.arc(ball.x, ball.y, ball.radius, 0, 64*math.pi) - ctx.set_source_rgba(0.5, 0.0, 0.0, 0.4) + ctx.set_source_rgba(0.0, 0.0, 0.5, 0.4) ctx.fill() + if ball.selected: + ctx.set_source_rgba(0.0, 0.5, 0.0, 0.4) + ctx.set_line_width(5) + ctx.arc(ball.x, ball.y, ball.radius+1, 0, 64*math.pi) + ctx.stroke() + def draw_current_ball(self): if self.start_x < 0: return -- 2.20.1