[mousetrap/gnome3-wip] Migrate to Gtk3 and GObject introspection.



commit d326ff6884f683e3b4248c581c02f9b9765cb52f
Author: Logan Hotchkiss <lhotchkiss17 gmail com>
Date:   Wed Sep 18 09:25:52 2013 -0400

    Migrate to Gtk3 and GObject introspection.
    
    * Applied Joanie's GTK fix and fixed camera issue.
    * Update handler.py
    * Merged Nikki's fixes for window and button sizes
    * Fixed size of main window and Preff Buttons
    * Updated files for deprecations of Gtk.HBox, Gtk.VBox, and Gtk.HButtonBox
    * fixed Gtk.Table deprecation
    * Fix GdkPixbuf.InterpType typo.

 src/mousetrap/app/addons/handler.py      |    2 +-
 src/mousetrap/app/addons/recalc.py       |    5 +-
 src/mousetrap/app/environment.py.in      |    7 +-
 src/mousetrap/app/lib/mouse.py           |    8 +-
 src/mousetrap/app/ui/dialogs-newGTK.py   |  549 +++++++++++++++++++
 src/mousetrap/app/ui/dialogs.py          |  517 +++++++++---------
 src/mousetrap/app/ui/main.py             |  484 ++++++++---------
 src/mousetrap/app/ui/scripts/joystick.py |    3 +-
 src/mousetrap/app/ui/settings_gui.py     |  853 +++++++++++++++---------------
 src/mousetrap/app/ui/widgets.py          |   34 +-
 src/mousetrap/ocvfw/_ocv.py              |    8 +-
 src/mousetrap/ocvfw/dev/camera.py        |   26 +-
 12 files changed, 1524 insertions(+), 972 deletions(-)
---
diff --git a/src/mousetrap/app/addons/handler.py b/src/mousetrap/app/addons/handler.py
index 7eba1ce..8afdfa7 100644
--- a/src/mousetrap/app/addons/handler.py
+++ b/src/mousetrap/app/addons/handler.py
@@ -98,4 +98,4 @@ class AddonsBase(object):
         - self: The main object pointer.
         - item: The item to add.
         """
-        self.itf.adds_vbox.pack_start(item, True, True)
+        self.itf.addonBox.add(item)
diff --git a/src/mousetrap/app/addons/recalc.py b/src/mousetrap/app/addons/recalc.py
index a42f1ee..d767b21 100644
--- a/src/mousetrap/app/addons/recalc.py
+++ b/src/mousetrap/app/addons/recalc.py
@@ -19,7 +19,8 @@
 # along with mouseTrap.  If not, see <http://www.gnu.org/licenses/>.
 
 import os
-import gtk, gobject
+from gi.repository import Gtk
+from gi.repository import GObject
 import mousetrap.app.debug as debug
 import mousetrap.app.environment as env
 
@@ -38,7 +39,7 @@ class Addon(AddonsBase):
 
         if self.cfg.getboolean("main", "startCam") and \
                 self.cfg.get("main", "algorithm") == "forehead":
-            self.button = gtk.Button(_("Recalc Point"))
+            self.button = Gtk.Button(_("Recalc Point"))
             self.button.connect("clicked", self.recalc)
             self.button.show()
             self.add_item(self.button)
diff --git a/src/mousetrap/app/environment.py.in b/src/mousetrap/app/environment.py.in
index 8073684..4ea688d 100644
--- a/src/mousetrap/app/environment.py.in
+++ b/src/mousetrap/app/environment.py.in
@@ -28,7 +28,7 @@ __license__   = "GPLv2"
 
 import sys
 import os
-import gtk
+from gi.repository import Gdk
 
 ## MouseTrap's PID
 pid = os.getpid()
@@ -89,8 +89,9 @@ debugFile = configPath + "mouseTrap.debug"
 langPath = "%s/locale/" % datadirname
 
 ## Screen Resolution
-screen       = { 'width'  : gtk.gdk.screen_width(),
-                 'height' : gtk.gdk.screen_height()}
+defaultScreen = Gdk.Screen.get_default()
+screen       = { 'width'  : defaultScreen.width(),
+                 'height' : defaultScreen.height()}
 
 ## Mose Movement Modes
 mouseModes = { }
diff --git a/src/mousetrap/app/lib/mouse.py b/src/mousetrap/app/lib/mouse.py
index 07efcfb..f678aee 100644
--- a/src/mousetrap/app/lib/mouse.py
+++ b/src/mousetrap/app/lib/mouse.py
@@ -26,8 +26,10 @@ __date__      = "$Date$"
 __copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
 __license__   = "GPLv2"
 
-import gtk
 import pyatspi
+#import gtk #FIXME: Remove this
+from gi.repository import Gdk
+from gi.repository import Gtk
 import mousetrap.app.debug as debug
 import mousetrap.app.environment as env
 import Xlib.ext.xtest as xtest
@@ -45,7 +47,9 @@ clickType = { 'p' : [ X.ButtonPress ],
 
 
 ## GTK Display for any user
-gtkDisplay = gtk.gdk.Display( "" )
+#FIXME: Swap these
+#gtkDisplay = gtk.gdk.Display( "" )
+gtkDisplay = Gdk.Display()
 
 ## X Display for non gnome users
 xDisplay   = display.Display()
diff --git a/src/mousetrap/app/ui/dialogs-newGTK.py b/src/mousetrap/app/ui/dialogs-newGTK.py
new file mode 100644
index 0000000..a7f6061
--- /dev/null
+++ b/src/mousetrap/app/ui/dialogs-newGTK.py
@@ -0,0 +1,549 @@
+# -*- coding: utf-8 -*-
+
+# MouseTrap
+#
+# Copyright 2009 Flavio Percoco Premoli
+#
+# This file is part of mouseTrap.
+#
+# MouseTrap is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License v2 as published
+# by the Free Software Foundation.
+#
+# mouseTrap 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with mouseTrap.  If not, see <http://www.gnu.org/licenses/>.
+
+""" A group of formated dialogs functions used by mousetrap. """
+
+__id__        = "$Id$"
+__version__   = "$Revision$"
+__date__      = "$Date$"
+__copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
+__license__   = "GPLv2"
+
+from gi.repository import Gtk
+from i18n import _
+
+def addLabelMessage( dialog, message ):
+    """
+    Adds a label to the dialog
+
+    Arguments:
+    - dialog: The dialog object pointer.
+    - message: The dialog message
+    """
+
+    label = Gtk.Label()
+    label.set_use_markup(True)
+    label.set_markup('<span>' + \
+        message + "</span>")
+    label.show()
+    dialog.hbox.pack_start(label, True, True, 0)
+
+def addImage( dialog, stockImage, stock=False):
+    """
+    Adds an image to a dialog.
+
+    Arguments:
+    - dialog: The dialog object pointer.
+    - stockImage: The image to set.
+    - stock. is it a stock image? False if it isn't.
+    """
+
+    image = Gtk.Image()
+    if stock:
+        image.set_from_stock( stockImage, Gtk.IconSize.DIALOG )
+    else:
+        pass
+    image.set_alignment( 0.0, 0.5 )
+    image.show()
+    dialog.hbox.pack_start(image, True, True, 0)
+
+def confirmDialog( message, parent ):
+    """
+    Creates a confirmation dialog.
+
+    Arguments:
+    - message: The dialog message
+    - parent: The parent window. None if there's not one.
+    """
+
+    dialog = createDialog( _( "Confirmation Dialog" ), parent,
+                            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, \
+                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, \
+                            Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
+    addImage( dialog, Gtk.STOCK_DIALOG_WARNING, True)
+    addLabelMessage( dialog, message )
+    return dialog.run()
+
+def errorDialog( message, parent ):
+    """
+    Creates an error dialog using the messageDialog function.
+
+    Arguments:
+    - message: The dialog message
+    - parent: The parent window. None if there's not one.
+    """
+    return messageDialog( _("Error Dialog"), message, parent,  Gtk.STOCK_DIALOG_ERROR )
+
+def warningDialog( message, parent ):
+    """
+    Creates a warning dialog using the messageDialog function.
+
+    Arguments:
+    - message: The dialog message
+    - parent: The parent window. None if there's not one.
+    """
+    return messageDialog( _("Information Dialog"), message, parent,  Gtk.STOCK_DIALOG_WARNING )
+
+def informationDialog( message, parent ):
+    """
+    Creates an information dialog using the messageDialog function.
+
+    Arguments:
+    - message: The dialog message
+    - parent: The parent window. None if there's not one.
+    """
+    return messageDialog( _("Information Dialog"), message, parent,  Gtk.STOCK_DIALOG_INFO )
+
+def messageDialog( title, message, parent, stockImage, stock = True ):
+    """
+    Creates a simple message dialog. E.g: Error, Warnings, Informations.
+
+    Arguments:
+    - title: The dialog title.
+    - message: The dialog message.
+    - parent: The parent Window, None if there's not one.
+    - stockImage: The image to show.
+    - stock: If the image is a stock image.
+    """
+    dialog = createDialog( title, parent, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, \
+                            (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
+
+    addImage( dialog, stockImage, stock)
+    addLabelMessage( dialog, message )
+    return dialog.run()
+
+def closeDialog( dialog, *args ):
+    """
+    Close Function for dialogs.
+
+    Arguments:
+    - dialog: the dialog to destroy.
+    - *args: The widget event arguments.
+    """
+    dialog.destroy()
+
+def createDialog( title, parent, flags, buttons ):
+    """
+    Creates a Dialog Window.
+
+    Arguments:
+    - self: The main object pointer.
+    - title: The Dialog window Title
+    - parent: The parent window.
+    - message: A message to show in the dialog.
+    - stockImage: A GTK+ stock image.
+    - flags: gtk.Dialog Flags to set the typo of dialog. E.g: gtk.DIALOG_MODAL | 
gtk.DIALOG_DESTROY_WITH_PARENT
+    - buttons: A tuple with the gtk.Buttons to show. E.g: ( gtk.STOCK_OK, gtk.STOCK_CANCEL )
+    """
+
+    # For some reason pylint says that a VBox doesn't have a set_spacing or pack_start member.
+    # pylint: disable-msg=E1101
+    # createDialog: Class 'vbox' has no 'set_spacing' member
+    # createDialog: Class 'vbox' has no 'pack_start' member
+    dialog = Gtk.Dialog( title, parent, flags, buttons )
+    dialog.set_default_size(150, 100)
+    dialog.set_position(Gtk.WindowPosition.CENTER)
+    dialog.set_border_width(8)
+    dialog.vbox.set_spacing ( 4 )
+
+    hbox = Gtk.HBox(spacing=4)
+
+    #bbox = gtk.HButtonBox()
+    #bbox.set_spacing(4)
+    #bbox.set_layout(gtk.BUTTONBOX_END)
+
+    dialog.vbox.pack_start(hbox, True, True, 0)
+    # pylint: enable-msg=E1101
+    # createDialog: Class 'vbox' has no 'set_spacing' member
+    # createDialog: Class 'vbox' has no 'pack_start' member
+
+    #vbox.pack_start(bbox, False)
+
+    #dialog.add(vbox)
+
+    #setattr(dialog, 'vbox', vbox)
+    setattr(dialog, 'hbox', hbox)
+    #setattr(dialog, 'bbox', bbox)
+
+    #args = list(args)
+    #args.insert(0, stock.CLOSE)
+    dialog.connect('delete-event', closeDialog, dialog)
+
+    dialog.show_all()
+    return dialog
+
+class IdmSettings(Gtk.Window):
+
+    def __init__(self, cfg, name, stgs):
+        """
+        Idm Settings window.
+
+        Arguments:
+        self: The main object pointer.
+        cfg: The config object.
+        stgs: The idm's settings dict to parse.
+        """
+        GObject.GObject.__init__(self)
+
+        self.cfg = cfg
+        self.idm_stgs = eval(stgs)
+        self.idm = name.lower()
+        self.tmp = {}
+
+        #self.set_size_request( 500 , 120)
+        #self.set_default_size( 500 , 120)
+        self.set_title(_("%s Config's Dialog" % self.idm.capitalize()))
+
+        self.main_vbox = Gtk.VBox(spacing=6)
+        self.add_widgets()
+
+        buttons_box = Gtk.HBox(spacing=6)
+
+        button = Gtk.Button( _("Accept"), stock=Gtk.STOCK_OK )
+        button.connect("clicked", self.accept_button)
+        buttons_box.pack_start(button, False, False, 0)
+
+        button = Gtk.Button( _("Cancel"), stock=Gtk.STOCK_CANCEL )
+        button.connect("clicked", self.cancel_button)
+        buttons_box.pack_start(button, False, False, 0)
+
+        buttons_box.show_all()
+
+        self.main_vbox.pack_start(buttons_box, False, False, 0)
+
+        self.main_vbox.show_all()
+        self.show_all()
+        self.add(self.main_vbox)
+
+        if not self.cfg.has_section(self.idm):
+            self.cfg.add_section(self.idm)
+
+    def accept_button(self, widget, *args):
+        for key in self.tmp:
+            self.cfg.set(self.idm, key, self.tmp[key])
+        self.destroy()
+
+    def cancel_button(self, widget, *args):
+        self.destroy()
+
+    def add_widgets(self):
+        """
+        Adds dinamicaly the widgets to the dialog.
+
+        Arguments:
+        - self: The main object pointer.
+        """
+        for key in self.idm_stgs:
+            self.main_vbox.pack_start(self.create_labled_input(key, True, True, 0), False, False, 0)
+
+    def value_changed(self, widget, key):
+        self.tmp[key] = widget.get_text()
+
+    def create_labled_input(self, key):
+        """
+        Creates a textbox with a lable.
+
+        Arguments:
+        - self: The main object pointer.
+        - key: The parent key.
+        """
+        hbox = Gtk.HBox()
+        label = Gtk.Label(_(key.capitalize()))
+        label.set_use_underline( True )
+        label.show()
+        hbox.pack_start(label, True, True, 0)
+
+        val = str(self.idm_stgs[key]["value"])
+        if self.cfg.get(self.idm, key):
+            val = self.cfg.get(self.idm, key)
+
+        entry = Gtk.Entry()
+        entry.set_text(val)
+        entry.connect("changed", self.value_changed, key)
+        entry.show()
+        hbox.pack_start(entry, True, True, 0)
+        hbox.show_all()
+        return hbox
+
+###############################################
+#                                             #
+#    THE WHEEL HAS ALREADY BEEN DISCOVERED    #
+#     SO, LETS USE MOUSETWEAK INSTEAD OF      #
+#      ADD THIS SUPPORT TO MOUSETRAP.         #
+###############################################
+# class ClicksDialog( gtk.Window ):
+#     """
+#     A Class for the Click Dialog.
+#
+#     Arguments:
+#     - gtk.Window: Window for the buttons.
+#     """
+#
+#     def __init__( self, gui ):
+#         """
+#         Initialize the Clicks Dialog.
+#
+#         Arguments:
+#         - self: The main object pointer.
+#         - mouseTrap: The mouseTrap object pointer.
+#         - cAm: The camera object pointer
+#         """
+#
+#         gtk.Window.__init__( self )
+#
+#         self.gui = gui
+#
+#         self.set_property("skip-taskbar-hint", True)
+#         self.set_keep_above( True )
+#         self.set_size_request( 500 , 120)
+#         self.set_default_size( 500 , 120)
+#         self.width, self.height = self.get_default_size()
+#
+#         self.set_title(_('Clicks Panel'))
+#
+#         self.set_app_paintable(True)
+#         #self.set_decorated(False)
+#
+#         self.buttons = []
+#         self.blue  = '#1161d9'
+#         self.green = '#60da11'
+#         evtBox = gtk.EventBox()
+#
+#         buttonsBox = gtk.HBox( spacing = 6 )
+#         buttonsBox.show_all()
+#
+#         self.leftClick = gtk.Button()
+#         self.leftClick.add(self._newImageButton(_("Left Click"),
+#                                                   "%s/images/leftClick.png" % env.mTDataDir))
+#         self.leftClick.connect("clicked", self.executeClick, 'b1c')
+#         self.leftClick.show()
+#         self.buttons.append( self.leftClick )
+#         buttonsBox.pack_start( self.leftClick )
+#
+#         self.doubleClick = gtk.Button()
+#         self.doubleClick.add(self._newImageButton(_("Double Click"),
+#                                                     "%s/images/doubleClick.png" % env.mTDataDir))
+#         self.doubleClick.connect("clicked", self.executeClick, 'b1d')
+#         self.doubleClick.show()
+#         self.buttons.append( self.doubleClick )
+#         buttonsBox.pack_start( self.doubleClick )
+#
+#         self.leftHold = gtk.Button()
+#         self.leftHold.add(self._newImageButton(_("Drag/Drop Click"),
+#                                                  "%s/images/leftHold.png" % env.mTDataDir))
+#         self.leftHold.connect("clicked", self.executeClick, 'b1p')
+#         self.leftHold.show()
+#         self.buttons.append( self.leftHold )
+#         buttonsBox.pack_start( self.leftHold )
+#
+#         #~ self.middleClick = gtk.Button()
+#         #~ self.middleClick.add(self._newImageButton(_("Middle Click"), "%s/images/middleClick.png" % 
env.mTDataDir))
+#         #~ self.middleClick.connect("clicked", self.executeClick, 'b2c')
+#         #~ self.middleClick.show()
+#         #~ self.buttons.append( self.middleClick )
+#         #~ buttonsBox.pack_start( self.middleClick )
+#
+#         self.rightClick = gtk.Button()
+#         self.rightClick.add(self._newImageButton(_("Right Click"),
+#                                                    "%s/images/rightClick.png" % env.mTDataDir))
+#         self.rightClick.connect("clicked", self.executeClick, 'b3c')
+#         self.rightClick.show()
+#         self.buttons.append( self.rightClick )
+#         buttonsBox.pack_start( self.rightClick )
+#
+#         self.add( buttonsBox  )
+#
+#     def showPanel( self ):
+#         """
+#         Shows the panel
+#
+#         Arguments:
+#         - self: The main object pointer.
+#         """
+#
+#         X = Y = 0
+#
+#         poss = mouseTrap.mice( "position" )
+#
+#         # We'll change the click panel position to be sure that
+#         # it won't appear under another window or worse under a
+#         # popup menu.
+#         if poss[0] in xrange( env.screen["width"]/2 ):
+#             X = env.screen["width"] - self.width
+#
+#
+#         if poss[1] in xrange( env.screen["height"]/2 ):
+#             Y = env.screen["height"] - self.height
+#
+#
+#         self.move(X, Y)
+#
+#         if self.get_focus():
+#             self.buttons[ self.buttons.index(self.get_focus()) ].get_child().modify_bg( gtk.STATE_NORMAL,
+#                                                                                         
gtk.gdk.color_parse(self.blue))
+#
+#         self.set_focus(self.buttons[0])
+#         self.buttons[0].get_child().modify_bg( gtk.STATE_NORMAL, gtk.gdk.color_parse(self.green))
+#         self.show_all()
+#
+#         mouseTrap.setState( "clk-dialog" )
+#
+#     def hidePanel( self, *args ):
+#         """
+#         Hides the panel
+#
+#         Arguments:
+#         - self: The main object pointer.
+#         - args: The event arguments
+#         """
+#         self.hide()
+#         mouseTrap.setState( "active" )
+#
+#     def pressButton( self, *args ):
+#         """
+#         Press the focused button
+#
+#         Arguments:
+#         - self: The main object pointer.
+#         - args: The event arguments
+#         """
+#
+#         self.get_focus().clicked()
+#
+#     def prevBtn( self, *args ):
+#         """
+#         Move to the prev button
+#
+#         Arguments:
+#         - self: The main object pointer.
+#         - args: The event arguments
+#         """
+#
+#         self.buttons[ self.buttons.index(self.get_focus()) ].get_child().modify_bg( gtk.STATE_NORMAL,
+#                                                                                     
gtk.gdk.color_parse(self.blue))
+#         self.buttons[ self.buttons.index(self.get_focus()) - 1 ].grab_focus()
+#         self.buttons[ self.buttons.index(self.get_focus()) ].get_child().modify_bg( gtk.STATE_NORMAL,
+#                                                                                     
gtk.gdk.color_parse(self.green))
+#
+#     def nextBtn( self, *args ):
+#         """
+#         Move to the next button
+#
+#         Arguments:
+#         - self: The main object pointer.
+#         - args: The event arguments
+#         """
+#
+#         index = self.buttons.index(self.get_focus()) + 1
+#         if index >= len(self.buttons):
+#             index = 0
+#         self.buttons[ index -1 ].get_child().modify_bg( gtk.STATE_NORMAL,
+#                                                         gtk.gdk.color_parse(self.blue))
+#         self.buttons[ index ].grab_focus()
+#         self.buttons[ index ].get_child().modify_bg( gtk.STATE_NORMAL,
+#                                                      gtk.gdk.color_parse(self.green))
+#
+#     def executeClick( self, widget, button ):
+#         """
+#         Execute the selected click
+#
+#         Arguments:
+#         - self: The main object pointer.
+#         - widget: The button clicked.
+#         - button: The mouse button that should be pressed.
+#         """
+#
+#         self.gui.clickDlgHandler( button )
+#         self.hidePanel()
+#
+#     def _newImageButton( self, label, image ):
+#         """
+#         Creates an image button from an image file
+#
+#         Arguments:
+#         - self: The main object pointer
+#         - label: The buttons label
+#         - image: The image path
+#
+#         Returns ButtonLabelBox A gtk.HBox that contains the new image stock button.
+#         """
+#         evt = gtk.EventBox()
+#
+#         buttonLabelBox = gtk.VBox()
+#
+#         im = gtk.Image()
+#         im.set_from_file( image )
+#         im.show
+#
+#         label = gtk.Label( label )
+#         label.set_alignment( 0.0, 0.5 )
+#         label.set_use_underline( True )
+#
+#         buttonLabelBox.pack_start( im )
+#         buttonLabelBox.pack_start( label )
+#         buttonLabelBox.show_all()
+#
+#         evt.add(buttonLabelBox)
+#         evt.modify_bg( gtk.STATE_NORMAL, gtk.gdk.color_parse(self.blue))
+#         evt.modify_bg( gtk.STATE_PRELIGHT, gtk.gdk.color_parse(self.green))
+#         return evt
+
+
+class CairoTransGui( Gtk.Window ):
+
+    def __init__( self, message ):
+        GObject.GObject.__init__(self)
+
+        self.set_property("skip-taskbar-hint", True)
+        self.connect("expose-event", self.expose)
+        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
+        self.connect('button-press-event', self.clicked)
+        self.set_size_request( 700 , 100)
+        #self.connect('screen-changed', self.screenChanged)
+
+        self.set_title('MouseTrap Message!!!')
+
+
+        self.set_app_paintable(True)
+        self.set_decorated(False)
+
+        self.message = message
+
+        self.show_all()
+
+    def expose( self, widget, event):
+
+        cr = widget.window.cairo_create()
+
+        cr.set_operator(1)
+        cr.paint()
+
+        cr.set_source_rgba (255.0, 255.0, 255.0, 100.0)
+        cr.set_font_size (50)
+        cr.move_to (0, 70)
+        cr.show_text (self.message)
+        cr.fill()
+        cr.stroke()
+        return False
+
+    def clicked(self, widget, event):
+        #If a shift key is pressed, start resizing
+        self.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time)
+
diff --git a/src/mousetrap/app/ui/dialogs.py b/src/mousetrap/app/ui/dialogs.py
index c99e4e9..4e9ec3e 100644
--- a/src/mousetrap/app/ui/dialogs.py
+++ b/src/mousetrap/app/ui/dialogs.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
 # MouseTrap
 #
 # Copyright 2009 Flavio Percoco Premoli
