<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Sun Aug 10 12:43:33 2008 -->
+<!--Generated with glade3 3.4.5 on Tue Aug 12 01:42:13 2008 -->
<glade-interface>
<widget class="GtkWindow" id="main-window">
<property name="title" translatable="yes">Gzv</property>
<widget class="GtkEventBox" id="eventbox">
<property name="visible">True</property>
<child>
- <widget class="GtkDrawingArea" id="draw">
+ <widget class="GtkImage" id="draw">
<property name="visible">True</property>
+ <property name="stock">gtk-missing-image</property>
</widget>
</child>
</widget>
<widget class="GtkEntry" id="width">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="text" translatable="yes">640</property>
</widget>
<packing>
<property name="position">1</property>
<widget class="GtkEntry" id="height">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="text" translatable="yes">480</property>
</widget>
<packing>
<property name="position">1</property>
self.dialog.set_transient_for(parent)
def get_project(self):
+ if not self.dialog.run():
+ return None
+
fname = self.wid('image').get_filename()
width = self.wid('width').get_text()
height = self.wid('height').get_text()
self.treeview.set_model(self.model)
self.draw = self.wid('draw')
- self.draw.connect('expose-event', self.expose_draw)
+ self.draw.connect_after('expose-event', self.expose_draw)
# Starting with an empty project with no image loaded
self.project = None
def on_cell_edited(self, renderer, path, value):
self.balls[int(path)].name = value
self.load_balls_to_treeview()
- self.draw.queue_draw()
def new_project(self, button):
proj = NewProject(self.window)
+ project = proj.get_project()
+ proj.destroy()
# This '1' was defined in the glade file
- if proj.dialog.run() == 1:
- self.load_project(proj.get_project())
- proj.destroy()
+ if project:
+ self.load_project(project)
def open_project(self, *args):
fc = gtk.FileChooserDialog(_('Choose a gzv project'), self.window,
self.project = project
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
+ try:
+ self.draw.set_from_file(project.image)
+ except gobject.GError:
+ msg = _("Couldn't recognize the image file format.")
+ dialog = gtk.MessageDialog(self.window,
+ gtk.DIALOG_MODAL,
+ gtk.MESSAGE_ERROR,
+ gtk.BUTTONS_CLOSE)
+ dialog.set_markup(msg)
+ dialog.run()
+ dialog.destroy()
+ return self.unload_project()
+
self.load_balls_to_treeview()
- self.draw.queue_draw()
def unload_project(self):
self.project = None
if not self.image:
return
- # loading the picture image and getting some useful
- # information to draw it in the widget's background
- try:
- img = gtk.gdk.pixbuf_new_from_file(self.image)
- except gobject.GError:
- msg = _("Couldn't recognize the image file format.")
- dialog = gtk.MessageDialog(self.window,
- gtk.DIALOG_MODAL,
- gtk.MESSAGE_ERROR,
- gtk.BUTTONS_CLOSE)
- dialog.set_markup(msg)
- dialog.run()
- dialog.destroy()
-
- self.draw.stop_emission('expose-event')
- return self.unload_project()
-
- pixels = img.get_pixels()
- rowstride = img.get_rowstride()
- width = img.get_width()
- height = img.get_height()
- gc = draw.style.black_gc
-
- # sets the correct size of the eventbox, to show the scrollbar
- # when needed.
- self.evtbox.set_size_request(width, height)
-
- # drawing the picture in the background of the drawing area,
- # this is really important.
- draw.window.draw_rgb_image(gc, 0, 0, width, height,
- 'normal', pixels, rowstride,
- 0, 0)
-
- # this call makes the ball being drown be shown correctly.
self.draw_current_ball()
+ for i in self.balls:
+ self.draw_ball(i)
+ return False
- # drawing other balls stored in the self.balls list.
- ctx = draw.window.cairo_create()
- ctx.fill()
-
- ctx.set_line_width(10.0)
+ 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)
-
- for i in self.balls:
- ctx.arc(i.x, i.y, i.radius, 0, 64*math.pi)
- ctx.fill()
+ 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.fill()
+ ball = Ball(self.start_x, self.start_y, self.radius)
+ self.draw_ball(ball)
def button_press(self, widget, event):
if event.button == 1:
self.last_x = event.x
def finish_drawing(self):
- self.draw_current_ball()
- 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)
+ # returning to the standard radius
+ self.radius = Ball.DEFAULT_WIDTH
+
if __name__ == '__main__':
Gzv().window.show_all()
gtk.main()