From ce39fc9e2a5b4eab1b3aa6b51039d72af0030c9d Mon Sep 17 00:00:00 2001 From: Lincoln de Sousa Date: Sat, 9 Aug 2008 19:54:42 -0300 Subject: [PATCH] Saving balls added in the image and making it possible to edit its text after added --- gzv.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/gzv.py b/gzv.py index 2149bd0..47cd87e 100644 --- a/gzv.py +++ b/gzv.py @@ -26,9 +26,9 @@ class Ball(object): def __init__(self, x, y, r, name='', position=0): self.position = position - self.x = x - self.y = y - self.radius = r + self.x = int(x) + self.y = int(y) + self.radius = int(r) self.name = name class BallManager(list): @@ -170,8 +170,7 @@ class Gzv(GladeLoader): print def on_cell_edited(self, renderer, path, value): - ball = Ball(self.start_x, self.start_y, self.radius, value, int(path)) - self.balls.append(ball) + self.balls[int(path)].name = value self.load_balls_to_treeview() self.draw.queue_draw() @@ -200,9 +199,9 @@ class Gzv(GladeLoader): self.draw.queue_draw() def load_balls_to_treeview(self): - model = self.treeview.get_model() + self.model.clear() for i in self.balls: - model.append([i.position, i.name]) + self.model.append([i.position, i.name]) def load_balls_from_file(self, fname): balls = BallManager() @@ -212,9 +211,9 @@ class Gzv(GladeLoader): for index, line in enumerate(file(fname)): if not line: continue - pos, radius, name = line.split() + pos, radius, name = line.split(None, 2) x, y = pos.split(',') - balls.append(Ball(int(x), int(y), int(radius), name, index)) + balls.append(Ball(x, y, radius, name.strip(), index)) return balls def remove_fp(self, *args): @@ -323,6 +322,8 @@ class Gzv(GladeLoader): self.ball_width = Ball.DEFAULT_WIDTH position = len(self.balls) + ball = Ball(self.start_x, self.start_y, self.radius, '', position) + self.balls.append(ball) self.model.append([position, '']) self.treeview.set_cursor(str(position), self.fpcolumn, True) -- 2.20.1