@@ -27,260 +25,254 @@ __copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
 __license__   = "GPLv2"
 
 from gi.repository import Gtk
-from .i18n import _
+from i18n import _
 
 def addLabelMessage( dialog, message ):
-    """
-    Adds a label to the dialog
+       """
+       Adds a label to the dialog
 
-    Arguments:
-    - dialog: The dialog object pointer.
-    - message: The dialog message
-    """
+       Arguments:
+       - dialog: The dialog object pointer.
+       - message: The dialog message
+       """
 
-    label = gtk.Label()
-    label.set_use_markup(True)
-    label.set_markup('<span>' + \
-        message + "</span>")
-    label.show()
-    dialog.hbox.pack_start(label)
+       label = Gtk.Label()
+       label.set_use_markup(True)
+       label.set_markup("<span>" + message + "</span>")
+       label.show()
+#      dialog.hbox.attach(label, left=, top=, width=, height=, )
 
 def addImage( dialog, stockImage, stock=False):
-    """
-    Adds an image to a dialog.
-
-    Arguments:
-    - dialog: The dialog object pointer.
-    - stockImage: The image to set.
-    - stock. is it a stock image? False if it isn't.
-    """
-
-    image = gtk.Image()
-    if stock:
-        image.set_from_stock( stockImage, gtk.ICON_SIZE_DIALOG )
-    else:
-        pass
-    image.set_alignment( 0.0, 0.5 )
-    image.show()
-    dialog.hbox.pack_start(image)
+       """
+       Adds an image to a dialog.
+
+       Arguments:
+       - dialog: The dialog object pointer.
+       - stockImage: The image to set.
+       - stock. is it a stock image? False if it isn't.
+       """
+
+       image = Gtk.Image()
+       if stock:
+               image.set_from_stock( stockImage, Gtk.IconSize.DIALOG )
+       else:
+               pass
+       image.set_alignment( 0.0, 0.5 )
+       image.show()
+#      dialog.hbox.attach(label, left=, top=, width=, height=, )
 
 def confirmDialog( message, parent ):
