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):
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()
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()
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):
ctx.fill()
ctx.set_line_width(10.0)
- ctx.set_source_rgba (0.5, 0.0, 0.0, 0.4)
+ ctx.set_source_rgba(0.5, 0.0, 0.0, 0.4)
for i in self.balls:
ctx.arc(i.x, i.y, i.radius, 0, 64*math.pi)
-
- ctx.fill()
- ctx.stroke()
+ ctx.fill()
def draw_current_ball(self):
if self.start_x < 0:
return
ctx = self.draw.window.cairo_create()
ctx.arc(self.start_x, self.start_y, self.radius, 0, 64*math.pi)
- ctx.set_source_rgba (0.5, 0.0, 0.0, 0.4)
+ ctx.set_source_rgba(0.5, 0.0, 0.0, 0.4)
ctx.fill()
def button_press(self, widget, event):
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)