Merge commit 'gzv/master'
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 16 Aug 2008 20:18:58 +0000 (17:18 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 16 Aug 2008 20:18:58 +0000 (17:18 -0300)
gzv.glade [new file with mode: 0644]
gzv.py [new file with mode: 0644]

diff --git a/gzv.glade b/gzv.glade
new file mode 100644 (file)
index 0000000..71bb68f
--- /dev/null
+++ b/gzv.glade
@@ -0,0 +1,562 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
+<!--Generated with glade3 3.4.5 on Wed Aug 13 00:51:49 2008 -->
+<glade-interface>
+  <widget class="GtkWindow" id="main-window">
+    <property name="title" translatable="yes">Gzv</property>
+    <property name="default_width">640</property>
+    <property name="default_height">480</property>
+    <child>
+      <widget class="GtkVBox" id="vbox1">
+        <property name="visible">True</property>
+        <child>
+          <widget class="GtkMenuBar" id="menubar1">
+            <property name="visible">True</property>
+            <child>
+              <widget class="GtkMenuItem" id="menuitem1">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_File</property>
+                <property name="use_underline">True</property>
+                <child>
+                  <widget class="GtkMenu" id="menu1">
+                    <property name="visible">True</property>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem1">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-new</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                        <signal name="activate" handler="new_project"/>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem2">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-open</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                        <signal name="activate" handler="open_project"/>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem3">
+                        <property name="visible">True</property>
+                        <property name="sensitive">False</property>
+                        <property name="label" translatable="yes">gtk-save</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                        <signal name="activate" handler="save_project"/>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
+                        <property name="visible">True</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem5">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-quit</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                        <signal name="activate" handler="gtk_main_quit"/>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkMenuItem" id="menuitem2">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Edit</property>
+                <property name="use_underline">True</property>
+                <child>
+                  <widget class="GtkMenu" id="menu2">
+                    <property name="visible">True</property>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem6">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-preferences</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkMenuItem" id="menuitem3">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_View</property>
+                <property name="use_underline">True</property>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkMenuItem" id="menuitem4">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Help</property>
+                <property name="use_underline">True</property>
+                <child>
+                  <widget class="GtkMenu" id="menu3">
+                    <property name="visible">True</property>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem10">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-about</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+              </widget>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkToolbar" id="toolbar1">
+            <property name="visible">True</property>
+            <child>
+              <widget class="GtkToolButton" id="toolbutton1">
+                <property name="visible">True</property>
+                <property name="stock_id">gtk-new</property>
+                <signal name="clicked" handler="new_project"/>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkToolButton" id="toolbutton2">
+                <property name="visible">True</property>
+                <property name="stock_id">gtk-open</property>
+                <signal name="clicked" handler="open_project"/>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkToolButton" id="toolbutton5">
+                <property name="visible">True</property>
+                <property name="sensitive">False</property>
+                <property name="stock_id">gtk-save</property>
+                <signal name="clicked" handler="save_project"/>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkSeparatorToolItem" id="toolbutton3">
+                <property name="visible">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkToolButton" id="toolbutton4">
+                <property name="visible">True</property>
+                <property name="sensitive">False</property>
+                <property name="stock_id">gtk-execute</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkHPaned" id="hpaned1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <child>
+              <widget class="GtkVBox" id="vbox2">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkHBox" id="hbox1">
+                    <property name="visible">True</property>
+                    <child>
+                      <widget class="GtkLabel" id="label1">
+                        <property name="visible">True</property>
+                        <property name="xalign">0</property>
+                        <property name="xpad">4</property>
+                        <property name="label" translatable="yes">Focus points</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="button1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="relief">GTK_RELIEF_NONE</property>
+                        <property name="response_id">0</property>
+                        <child>
+                          <widget class="GtkImage" id="image1">
+                            <property name="width_request">18</property>
+                            <property name="visible">True</property>
+                            <property name="stock">gtk-close</property>
+                            <property name="icon_size">1</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkScrolledWindow" id="scrolledwindow1">
+                    <property name="width_request">179</property>
+                    <property name="visible">True</property>
+                    <property name="sensitive">False</property>
+                    <property name="can_focus">True</property>
+                    <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                    <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                    <property name="shadow_type">GTK_SHADOW_IN</property>
+                    <child>
+                      <widget class="GtkTreeView" id="treeview">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="headers_visible">False</property>
+                        <property name="headers_clickable">True</property>
+                        <property name="rules_hint">True</property>
+                      </widget>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkHBox" id="hbox2">
+                    <property name="visible">True</property>
+                    <property name="sensitive">False</property>
+                    <property name="spacing">4</property>
+                    <child>
+                      <widget class="GtkButton" id="button4">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="tooltip" translatable="yes">Remove the selected focus point</property>
+                        <property name="response_id">0</property>
+                        <signal name="clicked" handler="remove_fp"/>
+                        <child>
+                          <widget class="GtkImage" id="image2">
+                            <property name="visible">True</property>
+                            <property name="stock">gtk-remove</property>
+                          </widget>
+                        </child>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="button5">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="tooltip" translatable="yes">Save list of focus points</property>
+                        <property name="response_id">0</property>
+                        <signal name="clicked" handler="save_fp_list"/>
+                        <child>
+                          <widget class="GtkImage" id="image3">
+                            <property name="visible">True</property>
+                            <property name="stock">gtk-save</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="button6">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="tooltip" translatable="yes">Move the selected focus point up</property>
+                        <property name="response_id">0</property>
+                        <signal name="clicked" handler="move_fp_up"/>
+                        <child>
+                          <widget class="GtkImage" id="image4">
+                            <property name="visible">True</property>
+                            <property name="stock">gtk-go-up</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="button7">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="tooltip" translatable="yes">Move the selected focus point down</property>
+                        <property name="response_id">0</property>
+                        <signal name="clicked" handler="move_fp_down"/>
+                        <child>
+                          <widget class="GtkImage" id="image5">
+                            <property name="visible">True</property>
+                            <property name="stock">gtk-go-down</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="position">3</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="padding">4</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="resize">False</property>
+                <property name="shrink">True</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkScrolledWindow" id="scrolledwindow2">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                <child>
+                  <widget class="GtkViewport" id="viewport">
+                    <property name="visible">True</property>
+                    <property name="resize_mode">GTK_RESIZE_QUEUE</property>
+                    <child>
+                      <widget class="GtkEventBox" id="eventbox">
+                        <property name="visible">True</property>
+                        <child>
+                          <widget class="GtkImage" id="draw">
+                            <property name="visible">True</property>
+                          </widget>
+                        </child>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+              </widget>
+              <packing>
+                <property name="resize">True</property>
+                <property name="shrink">True</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkStatusbar" id="statusbar1">
+            <property name="visible">True</property>
+            <property name="spacing">2</property>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+  <widget class="GtkDialog" id="new-project">
+    <property name="border_width">4</property>
+    <property name="title" translatable="yes">Start a new project</property>
+    <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
+    <property name="default_width">300</property>
+    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <widget class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="spacing">2</property>
+        <child>
+          <widget class="GtkVBox" id="vbox3">
+            <property name="visible">True</property>
+            <property name="border_width">4</property>
+            <property name="spacing">10</property>
+            <child>
+              <widget class="GtkFrame" id="frame2">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">GTK_SHADOW_NONE</property>
+                <child>
+                  <widget class="GtkAlignment" id="alignment2">
+                    <property name="visible">True</property>
+                    <property name="left_padding">14</property>
+                    <child>
+                      <widget class="GtkVBox" id="vbox5">
+                        <property name="visible">True</property>
+                        <child>
+                          <widget class="GtkFileChooserButton" id="image">
+                            <property name="visible">True</property>
+                          </widget>
+                          <packing>
+                            <property name="expand">False</property>
+                          </packing>
+                        </child>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label7">
+                    <property name="visible">True</property>
+                    <property name="ypad">8</property>
+                    <property name="label" translatable="yes">&lt;b&gt;Image&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                  </widget>
+                  <packing>
+                    <property name="type">label_item</property>
+                  </packing>
+                </child>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkFrame" id="frame1">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">GTK_SHADOW_NONE</property>
+                <child>
+                  <widget class="GtkAlignment" id="alignment1">
+                    <property name="visible">True</property>
+                    <property name="left_padding">14</property>
+                    <child>
+                      <widget class="GtkVBox" id="vbox4">
+                        <property name="visible">True</property>
+                        <property name="spacing">6</property>
+                        <child>
+                          <widget class="GtkHBox" id="hbox3">
+                            <property name="visible">True</property>
+                            <child>
+                              <widget class="GtkLabel" id="label3">
+                                <property name="width_request">100</property>
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">Width:</property>
+                              </widget>
+                            </child>
+                            <child>
+                              <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>
+                              </packing>
+                            </child>
+                          </widget>
+                        </child>
+                        <child>
+                          <widget class="GtkHBox" id="hbox4">
+                            <property name="visible">True</property>
+                            <child>
+                              <widget class="GtkLabel" id="label4">
+                                <property name="width_request">100</property>
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">Height:</property>
+                              </widget>
+                            </child>
+                            <child>
+                              <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>
+                              </packing>
+                            </child>
+                          </widget>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="ypad">8</property>
+                    <property name="label" translatable="yes">&lt;b&gt;Video Dimensions&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                  </widget>
+                  <packing>
+                    <property name="type">label_item</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <widget class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">GTK_BUTTONBOX_END</property>
+            <child>
+              <widget class="GtkButton" id="button2">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="label" translatable="yes">gtk-cancel</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">0</property>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkButton" id="button3">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="label" translatable="yes">gtk-ok</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">1</property>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">GTK_PACK_END</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+</glade-interface>
diff --git a/gzv.py b/gzv.py
new file mode 100644 (file)
index 0000000..ac4dce3
--- /dev/null
+++ b/gzv.py
@@ -0,0 +1,508 @@
+# -*- coding: utf-8; -*-
+# gzv.py - an user interface to select people in a picture
+#
+# Copyright (C) 2008  Lincoln de Sousa <lincoln@minaslivre.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+import os
+import gtk
+import gtk.glade
+import gobject
+import math
+import cairo
+from ConfigParser import ConfigParser
+
+_ = lambda x:x
+
+class Point(object):
+    def __init__(self, x, y):
+        self.x = x
+        self.y = y
+
+    @staticmethod
+    def pythagorean(p1, p2):
+        return math.sqrt((p2.x - p1.x)**2 + (p2.y - p1.y)**2)
+
+class Ball(object):
+    DEFAULT_WIDTH = 10
+
+    def __init__(self, x, y, r, name='', position=0, selected=False):
+        self.position = position
+        self.selected = selected
+        self.p = Point(int(x), int(y))
+        self.radius = int(r)
+        self.name = name
+
+class BallManager(list):
+    def __init__(self, *args, **kwargs):
+        super(BallManager, self).__init__(*args, **kwargs)
+
+    def save_to_file(self, path):
+        target = open(path, 'w')
+        for i in self:
+            target.write('%d,%d %d %s\n' % (i.p.x, i.p.y, i.radius, i.name))
+        target.close()
+
+class GladeLoader(object):
+    def __init__(self, fname, root=''):
+        self.ui = gtk.glade.XML(fname, root)
+        self.ui.signal_autoconnect(self)
+
+    def get_widget(self, wname):
+        return self.ui.get_widget(wname)
+
+    # little shortcut
+    wid = get_widget
+
+    # glade callbacks
+
+    def gtk_widget_show(self, widget, *args):
+        widget.show()
+        return True
+
+    def gtk_widget_hide(self, widget, *args):
+        widget.hide()
+        return True
+
+    def gtk_main_quit(self, *args):
+        gtk.main_quit()
+
+    def gtk_main(self, *args):
+        gtk.main()
+
+class Project(object):
+    def __init__(self, image, width, height):
+        self.image = image
+        self.width = width
+        self.height = height
+        self.focus_points_file = ''
+
+    def save_to_file(self, path):
+        if not self.focus_points_file:
+            bn = os.path.basename(path)
+            name = os.path.splitext(bn)[0]
+            self.focus_points_file = \
+                os.path.join(os.path.dirname(path), name + '_fpf')
+
+        cp = ConfigParser()
+        cp.add_section('Project')
+        cp.set('Project', 'image', self.image)
+        cp.set('Project', 'width', self.width)
+        cp.set('Project', 'height', self.height)
+        cp.set('Project', 'focus_points', self.focus_points_file)
+        
+        cp.write(open(path, 'w'))
+
+    @staticmethod
+    def parse_file(path):
+        cp = ConfigParser()
+        cp.read(path)
+
+        image = cp.get('Project', 'image')
+        width = cp.getint('Project', 'width')
+        height = cp.getint('Project', 'height')
+        x = cp.getint('Project', 'height')
+
+        proj = Project(image, width, height)
+        proj.focus_points_file = cp.get('Project', 'focus_points')
+
+        return proj
+
+class NewProject(GladeLoader):
+    def __init__(self, parent=None):
+        super(NewProject, self).__init__('gzv.glade', 'new-project')
+        self.dialog = self.wid('new-project')
+        if parent:
+            self.dialog.set_transient_for(parent)
+
+    def get_project(self):
+        # This '1' was defined in the glade file
+        if not self.dialog.run() == 1:
+            return None
+
+        fname = self.wid('image').get_filename()
+        width = self.wid('width').get_text()
+        height = self.wid('height').get_text()
+        return Project(fname, width, height)
+
+    def destroy(self):
+        self.dialog.destroy()
+
+class Gzv(GladeLoader):
+    def __init__(self):
+        super(Gzv, self).__init__('gzv.glade', 'main-window')
+        self.window = self.wid('main-window')
+        self.window.connect('delete-event', lambda *x: gtk.main_quit())
+
+        self.evtbox = self.wid('eventbox')
+        self.evtbox.connect('button-press-event', self.button_press)
+        self.evtbox.connect('button-release-event', self.button_release)
+        self.evtbox.connect('motion-notify-event', self.motion_notify)
+        self.evtbox.connect('motion-notify-event', self.ball_motion)
+
+        # making it possible to grab motion events when the mouse is
+        # over the widget.
+        self.evtbox.set_events(gtk.gdk.POINTER_MOTION_MASK)
+
+        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)
+
+        # Starting with an empty project with no image loaded
+        self.project = None
+        self.image = None
+
+        # This attr may be overriten, if so, call the method (load_balls_to_treeview)
+        self.balls = BallManager()
+
+        self.load_balls_to_treeview()
+        self.setup_treeview()
+
+        self.new_ball = False
+        self.move_ball = None
+
+        # drawing stuff
+        self.start_x = -1
+        self.start_y = -1
+        self.last_x = -1
+        self.last_y = -1
+        self.radius = Ball.DEFAULT_WIDTH
+
+    def show(self):
+        self.window.show_all()
+
+    def setup_treeview(self):
+        self.model.connect('rows-reordered', self.on_rows_reordered)
+
+        renderer = gtk.CellRendererText()
+        column = gtk.TreeViewColumn(_('Position'), renderer, text=0)
+        column.set_property('visible', False)
+        self.treeview.append_column(column)
+
+        renderer = gtk.CellRendererText()
+        renderer.connect('edited', self.on_cell_edited)
+        renderer.set_property('editable', True)
+        self.fpcolumn = gtk.TreeViewColumn(_('Name'), renderer, text=1)
+        self.treeview.append_column(self.fpcolumn)
+
+    def on_rows_reordered(self, *args):
+        print 
+
+    def on_cell_edited(self, renderer, path, value):
+        self.balls[int(path)].name = value
+        self.load_balls_to_treeview()
+
+    def new_project(self, button):
+        proj = NewProject(self.window)
+        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,
+                                   buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
+                                            gtk.STOCK_OK, gtk.RESPONSE_OK))
+        if fc.run() == gtk.RESPONSE_OK:
+            proj_file = fc.get_filename()
+            self.load_project(Project.parse_file(proj_file))
+        fc.destroy()
+
+    def save_project(self, *args):
+        fc = gtk.FileChooserDialog(_('Save project'), self.window,
+                                   action=gtk.FILE_CHOOSER_ACTION_SAVE,
+                                   buttons=(gtk.STOCK_CANCEL,
+                                            gtk.RESPONSE_CANCEL,
+                                            gtk.STOCK_SAVE,
+                                            gtk.RESPONSE_OK))
+        if fc.run() == gtk.RESPONSE_OK:
+            self.project.save_to_file(fc.get_filename())
+            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)
+        self.image = project.image
+
+        # I'm loading a pixbuf first because I need to get its
+        # dimensions this with a pixbuf is easier than with an image.
+        try:
+            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,
+                                       gtk.DIALOG_MODAL,
+                                       gtk.MESSAGE_ERROR,
+                                       gtk.BUTTONS_CLOSE)
+            dialog.set_markup(msg)
+            dialog.run()
+            dialog.destroy()
+            return self.unload_project()
+
+        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()
+        for i in self.balls:
+            self.model.append([i.position, i.name])
+
+    def load_balls_from_file(self, fname):
+        balls = BallManager()
+        if not os.path.exists(fname):
+            return balls
+
+        for index, line in enumerate(file(fname)):
+            if not line:
+                continue
+            pos, radius, name = line.split(None, 2)
+            x, y = pos.split(',')
+            balls.append(Ball(x, y, radius, name.strip(), index))
+        return balls
+
+    def remove_fp(self, *args):
+        selection = self.treeview.get_selection()
+        model, path = selection.get_selected()
+        if path:
+            position = model[path][0]
+            for i in self.balls:
+                if i.position == int(position):
+                    self.balls.remove(i)
+            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
+
+            # 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):
+        selection = self.treeview.get_selection()
+        selection.select_path(str(ball.position))
+
+        # 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
+
+        # if the project has no
+        if self.project and not self.project.focus_points_file:
+            fc = gtk.FileChooserDialog(_('Save the focus points file'),
+                                       self.window,
+                                       action=gtk.FILE_CHOOSER_ACTION_SAVE,
+                                       buttons=(gtk.STOCK_CANCEL,
+                                                gtk.RESPONSE_CANCEL,
+                                                gtk.STOCK_SAVE,
+                                                gtk.RESPONSE_OK))
+            if fc.run() == gtk.RESPONSE_OK:
+                self.project.focus_points_file = fc.get_filename()
+                fc.destroy()
+            else:
+                fc.destroy()
+                return
+
+        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
+
+        for i in self.balls:
+            self.draw_ball(i)
+
+        if self.start_x < 0:
+            return False
+
+        if self.new_ball:
+            ball = Ball(self.start_x, self.start_y, self.radius)
+            self.draw_ball(ball)
+
+        return False
+
+    def point_with_border(self, ball):
+        iw, ih = self.draw.size_request()
+        w = self.draw.get_allocation().width
+        h = self.draw.get_allocation().height
+
+        x = ((w / 2) - (iw / 2)) + ball.p.x
+        y = ((h / 2) - (ih / 2)) + ball.p.y
+        return Point(x, y)
+
+    def point_without_border(self, point):
+        iw, ih = self.draw.size_request()
+        w = self.draw.get_allocation().width
+        h = self.draw.get_allocation().height
+
+        x = point.x - ((w / 2) - (iw / 2))
+        y = point.y - ((h / 2) - (ih / 2))
+        return Point(x, y)
+
+    def draw_ball(self, ball):
+        ctx = self.draw.window.cairo_create()
+        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()
+
+        if ball.selected:
+            ctx.set_source_rgba(0.0, 0.5, 0.0, 0.4)
+            ctx.set_line_width(5)
+            ctx.arc(self.point_with_border(ball).x,
+                    self.point_with_border(ball).y,
+                    ball.radius+1, 0, 64*math.pi)
+            ctx.stroke()
+
+    def button_press(self, widget, event):
+        self.new_ball = True
+
+        self.last_x = event.x
+        self.last_y = event.y
+
+        if event.button == 1:
+            for i in self.balls:
+                p1 = Point(event.x, event.y)
+                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
+                    self.select_fp_from_image(i)
+
+                    self.new_ball = False
+                    self.move_ball = i
+                    break
+
+            self.start_x = self.point_without_border(event).x
+            self.start_y = self.point_without_border(event).y
+
+    def button_release(self, widget, event):
+        self.move_ball = None
+
+        if event.button == 1:
+            self.finish_drawing()
+
+    def motion_notify(self, widget, event):
+        if not self.new_ball:
+            return
+
+        self.draw.queue_draw()
+
+        if event.x > self.last_x:
+            self.radius += 3
+        else:
+            self.radius -= 3
+
+        self.last_x = event.x
+
+    def ball_motion(self, widget, event):
+        if not self.move_ball:
+            return
+
+        self.move_ball.p.x = self.point_without_border(event).x
+        self.move_ball.p.y = self.point_without_border(event).y
+
+        self.draw.queue_draw()
+
+    def finish_drawing(self):
+        if self.new_ball:
+            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)
+            self.new_ball = False
+
+        # reseting to the default coordenades
+        self.start_x = -1
+        self.start_y = -1
+        self.radius = Ball.DEFAULT_WIDTH
+
+if __name__ == '__main__':
+    Gzv().show()
+    gtk.main()