-    """
-    Creates a confirmation dialog.
-
-    Arguments:
-    - message: The dialog message
-    - parent: The parent window. None if there's not one.
-    """
-
-    dialog = createDialog( _( "Confirmation Dialog" ), parent,
-                            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, \
-                            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, \
-                            gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
-    addImage( dialog, gtk.STOCK_DIALOG_WARNING, True)
-    addLabelMessage( dialog, message )
-    return dialog.run()
+       """
+       Creates a confirmation dialog.
+
+       Arguments:
+       - message: The dialog message
+       - parent: The parent window. None if there's not one.
+       """
+
+       dialog = createDialog( _( "Confirmation Dialog" ), parent,
+                               Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, \
+                               (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, \
+                               Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
+       addImage( dialog, Gtk.STOCK_DIALOG_WARNING, True)
+       addLabelMessage( dialog, message )
+       return dialog.run()
 
 def errorDialog( message, parent ):
-    """
-    Creates an error dialog using the messageDialog function.
+       """
+       Creates an error dialog using the messageDialog function.
 
-    Arguments:
-    - message: The dialog message
-    - parent: The parent window. None if there's not one.
-    """
-    return messageDialog( _("Error Dialog"), message, parent,  gtk.STOCK_DIALOG_ERROR )
+       Arguments:
+       - message: The dialog message
+       - parent: The parent window. None if there's not one.
+       """
+       return messageDialog( _("Error Dialog"), message, parent,  Gtk.STOCK_DIALOG_ERROR )
 
 def warningDialog( message, parent ):
-    """
-    Creates a warning dialog using the messageDialog function.
+       """
+       Creates a warning dialog using the messageDialog function.
 
-    Arguments:
-    - message: The dialog message
-    - parent: The parent window. None if there's not one.
-    """
-    return messageDialog( _("Information Dialog"), message, parent,  gtk.STOCK_DIALOG_WARNING )
+       Arguments:
+       - message: The dialog message
+       - parent: The parent window. None if there's not one.
+       """
+       return messageDialog( _("Information Dialog"), message, parent,  Gtk.STOCK_DIALOG_WARNING )
 
 def informationDialog( message, parent ):
-    """
-    Creates an information dialog using the messageDialog function.
+       """
+       Creates an information dialog using the messageDialog function.
 
-    Arguments:
-    - message: The dialog message
-    - parent: The parent window. None if there's not one.
-    """
-    return messageDialog( _("Information Dialog"), message, parent,  gtk.STOCK_DIALOG_INFO )
+       Arguments:
+       - message: The dialog message
+       - parent: The parent window. None if there's not one.
+       """
+       return messageDialog( _("Information Dialog"), message, parent,  Gtk.STOCK_DIALOG_INFO )
 
 def messageDialog( title, message, parent, stockImage, stock = True ):
-    """
-    Creates a simple message dialog. E.g: Error, Warnings, Informations.
-
-    Arguments:
-    - title: The dialog title.
-    - message: The dialog message.
-    - parent: The parent Window, None if there's not one.
-    - stockImage: The image to show.
-    - stock: If the image is a stock image.
-    """
-    dialog = createDialog( title, parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, \
-                            (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
-
-    addImage( dialog, stockImage, stock)
-    addLabelMessage( dialog, message )
-    return dialog.run()
+       """
+       Creates a simple message dialog. E.g: Error, Warnings, Informations.
+
+       Arguments:
+       - title: The dialog title.
+       - message: The dialog message.
+       - parent: The parent Window, None if there's not one.
+       - stockImage: The image to show.
+       - stock: If the image is a stock image.
+       """
+       dialog = createDialog( title, parent, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, \
+                               (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
+
+       addImage( dialog, stockImage, stock)
+       addLabelMessage( dialog, message )
+       return dialog.run()
 
 def closeDialog( dialog, *args ):
-    """
-    Close Function for dialogs.
+       """
+       Close Function for dialogs.
 
-    Arguments:
-    - dialog: the dialog to destroy.
-    - *args: The widget event arguments.
-    """
-    dialog.destroy()
+       Arguments:
+       - dialog: the dialog to destroy.
+       - *args: The widget event arguments.
+       """
+       dialog.destroy()
 
 def createDialog( title, parent, flags, buttons ):
-    """
-    Creates a Dialog Window.
-
-    Arguments:
-    - self: The main object pointer.
-    - title: The Dialog window Title
-    - parent: The parent window.
-    - message: A message to show in the dialog.
-    - stockImage: A GTK+ stock image.
-    - flags: gtk.Dialog Flags to set the typo of dialog. E.g: gtk.DIALOG_MODAL | 
gtk.DIALOG_DESTROY_WITH_PARENT
-    - buttons: A tuple with the gtk.Buttons to show. E.g: ( gtk.STOCK_OK, gtk.STOCK_CANCEL )
-    """
-
-    # For some reason pylint says that a VBox doesn't have a set_spacing or pack_start member.
-    # pylint: disable-msg=E1101
-    # createDialog: Class 'vbox' has no 'set_spacing' member
-    # createDialog: Class 'vbox' has no 'pack_start' member
-    dialog = gtk.Dialog( title, parent, flags, buttons )
-    dialog.set_default_size(150, 100)
-    dialog.set_position(gtk.WIN_POS_CENTER)
-    dialog.set_border_width(8)
-    dialog.vbox.set_spacing ( 4 )
-
-    hbox = gtk.HBox(spacing=4)
-
-    #bbox = gtk.HButtonBox()
-    #bbox.set_spacing(4)
-    #bbox.set_layout(gtk.BUTTONBOX_END)
-
-    dialog.vbox.pack_start(hbox, True, True)
-    # pylint: enable-msg=E1101
-    # createDialog: Class 'vbox' has no 'set_spacing' member
-    # createDialog: Class 'vbox' has no 'pack_start' member
-
-    #vbox.pack_start(bbox, False)
-
-    #dialog.add(vbox)
-
-    #setattr(dialog, 'vbox', vbox)
-    setattr(dialog, 'hbox', hbox)
-    #setattr(dialog, 'bbox', bbox)
-
-    #args = list(args)
-    #args.insert(0, stock.CLOSE)
-    dialog.connect('delete-event', closeDialog, dialog)
-
-    dialog.show_all()
-    return dialog
-
-class IdmSettings(gtk.Window):
-
-    def __init__(self, cfg, name, stgs):
-        """
-        Idm Settings window.
-
-        Arguments:
-        self: The main object pointer.
-        cfg: The config object.
-        stgs: The idm's settings dict to parse.
-        """
-        gtk.Window.__init__(self)
-
-        self.cfg = cfg
-        self.idm_stgs = eval(stgs)
-        self.idm = name.lower()
-        self.tmp = {}
-
-        #self.set_size_request( 500 , 120)
-        #self.set_default_size( 500 , 120)
-        self.set_title(_("%s Config's Dialog" % self.idm.capitalize()))
-
-        self.main_vbox = gtk.VBox(spacing=6)
-        self.add_widgets()
-
-        buttons_box = gtk.HBox(spacing=6)
-
-        button = gtk.Button( _("Accept"), stock=gtk.STOCK_OK )
-        button.connect("clicked", self.accept_button)
-        buttons_box.pack_start(button, False, False)
-
-        button = gtk.Button( _("Cancel"), stock=gtk.STOCK_CANCEL )
-        button.connect("clicked", self.cancel_button)
-        buttons_box.pack_start(button, False, False)
-
-        buttons_box.show_all()
-
-        self.main_vbox.pack_start(buttons_box, False, False)
-
-        self.main_vbox.show_all()
-        self.show_all()
-        self.add(self.main_vbox)
-
-        if not self.cfg.has_section(self.idm):
-            self.cfg.add_section(self.idm)
-
-    def accept_button(self, widget, *args):
-        for key in self.tmp:
-            self.cfg.set(self.idm, key, self.tmp[key])
-        self.destroy()
-
-    def cancel_button(self, widget, *args):
-        self.destroy()
-
-    def add_widgets(self):
-        """
-        Adds dinamicaly the widgets to the dialog.
-
-        Arguments:
-        - self: The main object pointer.
-        """
-        for key in self.idm_stgs:
-            self.main_vbox.pack_start(self.create_labled_input(key), False, False)
-
-    def value_changed(self, widget, key):
-        self.tmp[key] = widget.get_text()
-
-    def create_labled_input(self, key):
-        """
-        Creates a textbox with a lable.
-
-        Arguments:
-        - self: The main object pointer.
-        - key: The parent key.
-        """
-        hbox = gtk.HBox()
-        label = gtk.Label(_(key.capitalize()))
-        label.set_use_underline( True )
-        label.show()
-        hbox.pack_start(label, True, True)
-
-        val = str(self.idm_stgs[key]["value"])
-        if self.cfg.get(self.idm, key):
-            val = self.cfg.get(self.idm, key)
-
-        entry = gtk.Entry()
-        entry.set_text(val)
-        entry.connect("changed", self.value_changed, key)
-        entry.show()
-        hbox.pack_start(entry, True, True)
-        hbox.show_all()
-        return hbox
+       """
+       Creates a Dialog Window.
+
+       Arguments:
+       - self: The main object pointer.
+       - title: The Dialog window Title
+       - parent: The parent window.
+       - message: A message to show in the dialog.
+       - stockImage: A GTK+ stock image.
+       - flags: gtk.Dialog Flags to set the typo of dialog. E.g: gtk.DIALOG_MODAL | 
gtk.DIALOG_DESTROY_WITH_PARENT
+       - buttons: A tuple with the gtk.Buttons to show. E.g: ( gtk.STOCK_OK, gtk.STOCK_CANCEL )
+       """
+
+       dialog = Gtk.Dialog(title, parent, flags, buttons)
+       dialog.set_default_size(150, 100)
+       dialog.set_position(Gtk.WindowPosition.CENTER)
+       dialog.set_border_width(8)
+       
+       vbox = Gtk.Grid()
+       vbox.set_column_spacing(4)
+       hbox = Gtk.Grid()
+       hbox.set_row_spacing(4)
+       bbox = Gtk.ButtonBox()
+       bbox.set_layout(Gtk.BUTTONBOX_END)
+       
+       vbox.add(hbox)
+       vbox.attach_next_to(bbox, hbox, Gtk.PositionType.BOTTOM, 1, 1)
+       dialog.add(vbox)
+       
+       setattr(dialog, 'vbox', vbox)
+       setattr(dialog, 'hbox', hbox)
+       setattr(dialog, 'bbox', bbox)
+       
+       args = list(args)
+       args.insert(0, stock.CLOSE)
+       dialog.connect('delete-event', closeDialog, dialog)
+       
+       dialog.show_all()
+       return dialog
+
+class IdmSettings(Gtk.Window):
+
+       def __init__(self, cfg, name, stgs):
+               """
+               Idm Settings window.
+
+               Arguments:
+               self: The main object pointer.
+               cfg: The config object.
+               stgs: The idm's settings dict to parse.
+               """
+               GObject.GObject.__init__(self)
+
+               self.cfg = cfg
+               self.idm_stgs = eval(stgs)
+               self.idm = name.lower()
+               self.tmp = {}
+
+               #self.set_size_request( 500 , 120)
+               self.set_default_size( 500 , 120)
+               self.set_title(_("%s Config's Dialog" % self.idm.capitalize()))
+
+               self.main_vbox = Gtk.Grid()
+               self.main_vbox.set_column_spacing(6)
+               self.add_widgets()
+               
+               buttons_box = Gtk.Grid()
+               buttons_box.set_row_spacing(6)
+               
+               button = Gtk.Button( _("Accept"), stock=Gtk.STOCK_OK )
+               button.connect("clicked", self.accept_button)
+               buttons_box.add(button)
+               
+               button = Gtk.Button( _("Cancel"), stock=Gtk.STOCK_CANCEL )
+               button.connect("clicked", self.cancel_button)
+               buttons_box.add(button)
+               
+               buttons_box.show_all()
+               
+               self.main_vbox.add(buttons_box)
+               
+               self.main_vbox.show_all()
+               # Switched the two lines below around.
+               self.add(self.main_vbox)
+               self.show_all()
+               
+               if not self.cfg.has_section(self.idm):
+                       self.cfg.add_section(self.idm)
+       
+       def accept_button(self, widget, *args):
+               for key in self.tmp:
+                       self.cfg.set(self.idm, key, self.tmp[key])
+               self.destroy()
+       
+       def cancel_button(self, widget, *args):
+               self.destroy()
+       
+       def add_widgets(self):
+               '''
+               Dynamically adds the widgets to the dialog.
+               
+               Arguments:
+               - self: The main object pointer.
+               '''
+               for key in self.idm_stgs:
+                       # This line might need to be edited..
+                       self.main_vbox.add(self.create_labled_input(key, True, True, 0))
+       
+       def value_changed(self, widget, key):
+               self.tmp[key] = widget.get_text()
+       
+       def create_labled_input(self, key):
+               '''
+               Creates a textbox with a label.
+               
+               Arguments:
+               - self: The main object pointer.
+               - key: The parent key.
+               '''
+               hbox = Gtk.Grid()
+               label = Gtk.Label( _(key.capitalize()) )
+               label.set_use_underline(True)
+               label.show()
+               hbox.add(label)
+               
+               val = str(self.idm_stgs[key]["value"])
+               if self.cfg.get(self.idm, key):
+                       val = self.cfg.get(self.idm, key)
+               
+               entry = Gtk.Entry()
+               entry.set_text(val)
+               entry.connect("changed", self.value_changed, key)
+               entry.show()
+               hbox.add(entry)
+               hbox.show_all()
+               return hbox
 
 ###############################################
 #                                             #
@@ -385,11 +377,11 @@ class IdmSettings(gtk.Window):
 #         # We'll change the click panel position to be sure that
 #         # it won't appear under another window or worse under a
 #         # popup menu.
-#         if poss[0] in range( env.screen["width"]/2 ):
+#         if poss[0] in xrange( env.screen["width"]/2 ):
 #             X = env.screen["width"] - self.width
 #
 #
-#         if poss[1] in range( env.screen["height"]/2 ):
+#         if poss[1] in xrange( env.screen["height"]/2 ):
 #             Y = env.screen["height"] - self.height
 #
 #
@@ -506,44 +498,43 @@ class IdmSettings(gtk.Window):
 #         return evt
 
 
-class CairoTransGui( gtk.Window ):
-
-    def __init__( self, message ):
-        gtk.Window.__init__(self)
+class CairoTransGui( Gtk.Window ):
 
-        self.set_property("skip-taskbar-hint", True)
-        self.connect("expose-event", self.expose)
-        self.add_events(gtk.gdk.BUTTON_PRESS_MASK)
-        self.connect('button-press-event', self.clicked)
-        self.set_size_request( 700 , 100)
-        #self.connect('screen-changed', self.screenChanged)
+       def __init__( self, message ):
+               GObject.GObject.__init__(self)
 
-        self.set_title('MouseTrap Message!!!')
+               self.set_property("skip-taskbar-hint", True)
+               self.connect("expose-event", self.expose)
+               self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
+               self.connect('button-press-event', self.clicked)
+               self.set_size_request( 700 , 100)
+               #self.connect('screen-changed', self.screenChanged)
 
+               self.set_title('MouseTrap Message!!!')
 
-        self.set_app_paintable(True)
-        self.set_decorated(False)
 
-        self.message = message
+               self.set_app_paintable(True)
+               self.set_decorated(False)
 
-        self.show_all()
+               self.message = message
 
-    def expose( self, widget, event):
+               self.show_all()
 
-        cr = widget.window.cairo_create()
+       def expose( self, widget, event):
 
-        cr.set_operator(1)
-        cr.paint()
+               cr = widget.window.cairo_create()
 
-        cr.set_source_rgba (255.0, 255.0, 255.0, 100.0)
-        cr.set_font_size (50)
-        cr.move_to (0, 70)
-        cr.show_text (self.message)
-        cr.fill()
-        cr.stroke()
-        return False
+               cr.set_operator(1)
+               cr.paint()
 
-    def clicked(self, widget, event):
-        #If a shift key is pressed, start resizing
-        self.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time)
+               cr.set_source_rgba (255.0, 255.0, 255.0, 100.0)
+               cr.set_font_size (50)
+               cr.move_to (0, 70)
+               cr.show_text (self.message)
+               cr.fill()
+               cr.stroke()
+               return False
 
+       def clicked(self, widget, event):
+               #If a shift key is pressed, start resizing
+               self.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time)
diff --git a/src/mousetrap/app/ui/main.py b/src/mousetrap/app/ui/main.py
index e29fbdc..6fe8466 100644
--- a/src/mousetrap/app/ui/main.py
+++ b/src/mousetrap/app/ui/main.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
 # MouseTrap
 #
 # Copyright 2009 Flavio Percoco Premoli
@@ -18,8 +16,7 @@
 # You should have received a copy of the GNU General Public License
 # along with mouseTrap.  If not, see <http://www.gnu.org/licenses/>.
 
-
-"""The main GUI of mousetrap."""
+""" The main GUI of mousetrap. """
 
 __id__        = "$Id$"
 __version__   = "$Revision$"
@@ -31,254 +28,241 @@ from gi.repository import Gdk
 from gi.repository import GObject
 from gi.repository import Gtk
 from gi.repository import GdkPixbuf
-from . import dialogs
-from . import settings_gui
+import dialogs
+import settings_gui
 import mousetrap.app.debug as debug
 import mousetrap.app.environment as env
 from mousetrap.app.addons import cpu
 
-class MainGui( gtk.Window ):
-    """
-    MouseTrap main GUI Class
-    """
-
-    def __init__( self, controller ):
-        """
-        The main GUI constructor
-
-        Arguments:
-        - self: The main object pointer
-        - controller: The mouseTrap's controller.
-        """
-
-        gtk.Window.__init__( self )
-        self.ctr    = controller
-        self.cfg    = controller.cfg
-        self.script = self.ctr.script()
-        #self.set_default_size(200, 400)
-
-    def setWindowsIcon( self ):
-        """
-        Sets the mainGui icon
-
-        Arguments:
-        - self: The main object pointer
-        """
-
-        icon_theme = gtk.icon_theme_get_default()
-        try:
-            icon = icon_theme.load_icon("mousetrap", 48, 0)
-        except:
-            return
-
-        gtk.window_set_default_icon(icon)
-
-
-    def build_interface( self ):
-        """
-        Builds the interface
-
-        Arguments:
-        - self: The main object pointer
-        """
-
-        self.setWindowsIcon()
-
-        accelGroup = gtk.AccelGroup()
-        self.add_accel_group( accelGroup )
-
-        self.accelGroup = accelGroup
-
-        self.set_title( "MouseTrap" )
-        self.connect( "destroy", self.close)
-        self.setWindowsIcon()
-
-        self.vBox = gtk.VBox()
-
-        self.buttonsBox = gtk.HButtonBox()
-        #self.buttonsBox = gtk.HBox(False,0)
-
-        self.prefButton = gtk.Button(stock=gtk.STOCK_PREFERENCES)
-        self.prefButton.connect("clicked", self._show_settings_gui)
-        self.buttonsBox.pack_start( self.prefButton, True, True )
-
-        self.closeButton = gtk.Button(stock=gtk.STOCK_QUIT)
-        self.closeButton.connect("clicked", self.close)
-        self.buttonsBox.pack_start( self.closeButton, True, True )
-
-        self.helpButton = gtk.Button(stock=gtk.STOCK_HELP)
-        self.helpButton.connect("clicked", self._loadHelp)
-        self.buttonsBox.pack_start( self.helpButton, True, True )
-
-        self.vBox.pack_start( self.buttonsBox, False, False )
-
-        self.adds_vbox = gtk.VBox()
-        self.adds_vbox.show_all()
-        self.vBox.pack_start( self.adds_vbox, False, False )
-
-        self.cap_image    = gtk.Image()
-
-        if self.cfg.getboolean("gui", "showCapture"):
-            self.cap_expander = gtk.expander_new_with_mnemonic("_Camera Image")
-            self.cap_expander.add(self.cap_image)
-            self.cap_expander.set_expanded(True)
-            #expander.connect('notify::expanded', self.expanded_cb)
-            self.vBox.pack_start(self.cap_expander)
-
-        if self.cfg.getboolean("gui", "showPointMapper"):
-            self.map_expander = gtk.expander_new_with_mnemonic("_Script Mapper")
-            self.map_expander.add(self.script)
-            self.map_expander.set_expanded(True)
-            #expander.connect('notify::expanded', self.expanded_cb)
-            self.vBox.pack_start(self.map_expander)
-
-#
-#         flipButton = gtk.Button( _("Flip Image") )
-#         flipButton.connect("clicked", self.recalcPoint, "flip" )
-#         hBox.pack_start( flipButton, False, False )
-#
-#         recalcButton = gtk.Button( _("Recalc Point") )
-#         recalcButton.connect("clicked", self.recalcPoint )
-#         hBox.pack_start( recalcButton, False, False )
-#
-#         self.vBox.pack_end(hBox, False, False )
-#
-#         self.buttonsBox.show_all()
-
-        self.statusbar = gtk.Statusbar()
-        self.statusbar_id = self.statusbar.get_context_id("statusbar")
-
-        self.vBox.pack_start(self.statusbar, True, True)
-
-        self.vBox.show_all()
-        self.add(self.vBox)
-        self.show()
-        
-        debug.debug("ui.main", "Interface Built")
-
-
-    def load_addons(self):
-        """
-        Loads the enabled addons
-         
-        Arguments:
-        - self: The main object pointer.
-        """
-
-        for add in self.cfg.getList("main", "addon"):
-            tmp = __import__("mousetrap.app.addons.%s" % add,
-                    globals(), locals(),[''])
-
-            setattr(self, add, tmp.Addon(self.ctr))
-        debug.debug("ui.main", "Addons loaded")
-
-
-    def update_frame(self, cap, point):
-        """
-        Updates the image
-
-        Arguments:
-        - self: The main object pointer.
-        - img: The IPLimage object.
-        """
-
-        if not cap.image():
-            return False
-
-        #sets new pixbuf
-        self.cap_image.set_from_pixbuf(cap.to_gtk_buff().scale_simple(200, 160, gtk.gdk.INTERP_BILINEAR))
-
-#     def recalcPoint( self, widget, flip = ''):
-#         """
-#         Enables the Flip of the Image in the X axis
-#
-#         This is for webcams that capture images as a mirror.
-#
-#         Arguments:
-#         - self: The main object pointer.
-#         - *args: Widget related arguments.
-#         """
-#
-#         if flip:
-#             self.settings.set( "cam", "flipImage",  str(not self.settings.getboolean( "cam", "flipImage" 
)) )
-#
-#         mouseTrap.calcPoint()
-#
-
-    def _newStockImageButton( self, label, stock ):
-        """
-        Creates an image button from gtk's stock.
-
-        Arguments:
-        - self: The main object pointer
-        - label: The buttons label
-        - stock: The Stock image the button will use. E.g: gtk.STOCK_GO-FORWARD
-
-        Returns buttonLabelBox A gtk.HBox that contains the new image stock button.
-        """
-
-        buttonLabelBox = gtk.VBox()
-
-        im = gtk.image_new_from_stock( stock, gtk.ICON_SIZE_BUTTON )
-
-        label = gtk.Label( label )
-        #label.set_alignment( 0.0, 0.5 )
-        label.set_use_underline( True )
-
-        buttonLabelBox.pack_start( im )
-        buttonLabelBox.pack_start( label )
-        buttonLabelBox.show_all()
-
-        return buttonLabelBox
-
-    def _show_settings_gui( self, *args ):
-        """
-        Starts the preferences GUI
-
-        Arguments:
-        - self: The main object pointer.
-        - *args: The widget callback arguments.
-        """
-
-        settings_gui.showPreffGui(self.ctr)
-
-
-    def _loadHelp( self, *args ):
-        """
-        Shows the user manual.
-
-        Arguments:
-        - self: The main object pointer.
-        - *args: The widget callback arguments.
-        """
-
-        try:
-            import gnome
-            gnome.help_display_uri("ghelp:%s/docs/mousetrap.xml" % env.mTDataDir)
-        except ImportError:
-            dialogs.errorDialog(
-            "mouseTrap needs <b>gnome</b> module to show the help. Please install gnome-python and try 
again.", None )
-            debug.exception( "mainGui", "The help load failed" )
-
-    def close( self, *args ):
-        """
-        Close Function for the quit button. This will kill mouseTrap.
-
-        Arguments:
-        - self: The main object pointer.
-        - *args: The widget callback arguments.
-        """
-        self.ctr.quit(0)
-
+class MainGui( Gtk.Window ):
+       '''
+       MouseTrap's main GUI Class.
+       '''
+       
+       def __init__( self, controller ):
+               '''
+               The main GUI constructor
+               
+               Arguments:
+               - self: The main object pointer.
+               - controller: The mouseTrap's controller.
+               '''
+               
+               GObject.GObject.__init__( self )
+               self.ctr    = controller
+               self.cfg    = controller.cfg
+               self.script = self.ctr.script()
+               self.set_default_size(200, 400)
+               
+       def setWindowsIcon( self ):
+               '''
+               Sets the mainGui icon
+               
+               Arguments:
+               - self: The main object pointer.
+               '''
+               
+               icon_theme = Gtk.IconTheme.get_default()
+               try:
+                       icon = icon_theme.load_icon("mousetrap", 48, 0)
+               except:
+                       return
+               
+               self.set_default_icon(icon)
+               
+       def build_interface( self ):
+               '''
+               Builds the interface
+               
+               Arguments:
+               - self: The main object pointer.
+               '''
+               
+               self.setWindowsIcon()
+               
+               accelGroup = Gtk.AccelGroup()
+               self.add_accel_group( accelGroup )
+               
+               self.accelGroup = accelGroup
+               
+               self.set_title("MouseTrap")
+               self.connect("destroy", self.close)
+               # Why does this appear twice?? (line below)
+               self.setWindowsIcon()
+               
+               self.vbox = Gtk.Grid()
+               
+               self.buttonsBox = Gtk.ButtonBox()
+               
+               self.prefButton = Gtk.Button(stock=Gtk.STOCK_PREFERENCES)
+               self.prefButton.connect("clicked", self._show_settings_gui)
+               self.buttonsBox.add(self.prefButton)
+               
+               self.closeButton = Gtk.Button(stock=Gtk.STOCK_QUIT)
+               self.closeButton.connect("clicked", self.close)
+               self.buttonsBox.add(self.closeButton)
+               
+               self.helpButton = Gtk.Button(stock=Gtk.STOCK_HELP)
+               self.helpButton.connect("clicked", self._loadHelp)
+               self.buttonsBox.add(self.helpButton)
+               
+               self.vbox.add(self.buttonsBox)
+
+               self.addonBox = Gtk.Grid()
+               self.addonBox.show_all()
+               self.vbox.attach_next_to(self.addonBox, self.buttonsBox, Gtk.PositionType.BOTTOM, 1, 1)
+               
+               self.cap_image = Gtk.Image()
+               
+               if self.cfg.getboolean("gui", "showCapture"):
+                       self.cap_expander = Gtk.Expander.new_with_mnemonic("_Camera Image")
+                       self.cap_expander.add(self.cap_image)
+                       self.cap_expander.set_expanded(True)
+                       #expander.connect('notify::expanded', self.expaned_cb)
+                       self.vbox.attach_next_to(self.cap_expander, self.addonBox, Gtk.PositionType.BOTTOM, 
1, 1)
+                       
+               if self.cfg.getboolean("gui", "showPointMapper"):
+                       self.map_expander = Gtk.Expander.new_with_mnemonic("_Script Mapper")
+                       self.map_expander.add(self.script)
+                       self.map_expander.set_expanded(True)
+                       #expander.connect('notify::expanded', self.expaned_cb)
+                       self.vbox.attach_next_to(self.map_expander, self.addonBox, Gtk.PositionType.BOTTOM, 
1, 1)
+               
+#              self.hbox = Gtk.Grid()
+#                      
+#              flipButton = Gtk.Button( _("Flip Image") )
+#              flipButton.connect("clicked", self.recalcPoint, "flip" )
+#              hbox.add(flipButton)
+#              
+#              recalcButton = Gtk.Button( _("Recalc Point") )
+#              recalcButton.connect("clicked", self.recalcPoint )
+#              hbox.add(recalcButton)
+#              
+#              self.vbox.add(self.hbox, Gtk.PositionType.BOTTOM)
+#              
+#              self.buttonsBox.show_all()
+
+               self.statusbar = Gtk.Statusbar()
+               self.statusbar_id = self.statusbar.get_context_id("statusbar")
+               
+               self.vbox.attach_next_to(self.statusbar, self.addonBox, Gtk.PositionType.BOTTOM, 1, 1)
+               
+               self.vbox.show_all()
+               self.add(self.vbox)
+               self.show_all()
+       
+       def load_addons(self):
+               '''
+               Loads the enabled addons
+               
+               Arguments:
+               - self: The main object pointer.
+               '''
+               
+               for add in self.cfg.getList("main", "addon"):
+                       tmp = __import__("mousetrap.app.addons.%s" % add, globals(), locals(),[''])
+               
+                       setattr(self, add, tmp.Addon(self.ctr))
+               
+       def update_frame(self, cap, point):
+               '''
+               Updates the image
+               
+               Arguments:
+               - self: The main object pointer.
+               - img: The IPLimage object.
+               '''
+               if not cap.image():
+                       return False
+               
+               #sets new pixbuf
+               self.cap_image.set_from_pixbuf(cap.to_gtk_buff().scale_simple(200, 160, 
GdkPixbuf.InterpType.BILINEAR))
+               
+#      def recalPoint(self, widget, flip = ''):
+#              '''
+#              Enables the Flip of the Image in the X axis
+#              
+#              This is for webcams that capture images as a mirror.
+#              
+#              Arguments:
+#              - selfL The main object pointer.
+#              - *args: Widget related arguments.
+#              '''
+#              
+#              if flip:
+#                      self.settings.set( "cam", "flipImage", str(not self.settings.getboolean("cam", 
"flipImage")) )
+#              
+#              mouseTrap.calcPoint()
+       
+       def _newStockImageBurron(self, label, stock):
+               '''
+               Creates an image button from gtk's stock.
+               
+               Arguments:
+               - self: The main object pointer.
+               - label: The button's label.
+               - stock: The Stock image the button will use. E.g. Gtk.STOCK_GO-FORWARD.
+               
+               Returns buttonLabelBox - A Gtk.Grid that contains the new image stock button.
+               '''
+               
+               buttonLabelBox = Gtk.Grid()
+               
+               im = Gtk.Image.new_from_stock( stock, Gtk.IconSize.BUTTON )
+               
+               label = Gtk.Label( label = label )
+               #label.set_alignment( 0.0, 0.5 )
+               label.set_use_underline( True )
+               
+               buttonLabelBox.add( im )
+               buttonLabelBox.attach_next_to( label, im, Gtk.PositionType.BOTTOM, 1, 1 )
+               buttonLabelBox.show_all()
+               return buttonLabelBox
+               
+       def _show_settings_gui(self, *args):
+               '''
+               Starts the preferences GUI
+               
+               Arguments:
+               - self: The main object pointer.
+               - *args: The widget callback arguments.
+               '''
+               
+               settings_gui.showPreffGui(self.ctr)
+       
+       def _loadHelp(self, *args):
+               '''
+               Shows the user manual.
+               
+               Arguments:
+               - self: The main object pointer.
+               - *args: The widget callback arguments.
+               '''
+               
+               uri = "ghelp:%s/docs/mousetrap.xml" % env.mTDataDir
+               try:
+                       Gtk.show_uri(Gdk.Screen.get_default(), uri, Gtk.get_current_event_time())
+               except:
+                       debug.exception( "mainGui", "The help load failed" )
+       
+       def close(self, *args):
+               '''
+               Close function for the quit button. This will kill mouseTrap.
+               
+               Arguments:
+               - self: The main object pointer.
+               - *args: The widget callback arguments.
+               '''
+               self.ctr.quit(0)
+       
 def showMainGui( ):
-    """
-    Loads the mainGUI components and launch it.
-
-    Arguments:
-    - mouseTrap: The mouseTrap object pointer
-    """
-
-    gui = MainGui()
-    gui.build_interface()
-    return gui
-
+       '''
+       Loads the mainGUI components and launches it.
+       
+       Arguments:
+       - mouseTrap: The mouseTrap object pointer.
+       '''
+       
+       gui = MianGui()
+       gui.build_interface()
+       return gui
diff --git a/src/mousetrap/app/ui/scripts/joystick.py b/src/mousetrap/app/ui/scripts/joystick.py
index bfe3a14..81a9d1e 100644
--- a/src/mousetrap/app/ui/scripts/joystick.py
+++ b/src/mousetrap/app/ui/scripts/joystick.py
@@ -53,7 +53,8 @@ class ScriptClass(Mapper):
         self.point       = None
         self.border_width = 0
 
-        self.connect("expose_event", self.expose_event)
+       #FIXME: uncommenting this results in tracebacks and the window not showing.
+        #self.connect("expose_event", self.expose_event)
 
     def update_items(self, point):
         self.point = point
diff --git a/src/mousetrap/app/ui/settings_gui.py b/src/mousetrap/app/ui/settings_gui.py
index 9b012e7..7b5faa5 100644
--- a/src/mousetrap/app/ui/settings_gui.py
+++ b/src/mousetrap/app/ui/settings_gui.py
@@ -1,3 +1,4 @@
+
 # -*- coding: utf-8 -*-
 
 # MouseTrap
@@ -29,341 +30,351 @@ __license__   = "GPLv2"
 
 from gi.repository import GObject
 from gi.repository import Gtk
-from . import dialogs
-from .i18n import _
+import dialogs
+from i18n import _
 from mousetrap.ocvfw import pocv
 import mousetrap.app.environment as env
 
 from mousetrap.app.ui.scripts import get_scripts_list
 from mousetrap.app.addons.handler import AddonsHandler
 
-class PreffGui( gtk.Window ):
-    """
-    The Class for the preferences GUI.
+class PreffGui( Gtk.Window ):
+       """
+       The Class for the preferences GUI.
 
-    Arguments:
-    - gtk.Window: The gtk.Window Object.
-    """
+       Arguments:
+       - gtk.Window: The gtk.Window Object.
+       """
 
-    def __init__(self, controller):
-        """
-        The Class Constructor.
+       def __init__(self, controller):
+               """
+               The Class Constructor.
 
-        Arguments:
-        - self: The main object pointer.
-        - mouseTrap: The mouseTrap object pointer.
-        """
+               Arguments:
+               - self: The main object pointer.
+               - mouseTrap: The mouseTrap object pointer.
+               """
 
-        gtk.Window.__init__( self )
+               GObject.GObject.__init__( self )
 
-        self.ctr = controller
-        self.cfg = self.ctr.cfg
-        self.adds = AddonsHandler(self.ctr)
-        self.preffWidgets = dict()
+               self.ctr = controller
+               self.cfg = self.ctr.cfg
+               self.adds = AddonsHandler(self.ctr)
+               self.preffWidgets = dict()
 
-    def setWindowsIcon( self ):
-        """
-        Sets the icon for the preffGUI.
+       def setWindowsIcon( self ):
+               """
+               Sets the icon for the preffGUI.
 
-        Arguments:
-        - self: The main object pointer.
-        """
+               Arguments:
+               - self: The main object pointer.
+               """
 
-        icon_theme = gtk.icon_theme_get_default()
-        try:
-            icon = icon_theme.load_icon("mouseTrap", 48, 0)
-        except:
-            return
+               icon_theme = Gtk.IconTheme.get_default()
+               try:
+                       icon = icon_theme.load_icon("mouseTrap", 48, 0)
+               except:
+                       return
 
-        gtk.window_set_default_icon(icon)
+               Gtk.Window_set_default_icon(icon)
 
-    def buildInterface( self ):
-        """
-        Builds the preffGUI.
+       def buildInterface( self ):
+               """
+               Builds the preffGUI.
 
-        Arguments:
-        - self: The main object pointer.
-        """
+               Arguments:
+               - self: The main object pointer.
+               """
 
-        accelGroup = gtk.AccelGroup()
-        self.add_accel_group( accelGroup )
+               accelGroup = Gtk.AccelGroup()
+               self.add_accel_group( accelGroup )
 
-        accelGroup = accelGroup
+               accelGroup = accelGroup
 
-        self.set_title( _("mouseTrap Preferences") )
-        self.set_size_request( 600 , 400)
-        self.connect( "destroy", self.close)
+               self.set_title( _("mouseTrap Preferences") )
+               self.set_size_request( 300, 100)
+               self.connect( "destroy", self.close)
 
-        self.table = gtk.Table( 3, 6, False )
+               self.window = Gtk.Grid()
 
-        self.noteBook = gtk.Notebook()
-        self.noteBook.set_tab_pos( gtk.POS_TOP )
-        self.table.attach( self.noteBook, 0, 6, 0, 1 )
-        self.noteBook.show()
+               self.noteBook = Gtk.Notebook()
+               self.noteBook.set_tab_pos( Gtk.PositionType.TOP )
+               self.window.add( self.noteBook )
+               self.noteBook.show()
 
-        self.main_gui_tab()
-        self.cam_tab()
-        self.algorithm_tab()
-        self.addons_tab()
-        self.mouseTab()
-        self.debug_tab()
+               self.main_gui_tab()
+               self.cam_tab()
+               self.algorithm_tab()
+               self.addons_tab()
+               self.mouseTab()
+               self.debug_tab()
 
-        ####################
-        # Bottom's buttons #
-        ####################
-        self.buttonsBox = gtk.HBox( False, spacing=6 )
+               ####################
+               # Bottom's buttons #
+               ####################
+               self.buttonsBox = Gtk.Grid()
 
-        self.acceptButton = gtk.Button( _("Accept"), stock=gtk.STOCK_OK)
-        self.acceptButton.connect("clicked", self.acceptButtonClick )
-        self.buttonsBox.pack_end( self.acceptButton )
+               self.acceptButton = Gtk.Button( _("Accept"), stock=Gtk.STOCK_OK)
+               self.acceptButton.connect("clicked", self.acceptButtonClick )
+               self.buttonsBox.add( self.acceptButton )
 
-        cancelButton = gtk.Button( _("Accept"), stock=gtk.STOCK_CANCEL )
-        cancelButton.connect("clicked", self.close )
-        self.buttonsBox.pack_end( cancelButton)
+               self.cancelButton = Gtk.Button( _("Accept"), stock=Gtk.STOCK_CANCEL )
+               self.cancelButton.connect("clicked", self.close )
+               self.buttonsBox.add( self.cancelButton )
 
-        self.applyButton = gtk.Button( _("Accept"), stock=gtk.STOCK_APPLY )
-        self.applyButton.connect( "clicked", self.applyButtonClick )
-        self.buttonsBox.pack_end( self.applyButton )
+               self.applyButton = Gtk.Button( _("Accept"), stock=Gtk.STOCK_APPLY )
+               self.applyButton.connect( "clicked", self.applyButtonClick )
+               self.buttonsBox.add( self.applyButton )
 
-        self.buttonsBox.show_all()
+               self.buttonsBox.show_all()
 
-        self.table.attach(self.buttonsBox, 1, 2, 2, 3, 'fill', False)
-        self.table.show()
-        self.add( self.table )
-        self.show()
+               self.window.attach_next_to(self.buttonsBox, self.noteBook, Gtk.PositionType.BOTTOM, 1, 1)
+               self.window.show_all()
+               self.add( self.window )
+               self.show()
 
-    def main_gui_tab( self ):
-        """
-        The mainGui Preff Tab.
+       def main_gui_tab( self ):
+               """
+               The mainGui Preff Tab.
 
-        Arguments:
-        - self: The main object pointer.
-        """
+               Arguments:
+               - self: The main object pointer.
+               """
 
-        frame = gtk.Frame()
+               frame = Gtk.Frame()
 
-        general_box = gtk.VBox( spacing = 6 )
+               general_box = Gtk.Grid()
+               general_box.set_column_spacing(6)
 
-#         mWindowActive = gtk.CheckButton( _("Show main window") )
+#         mWindowActive = Gtk.CheckButton( _("Show main window") )
 #         mWindowActive.set_active( self.cfg.getboolean( "gui", "showMainGui" ) )
 #         mWindowActive.connect( "toggled", self._checkToggled, "gui", "showMainGui" )
 #
-#         mainGuiBox.pack_start( mWindowActive, False, False )
+#         mainGuiBox.add( mWindowActive )
 
-        cAmActive = gtk.CheckButton( _("Activate Camera module") )
-        cAmActive.set_active( self.cfg.getboolean( "main", "startCam" ) )
-        cAmActive.connect( "toggled", self._checkToggled, "main", "startCam" )
+               cAmActive = Gtk.CheckButton( _("Activate Camera module") )
+               cAmActive.set_active( self.cfg.getboolean( "main", "startCam" ) )
+               cAmActive.connect( "toggled", self._checkToggled, "main", "startCam" )
 
-        general_box.pack_start( cAmActive, False, False )
+               general_box.add( cAmActive )
 
-        flipImage = gtk.CheckButton( _("Flip Image") )
-        flipImage.set_active( self.cfg.getboolean( "cam",  "flipImage" ) )
-        flipImage.connect( "toggled", self._checkToggled, "cam", "flipImage" )
+               flipImage = Gtk.CheckButton( _("Flip Image") )
+               flipImage.set_active( self.cfg.getboolean( "cam",  "flipImage" ) )
+               flipImage.connect( "toggled", self._checkToggled, "cam", "flipImage" )
 
-        general_box.pack_start( flipImage, False, False )
+               general_box.attach_next_to( flipImage, cAmActive, Gtk.PositionType.BOTTOM, 1, 1 )
 
-        inputDevIndex = self.addSpin( _("Input Video Device Index: "), "inputDevIndex",
-                        self.cfg.getint( "cam", "inputDevIndex" ), "cam", "inputDevIndex", 0)
-        general_box.pack_start( inputDevIndex, False, False )
+               inputDevIndex = self.addSpin( _("Input Video Device Index: "), "inputDevIndex",
+                                               self.cfg.getint( "cam", "inputDevIndex" ), "cam", 
"inputDevIndex", 0)
+               general_box.attach_next_to( inputDevIndex, flipImage, Gtk.PositionType.BOTTOM, 1, 1 )
 
-        general_box.show_all()
+               general_box.show_all()
 
-        frame.add( general_box )
-        frame.show()
+               frame.add( general_box )
+               frame.show()
 
-        self.noteBook.insert_page(frame, gtk.Label( _("General") ) )
+               self.noteBook.insert_page(frame, Gtk.Label(label= _("General")), -1)
 
-    def cam_tab( self ):
-        """
-        The cam module Preff Tab.
+       def cam_tab( self ):
+               """
+               The cam module Preff Tab.
 
-        Arguments:
-        - self: The main object pointer.
-        """
+               Arguments:
+               - self: The main object pointer.
+               """
 
-        frame = gtk.Frame()
+               frame = Gtk.Frame()
 
-        camBox = gtk.VBox( spacing = 6 )
+               camBox = Gtk.Grid()
+               camBox.set_column_spacing(6)
 
-        mapperActive = gtk.CheckButton( _("Show Point Mapper") )
-        mapperActive.set_active( self.cfg.getboolean( "gui", "showPointMapper" ) )
-        mapperActive.connect( "toggled", self._checkToggled, "gui", "showPointMapper" )
+               mapperActive = Gtk.CheckButton( _("Show Point Mapper") )
+               mapperActive.set_active( self.cfg.getboolean( "gui", "showPointMapper" ) )
+               mapperActive.connect( "toggled", self._checkToggled, "gui", "showPointMapper" )
 
-        camBox.pack_start( mapperActive, False, False )
+               camBox.add( mapperActive )
 
-        showCapture = gtk.CheckButton( _("Show Capture") )
-        showCapture.set_active( self.cfg.getboolean( "gui", "showCapture" ) )
-        showCapture.connect( "toggled", self._checkToggled, "gui", "showCapture" )
+               showCapture = Gtk.CheckButton( _("Show Capture") )
+               showCapture.set_active( self.cfg.getboolean( "gui", "showCapture" ) )
+               showCapture.connect( "toggled", self._checkToggled, "gui", "showCapture" )
 
-        camBox.pack_start( showCapture, False, False )
+               camBox.attach_next_to( showCapture, mapperActive, Gtk.PositionType.BOTTOM, 1, 1 )
 
-        camBox.show_all()
+               camBox.show_all()
 
-        frame.add( camBox )
-        frame.show()
+               frame.add( camBox )
+               frame.show()
 
-        self.noteBook.insert_page(frame, gtk.Label( _("Camera") ) )
+               self.noteBook.insert_page(frame, Gtk.Label(label= _("Camera")), -1)
 
-    def algorithm_tab( self ):
-        """
-        The cam module Preff Tab.
+       def algorithm_tab( self ):
+               """
+               The cam module Preff Tab.
 
-        Arguments:
-        - self: The main object pointer.
-        """
+               Arguments:
+               - self: The main object pointer.
+               """
 
-        frame = gtk.Frame()
+               frame = Gtk.Frame()
 
-        algo_box = gtk.VBox( spacing = 6 )
+               algo_box = Gtk.Grid()
+               algo_box.set_column_spacing(6)
 
-        liststore = gtk.ListStore(bool, str, str, str)
+               liststore = Gtk.ListStore(bool, str, str, str)
 
-        conf_button = gtk.Button(stock=gtk.STOCK_PREFERENCES)
-        conf_button.connect('clicked', self.show_alg_pref, liststore)
-        conf_button.set_sensitive(False)
+               conf_button = Gtk.Button(stock=Gtk.STOCK_PREFERENCES)
+               conf_button.connect('clicked', self.show_alg_pref, liststore)
+               conf_button.set_sensitive(False)
 
-        scripts_combo = gtk.combo_box_new_text()
-        scripts_combo.append_text(self.cfg.get("scripts", "name"))
-        
-        for script in get_scripts_list():
-            if script.lower() != self.cfg.get("scripts", "name"):
-                scripts_combo.append_text(script)
+               scripts_combo = Gtk.ComboBoxText()
+               scripts_combo.append_text(self.cfg.get("scripts", "name"))
+
+               for script in get_scripts_list():
+                       if script.lower() != self.cfg.get("scripts", "name"):
+                               scripts_combo.append_text(script)
 
-        scripts_combo.connect('changed', self._comboChanged, "scripts", "name")
-        scripts_combo.set_active(0)
+               scripts_combo.connect('changed', self._comboChanged, "scripts", "name")
+               scripts_combo.set_active(0)
         
-        tree_view = gtk.TreeView(liststore)
-        tree_view.connect("cursor-changed", self._tree_view_click, conf_button)
+               tree_view = Gtk.TreeView(liststore)
+               tree_view.connect("cursor-changed", self._tree_view_click, conf_button)
 
-        toggle_cell = gtk.CellRendererToggle()
-        toggle_cell.set_radio(True)
-        toggle_cell.connect( 'toggled', self._toggle_cell_changed, liststore)
-        toggle_cell.set_property('activatable', True)
-        #toggle_cell.set_property('background-set' , True)
+               toggle_cell = Gtk.CellRendererToggle()
+               toggle_cell.set_radio(True)
+               toggle_cell.connect( 'toggled', self._toggle_cell_changed, liststore)
+               toggle_cell.set_property('activatable', True)
+               #toggle_cell.set_property('background-set' , True)
 
-        name_cell = gtk.CellRendererText()
-        desc_cell = gtk.CellRendererText()
+               name_cell = Gtk.CellRendererText()
+               desc_cell = Gtk.CellRendererText()
 
-        toggle_column = gtk.TreeViewColumn(_('Active Algorithms'), toggle_cell)
-        name_column = gtk.TreeViewColumn(_('Installed Algorithms'))
-        desc_column = gtk.TreeViewColumn(_('Description'))
+               toggle_column = Gtk.TreeViewColumn(_('Active Algorithms'), toggle_cell)
+               name_column = Gtk.TreeViewColumn(_('Installed Algorithms'))
+               desc_column = Gtk.TreeViewColumn(_('Description'))
 
-        for alg in pocv.get_idms_list():
-            alg_inf = pocv.get_idm_inf(alg)
+               for alg in pocv.get_idms_list():
+                       alg_inf = pocv.get_idm_inf(alg)
             
-            if not alg_inf:
-                continue
+                       if not alg_inf:
+                               continue
             
-            state = False
-            if alg_inf["name"].lower() in self.cfg.get("main", "algorithm").lower():
-                state = True
-            liststore.append([state, alg_inf["name"], alg_inf["dsc"], alg_inf["stgs"]])
-            #liststore.append([False, "%s: %s" % (alg_inf["name"], alg_inf["dsc"]), alg_inf["stgs"]])
+                       state = False
+                       if alg_inf["name"].lower() in self.cfg.get("main", "algorithm").lower():
+                               state = True
+                       # FIXME: I don't know what the purpose of this liststore is,
+                       # but it wants strings, so let's not argue for now. ;)
+                       liststore.append([state, alg_inf["name"], alg_inf["dsc"], str(alg_inf["stgs"])])
 
-        tree_view.append_column(toggle_column)
-        tree_view.append_column(name_column)
-        tree_view.append_column(desc_column)
+                       #liststore.append([False, "%s: %s" % (alg_inf["name"], alg_inf["dsc"]), 
alg_inf["stgs"]])
 
-        name_column.pack_start(name_cell, True)
-        desc_column.pack_start(desc_cell, True)
+               tree_view.append_column(toggle_column)
+               tree_view.append_column(name_column)
+               tree_view.append_column(desc_column)
 
-        toggle_column.add_attribute( toggle_cell, "active", 0 )
-        toggle_column.set_max_width(30)
-        #toggle_column.set_attributes( toggle_cell, background=2 )
-        name_column.set_attributes(name_cell, text=1)
-        desc_column.set_attributes(desc_cell, text=2)
+               name_column.pack_start(name_cell, True)
+               desc_column.pack_start(desc_cell, True)
 
-        algo_box.pack_start(tree_view)
-        algo_box.pack_start(conf_button, False, False)
-        algo_box.pack_start(scripts_combo, False, False)
+               toggle_column.add_attribute( toggle_cell, "active", 0 )
+               toggle_column.set_max_width(30)
+               #toggle_column.set_attributes( toggle_cell, background=2 )
+               name_column.set_attributes(name_cell, text=1)
+               desc_column.set_attributes(desc_cell, text=2)
 
-        algo_box.show_all()
+               algo_box.add(tree_view)
+               algo_box.attach_next_to(conf_button, tree_view, Gtk.PositionType.BOTTOM, 1, 1)
+               algo_box.attach_next_to(scripts_combo, conf_button, Gtk.PositionType.BOTTOM, 1, 1)
 
-        frame.add( algo_box )
-        frame.show()
+               algo_box.show_all()
 
-        self.noteBook.insert_page(frame, gtk.Label( _("Algorithm") ) )
+               frame.add( algo_box )
+               frame.show()
+
+               self.noteBook.insert_page(frame, Gtk.Label(label= _("Algorithm")), -1)
     
-    def addons_tab( self ):
-        """
-        The cam module Preff Tab.
+       def addons_tab( self ):
+               """
+               The cam module Preff Tab.
 
-        Arguments:
-        - self: The main object pointer.
-        """
+               Arguments:
+               - self: The main object pointer.
+               """
 
-        frame = gtk.Frame()
+               frame = Gtk.Frame()
 
-        algo_box = gtk.VBox( spacing = 6 )
+               algo_box = Gtk.Grid()
+               algo_box.set_column_spacing(6)
 
-        liststore = gtk.ListStore(bool, str, str, str)
+               liststore = Gtk.ListStore(bool, str, str, str)
 
-        conf_button = gtk.Button(stock=gtk.STOCK_PREFERENCES)
-        conf_button.connect('clicked', self.show_alg_pref, liststore)
-        conf_button.set_sensitive(False)
+               conf_button = Gtk.Button(stock=Gtk.STOCK_PREFERENCES)
+               conf_button.connect('clicked', self.show_alg_pref, liststore)
+               conf_button.set_sensitive(False)
 
-        tree_view = gtk.TreeView(liststore)
-        tree_view.connect("cursor-changed", self._tree_view_click, conf_button)
+               tree_view = Gtk.TreeView(liststore)
+               tree_view.connect("cursor-changed", self._tree_view_click, conf_button)
 
-        toggle_cell = gtk.CellRendererToggle()
-        toggle_cell.connect( 'toggled', self._enable_disable_addon, liststore)
-        toggle_cell.set_property('activatable', True)
+               toggle_cell = Gtk.CellRendererToggle()
+               toggle_cell.connect( 'toggled', self._enable_disable_addon, liststore)
+               toggle_cell.set_property('activatable', True)
 
-        name_cell = gtk.CellRendererText()
-        desc_cell = gtk.CellRendererText()
+               name_cell = Gtk.CellRendererText()
+               desc_cell = Gtk.CellRendererText()
 
-        toggle_column = gtk.TreeViewColumn(_('Active'), toggle_cell)
-        name_column = gtk.TreeViewColumn(_('Name'))
-        desc_column = gtk.TreeViewColumn(_('Description'))
+               toggle_column = Gtk.TreeViewColumn(_('Active'), toggle_cell)
+               name_column = Gtk.TreeViewColumn(_('Name'))
+               desc_column = Gtk.TreeViewColumn(_('Description'))
 
-        for add in self.adds.get_addons_list():
-            add_inf = self.adds.get_addon_inf(add)
+               for add in self.adds.get_addons_list():
+                       add_inf = self.adds.get_addon_inf(add)
             
-            if not add_inf:
-                continue
+                       if not add_inf:
+                               continue
             
-            state = False
-            if add_inf["name"].lower() in self.cfg.getList("main", "addon"):
-                state = True
-            liststore.append([state, add_inf["name"], add_inf["dsc"], add_inf["stgs"]])
+                       state = False
+                       if add_inf["name"].lower() in self.cfg.getList("main", "addon"):
+                               state = True
+                       # FIXME: I don't know what the purpose of this liststore is,
+                       # but it wants strings, so let's not argue for now. ;)
+                       liststore.append([state, add_inf["name"], add_inf["dsc"], str(add_inf["stgs"])])      
  
 
-        tree_view.append_column(toggle_column)
-        tree_view.append_column(name_column)
-        tree_view.append_column(desc_column)
+               tree_view.append_column(toggle_column)
+               tree_view.append_column(name_column)
+               tree_view.append_column(desc_column)
 
-        name_column.pack_start(name_cell, True)
-        desc_column.pack_start(desc_cell, True)
+               name_column.pack_start(name_cell, True)
+               desc_column.pack_start(desc_cell, True)
 
-        toggle_column.add_attribute( toggle_cell, "active", 0 )
-        toggle_column.set_max_width(30)
-        #toggle_column.set_attributes( toggle_cell, background=2 )
-        name_column.set_attributes(name_cell, text=1)
-        desc_column.set_attributes(desc_cell, text=2)
+               toggle_column.add_attribute( toggle_cell, "active", 0 )
+               toggle_column.set_max_width(30)
+               #toggle_column.set_attributes( toggle_cell, background=2 )
+               name_column.set_attributes(name_cell, text=1)
+               desc_column.set_attributes(desc_cell, text=2)
 
-        algo_box.pack_start(tree_view)
-        algo_box.pack_start(conf_button, False, False)
+               algo_box.add(tree_view)
+               algo_box.attach_next_to(conf_button, tree_view, Gtk.PositionType.BOTTOM, 1, 1)
 
-        algo_box.show_all()
+               algo_box.show_all()
 
-        frame.add( algo_box )
-        frame.show()
+               frame.add( algo_box )
+               frame.show()
 
-        self.noteBook.insert_page(frame, gtk.Label( _("Addons") ) )
+               self.noteBook.insert_page(frame, Gtk.Label(label= _("Addons")), -1)
 
-    def mouseTab( self ):
-        """
-        The cam module Preff Tab.
+       def mouseTab( self ):
+               """
+               The cam module Preff Tab.
 
-        Arguments:
-        - self: The main object pointer.
-        """
+               Arguments:
+               - self: The main object pointer.
+               """
 
-        frame = gtk.Frame()
+               frame = Gtk.Frame()
 
-        camBox = gtk.VBox( spacing = 6 )
+               camBox = Gtk.Grid()
+               camBox.set_column_spacing(6)
 
-        reqMov = self.addSpin( _("Step Speed: "), "stepSpeed", self.cfg.getint( "mouse", "stepSpeed" ), 
"mouse", "stepSpeed" )
-        camBox.pack_start( reqMov, False, False )
+               reqMov = self.addSpin( _("Step Speed: "), "stepSpeed", self.cfg.getint( "mouse", "stepSpeed" 
), "mouse", "stepSpeed" )
+               camBox.add( reqMov )
 
         ###############################################
         #                                             #
@@ -398,223 +409,225 @@ class PreffGui( gtk.Window ):
 #         defClickF.add( defClick)
 #         camBox.pack_start( defClickF, False, False )
 
-        camBox.show_all()
-
-        frame.add( camBox )
-        frame.show()
-
-        self.noteBook.insert_page(frame, gtk.Label( _("Mouse") ) )
+               camBox.show_all()
 
-    def debug_tab( self ):
-        """
-        The debuging Preff Tab.
+               frame.add( camBox )
+               frame.show()
 
-        Arguments:
-        - self: The main object pointer.
-        """
+               self.noteBook.insert_page(frame, Gtk.Label(label= _("Mouse")), -1)
 
+       def debug_tab( self ):
+               """
+               The debuging Preff Tab.
 
-        frame = gtk.Frame()
+               Arguments:
+               - self: The main object pointer.
+               """
 
-        debugBox = gtk.VBox( spacing = 6 )
+               frame = Gtk.Frame()
 
-        levelHbox = gtk.HBox( spacing = 4 )
+               debugBox = Gtk.Grid()
+               debugBox.set_column_spacing(6)
 
-        levellabel = gtk.Label( _("Debugging Level:") )
-        levellabel.set_alignment( 0.0, 0.5 )
-        levellabel.show()
-        levelHbox.pack_start( levellabel, False, False )
+               levelHbox = Gtk.Grid()
+               levelHbox.set_row_spacing(4)
 
-        adj = gtk.Adjustment( self.cfg.getint( "main", "debugLevel" ), 10, 50, 10, 1, 0)
-        levelSpin = gtk.SpinButton( adj, 0.0, 0 )
-        levelSpin.set_wrap( True )
-        levelHbox.pack_start( levelSpin, False, False )
-        levelSpin.connect( "value-changed", self._spinChanged, "main", "debugLevel" )
+               levellabel = Gtk.Label(label= _("Debugging Level:") )
+               levellabel.set_alignment( 0.0, 0.5 )
+               levellabel.show()
+               levelHbox.add( levellabel )
 
-        debugBox.pack_start( levelHbox, False, False )
+               adj = Gtk.Adjustment( self.cfg.getint( "main", "debugLevel" ), 10, 50, 10, 1, 0)
+               levelSpin = Gtk.SpinButton()
+               levelSpin.set_adjustment(adj)
+               levelSpin.set_wrap( True )
+               levelHbox.add( levelSpin )
+               levelSpin.connect( "value-changed", self._spinChanged, "main", "debugLevel" )
 
-        debugBox.show_all()
+               debugBox.add( levelHbox )
 
-        frame.add( debugBox )
-        frame.show()
+               debugBox.show_all()
 
-        self.noteBook.insert_page(frame, gtk.Label( _("Debug") ) )
+               frame.add( debugBox )
+               frame.show()
 
+               self.noteBook.insert_page(frame, Gtk.Label(label= _("Debug")), -1)
 
-    def show_alg_pref(self, widget, liststore):
-        dlg = dialogs.IdmSettings(self.cfg, self.selected_idm, self.selected_idm_stgs)
-        dlg.set_transient_for(self)
-        dlg.set_destroy_with_parent(True)
+       def show_alg_pref(self, widget, liststore):
+               dlg = dialogs.IdmSettings(self.cfg, self.selected_idm, self.selected_idm_stgs)
+               dlg.set_transient_for(self)
+               dlg.set_destroy_with_parent(True)
 
-    def acceptButtonClick( self, *args ):
-        """
-        Acept button callback. This will apply the settings and close the
-        preferences GUI.
+       def acceptButtonClick( self, *args ):
+               """
+               Accept button callback. This will apply the settings and close the
+               preferences GUI.
 
-        Arguments:
-        - self: The main object pointer.
-        - *args: The button event arguments
-        """
+               Arguments:
+               - self: The main object pointer.
+               - *args: The button event arguments
+               """
 
-        self.cfg.write( open( env.configPath + "userSettings.cfg", "w" ) )
-        self.destroy()
+               self.cfg.write( open( env.configPath + "userSettings.cfg", "w" ) )
+               self.destroy()
 
 
-    def _tree_view_click(self, widget, conf_button):
-        """
-        Row Selection Event.
+       def _tree_view_click(self, widget, conf_button):
+               """
+               Row Selection Event.
 
-        Enables/Disables the conf_button whether the
-        selected algorithm can be configured or not.
+               Enables/Disables the conf_button whether the
+               selected algorithm can be configured or not.
 
-        Arguments:
-        - widget: The gtk Widget
-        - conf_button: The configuration button object.
-        """
+               Arguments:
+               - widget: The gtk Widget
+               - conf_button: The configuration button object.
+               """
 
-        ts = widget.get_selection()
-        model, it = ts.get_selected()
-        path = model.get_path(it)[0]
-        if model[path][0] and model[path][3]:
-            self.selected_idm = model[path][1]
-            self.selected_idm_stgs = model[path][3]
-            conf_button.set_sensitive(True)
+               ts = widget.get_selection()
+               model, it = ts.get_selected()
+               path = model.get_path(it)[0]
+               if model[path][0] and model[path][3]:
+                       self.selected_idm = model[path][1]
+                       self.selected_idm_stgs = model[path][3]
+                       conf_button.set_sensitive(True)
 
-    def _toggle_cell_changed(self, cell, path, model):
-        """
-        ListStore RadioButton Value Changer.
-        """
+       def _toggle_cell_changed(self, cell, path, model):
+               """
+               ListStore RadioButton Value Changer.
+               """
 
-        if model[path][0]:
-            return False
+               if model[path][0]:
+                       return False
 
-        for pth in range(len(model)):
-            pth = str(pth)
-            if pth == path:
-                model[pth][0] = True
-                self.cfg.set("main", "algorithm", model[pth][1].lower())
-            else:
-                model[pth][0] = False
+               for pth in range(len(model)):
+                       pth = str(pth)
+                       if pth == path:
+                               model[pth][0] = True
+                               self.cfg.set("main", "algorithm", model[pth][1].lower())
+                       else:
+                               model[pth][0] = False
 
-    def _enable_disable_addon(self, cell, path, model):
-        """
-        ListStore RadioButton Value Changer.
-        """
+       def _enable_disable_addon(self, cell, path, model):
+               """
+               ListStore RadioButton Value Changer.
+               """
         
-        model[path][0] = not model[path][0]
-
-        cur = self.cfg.getList("main", "addon")
-
-        if model[path][1] in cur:
-            cur.remove(model[path][1].lower())
-        else:
-            cur.append(model[path][1].lower())
-
-        self.cfg.setList("main", "addon", cur)
-
-    def _checkToggled( self, widget, section, option ):
-        """
-        Sets the new value in the settings object for the toggled checkbox
-
-        Arguments:
-        - self: The main object pointer.
-        - widget: The checkbox.
-        - section: The section of the settings object.
-        - option: The option in the section.
-        """
-        self.cfg.set( section, option, str(widget.get_active()))
-
-    def _spinChanged( self, widget, section, option ):
-        """
-        Sets the new value in the settings object for the toggled checkbox
-
-        Arguments:
-        - self: The main object pointer.
-        - widget: The checkbox.
-        - section: The section of the settings object.
-        - option: The option in the section.
-        """
-        self.cfg.set( section, option, str(widget.get_value_as_int()))
-
-
-    def applyButtonClick( self, *args):
-        """
-        Apply button callback. This will apply the settings.
-
-        Arguments:
-        - self: The main object pointer.
-        - *args: The button event arguments
-        """
-        self.cfg.write( open( env.configPath + 'userSettings.cfg', "w" ) )
-
-    def _comboChanged( self, widget, section, option, modes=None ):
-        """
-        On combo change. This function is the callback for the on_change
-        event.
-
-        This helps to keep the combobox settings variable updated with the
-        selected option.
-
-        Arguments:
-        - self: The main object pointer.
-        - widget: The widget pointer.
-        - section: The section of the settings object.
-        - option: The option in the section.
-        - modes: The new value.
-        """
-
-        model = widget.get_model()
-        index = widget.get_active()
-        val = (modes and modes[model[index][0]]) or model[index][0] 
-        self.cfg.set( section, option, val)
-
-    def addSpin( self, label, var, startValue, section, option, min_ = 1, max_ = 15):
-        """
-        Creates a new spin button inside a HBox and return it.
-
-        Arguments:
-        - self: The main object pointer.
-        - label: The spin button label.
-        - var: The prefferences dict variable.
-        - startValue: The start value.
-        """
-
-        spinHbox = gtk.HBox( spacing = 4 )
-
-        spinLbl = gtk.Label( label )
-        spinLbl.set_alignment( 0.0, 0.5 )
-        spinLbl.show()
-        spinHbox.pack_start( spinLbl, False, False )
-
-        adj = gtk.Adjustment( startValue, min_, max_, 1, 1, 0)
-        spinButton = gtk.SpinButton( adj, 0.0, 0 )
-        spinButton.set_wrap( True )
-        spinButton.connect( "value-changed", self._spinChanged, section, option )
-        spinHbox.pack_start( spinButton, False, False )
-
-        spinLbl.set_mnemonic_widget( spinButton )
-
-        return spinHbox
-
-    def close( self, *args ):
-        """
-        Closes the prefferences GUI without saving the changes.
-
-        Arguments:
-        - self: The main object pointer.
-        - *args: The button event arguments
-        """
-        self.destroy()
+               model[path][0] = not model[path][0]
+
+               cur = self.cfg.getList("main", "addon")
+
+               if model[path][1] in cur:
+                       cur.remove(model[path][1].lower())
+               else:
+                       cur.append(model[path][1].lower())
+
+               self.cfg.setList("main", "addon", cur)
+
+       def _checkToggled( self, widget, section, option ):
+               """
+               Sets the new value in the settings object for the toggled checkbox
+
+               Arguments:
+               - self: The main object pointer.
+               - widget: The checkbox.
+               - section: The section of the settings object.
+               - option: The option in the section.
+               """
+               self.cfg.set( section, option, str(widget.get_active()))
+
+       def _spinChanged( self, widget, section, option ):
+               """
+               Sets the new value in the settings object for the toggled checkbox
+
+               Arguments:
+               - self: The main object pointer.
+               - widget: The checkbox.
+               - section: The section of the settings object.
+               - option: The option in the section.
+               """
+               self.cfg.set( section, option, str(widget.get_value_as_int()))
+
+       def applyButtonClick( self, *args):
+               """
+               Apply button callback. This will apply the settings.
+
+               Arguments:
+               - self: The main object pointer.
+               - *args: The button event arguments
+               """
+               self.cfg.write( open( env.configPath + 'userSettings.cfg', "w" ) )
+
+       def _comboChanged( self, widget, section, option, modes=None ):
+               """
+               On combo change. This function is the callback for the on_change
+               event.
+
+               This helps to keep the combobox settings variable updated with the
+               selected option.
+
+               Arguments:
+               - self: The main object pointer.
+               - widget: The widget pointer.
+               - section: The section of the settings object.
+               - option: The option in the section.
+               - modes: The new value.
+               """
+
+               model = widget.get_model()
+               index = widget.get_active()
+               val = (modes and modes[model[index][0]]) or model[index][0] 
+               self.cfg.set( section, option, val)
+
+       def addSpin( self, label, var, startValue, section, option, min_ = 1, max_ = 15):
+               """
+               Creates a new spin button inside a HBox and return it.
+
+               Arguments:
+               - self: The main object pointer.
+               - label: The spin button label.
+               - var: The prefferences dict variable.
+               - startValue: The start value.
+               """
+
+               spinHbox = Gtk.Grid()
+               spinHbox.set_row_spacing(4)
+
+               spinLbl = Gtk.Label(label= label )
+               spinLbl.set_alignment( 0.0, 0.5 )
+               spinLbl.show()
+               spinHbox.add( spinLbl )
+
+               adj = Gtk.Adjustment( startValue, min_, max_, 1, 1, 0)
+               spinButton = Gtk.SpinButton()
+               spinButton.set_adjustment(adj)
+               spinButton.set_wrap( True )
+               spinButton.connect( "value-changed", self._spinChanged, section, option )
+               spinHbox.add( spinButton )
+
+               spinLbl.set_mnemonic_widget( spinButton )
+
+               return spinHbox
+
+       def close( self, *args ):
+               """
+               Closes the prefferences GUI without saving the changes.
+
+               Arguments:
+               - self: The main object pointer.
+               - *args: The button event arguments
+               """
+               self.destroy()
 
 
 def showPreffGui(controller):
-    """
-    Starts the preffGui.
+       """
+       Starts the preffGui.
 
-    Arguments:
-    - mouseTrap: The mouseTrap object pointer.
-    """
+       Arguments:
+       - mouseTrap: The mouseTrap object pointer.
+       """
 
-    gui = PreffGui(controller)
-    gui.setWindowsIcon()
-    gui.buildInterface()
+       gui = PreffGui(controller)
+       gui.setWindowsIcon()
+       gui.buildInterface()
diff --git a/src/mousetrap/app/ui/widgets.py b/src/mousetrap/app/ui/widgets.py
index cf4ca52..c277ffc 100644
--- a/src/mousetrap/app/ui/widgets.py
+++ b/src/mousetrap/app/ui/widgets.py
@@ -27,10 +27,10 @@ __date__      = "$Date$"
 __copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
 __license__   = "GPLv2"
 
-import gtk
 import cairo
-import gobject
-from gtk import gdk
+from gi.repository import Gdk
+from gi.repository import GObject
+from gi.repository import Gtk
 from math import pi
 
 BORDER_WIDTH = 0
@@ -38,10 +38,10 @@ BORDER_WIDTH = 0
 # A quite simple gtk.Widget subclass which demonstrates how to subclass
 # and do realizing, sizing and drawing.
 
-class Mapper(gtk.Widget):
+class Mapper(Gtk.Widget):
 
     def __init__(self, width, height):
-        gtk.Widget.__init__(self)
+        GObject.GObject.__init__(self)
 
         self.width   = width
         self.height  = height
@@ -64,22 +64,22 @@ class Mapper(gtk.Widget):
         # Mapper.do_realize: Class 'style' has no 'fg_gc' member
 
         # First set an internal flag telling that we're realized
-        self.set_flags(self.flags() | gtk.REALIZED)
+        self.set_flags(self.flags() | Gtk.REALIZED)
 
         # Create a new gdk.Window which we can draw on.
         # Also say that we want to receive exposure events
         # and button click and button press events
 
-        self.window = gdk.Window(
+        self.window = Gdk.Window(
                 self.get_parent_window(),
                 width=self.allocation.width,
                 height=self.allocation.height,
-                window_type=gdk.WINDOW_CHILD,
-                wclass=gdk.INPUT_OUTPUT,
-                event_mask=self.get_events() | gdk.EXPOSURE_MASK
-                        | gdk.BUTTON1_MOTION_MASK | gdk.BUTTON_PRESS_MASK
-                        | gtk.gdk.POINTER_MOTION_MASK
-                        | gtk.gdk.POINTER_MOTION_HINT_MASK)
+                window_type=Gdk.WINDOW_CHILD,
+                wclass=Gdk.INPUT_OUTPUT,
+                event_mask=self.get_events() | Gdk.EventMask.EXPOSURE_MASK
+                        | Gdk.EventMask.BUTTON1_MOTION_MASK | Gdk.EventMask.BUTTON_PRESS_MASK
+                        | Gdk.EventMask.POINTER_MOTION_MASK
+                        | Gdk.EventMask.POINTER_MOTION_HINT_MASK)
 
         # Associate the gdk.Window with ourselves, Gtk+ needs a reference
         # between the widget and the gdk window
@@ -91,13 +91,13 @@ class Mapper(gtk.Widget):
 
         # The default color of the background should be what
         # the style (theme engine) tells us.
-        self.style.set_background(self.window, gtk.STATE_NORMAL)
+        self.style.set_background(self.window, Gtk.StateType.NORMAL)
         self.window.move_resize(*self.allocation)
 
         # self.style is a gtk.Style object, self.style.fg_gc is
         # an array or graphic contexts used for drawing the forground
         # colours
-        self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
+        self.gc = self.style.fg_gc[Gtk.StateType.NORMAL]
         # pylint: enable-msg=E1101
 
         #self.connect("motion_notify_event", self.motion_notify_event)
@@ -128,7 +128,7 @@ class Mapper(gtk.Widget):
         # pylint: disable-msg=W0142
         # Mapper.do_size_allocate: Used * or ** magic
         # WE DO NEED THE *
-        if self.flags() & gtk.REALIZED:
+        if self.get_realized():
             self.window.move_resize(*allocation)
         # pylint: enable-msg=W0142
 
@@ -233,4 +233,4 @@ class Mapper(gtk.Widget):
                 reg_event["callback"]()
 
 
-gobject.type_register(Mapper)
+GObject.type_register(Mapper)
diff --git a/src/mousetrap/ocvfw/_ocv.py b/src/mousetrap/ocvfw/_ocv.py
index bd9daa8..bb3d46d 100644
--- a/src/mousetrap/ocvfw/_ocv.py
+++ b/src/mousetrap/ocvfw/_ocv.py
@@ -371,7 +371,13 @@ class OcvfwPython(OcvfwBase):
         if not cascade:
             debug.exception( "ocvfw", "The Haar Classifier Cascade load failed" )
 
-        co.cv.cvClearMemStorage(self.storage)
+        debug.debug( "ocvfw-get_haar_roi_points", self.img)
+
+        #remove, DNE co.cv.ClearMemStorage(self.storage)
+
+       if ((rect[0]+rect[2]) > self.img.width) or ((rect[1]+rect[3]) > self.img.height):
+               rect = (rect[0], rect[1], self.img.width-rect[0],self.img.height-rect[1])
+               debug.debug("GetSubRect", "Rect was too big. Fixed size")
 
         imageROI = co.cv.cvGetSubRect(self.img, rect)
 
diff --git a/src/mousetrap/ocvfw/dev/camera.py b/src/mousetrap/ocvfw/dev/camera.py
index 7d00a23..a3eb776 100644
--- a/src/mousetrap/ocvfw/dev/camera.py
+++ b/src/mousetrap/ocvfw/dev/camera.py
@@ -27,7 +27,10 @@ __date__      = "$Date$"
 __copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
 __license__   = "GPLv2"
 
-import gobject
+from gi.repository import GdkPixbuf
+from gi.repository import GObject
+from gi.repository import Gtk
+
 from warnings import *
 from .. import debug
 from .. import commons as co
@@ -35,11 +38,6 @@ from mousetrap.ocvfw import _ocv as ocv
 
 Camera = None
 
-try:
-    import gtk
-except ImportError:
-    debug.info("Camera", "Gtk not imported")
-
 def _camera(backend):
     if not hasattr(ocv, backend):
         debug.warning("Camera", "Not such backend %s falling back to OcvfwPython" % backend)
@@ -187,14 +185,18 @@ class Capture(object):
         img = self.__image
 
         if "as_numpy_array" in dir(img):
-            buff = gtk.gdk.pixbuf_new_from_array(img.as_numpy_array(), 
-                                                 gtk.gdk.COLORSPACE_RGB, 
+            buff = GdkPixbuf.Pixbuf.new_from_array(img.as_numpy_array(),
+                                                 GdkPixbuf.Colorspace.RGB,  
                                                  img.depth)
         else:
-            buff = gtk.gdk.pixbuf_new_from_data(img.imageData, 
-                                                gtk.gdk.COLORSPACE_RGB, False, 8,
-                                                int(img.width), int(img.height), 
-                                                img.widthStep )
+            buff = GdkPixbuf.Pixbuf.new_from_data(img.tostring(),
+                                                GdkPixbuf.Colorspace.RGB, 
+                                               False,                      # has alpha channel
+                                                img.depth,
+                                                img.width,
+                                                img.height,
+                                                img.width*img.nChannels,       # stride or widthStep
+                                               None, None)                     #Bug workaround for memory 
management
         return buff
 
     def points(self):




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]