[mousetrap/gnome3-wip] Continue the move of of PyGI



commit 19af5086e2163f677ae7047525e346cc2bac9589
Author: Kevin Brown <kbrown rediker com>
Date:   Sun Mar 2 15:04:09 2014 -0500

    Continue the move of of PyGI
    
    This fixes the old-style calls in `__init__` so it actually calls
    `super`.  While the old style is still supported, it will cause
    issues if the class ever needs to be modified to use multiple
    inheritance.
    
    This also cleans up the code that is used for calling the process
    for the CPU addon to check the CPU usage.
    
    --
    
    Moved `dialogs-newGTK` to `dialogs`
    
    The first file was created as a revised version of the second file
    during the transition to GTK 3.  This finishes off the transition
    and finally moves the code over, removing the redundant file.
    
    --
    
    This also changes the remaining calls to `GObject.__init__` to
    use `super`.  The remaining imports for `GObject`, in cases where
    it is not otherwise used, have been removed from files where it
    was present.
    
    --
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691879

 src/mousetrap/app/addons/cpu.py        |   15 +-
 src/mousetrap/app/addons/recalc.py     |    1 -
 src/mousetrap/app/ui/dialogs-newGTK.py |  549 --------------------------------
 src/mousetrap/app/ui/dialogs.py        |  319 +++----------------
 src/mousetrap/app/ui/main.py           |    4 +-
 src/mousetrap/app/ui/settings_gui.py   |    3 +-
 src/mousetrap/app/ui/widgets.py        |    2 +-
 src/mousetrap/ocvfw/dev/camera.py      |    1 -
 8 files changed, 59 insertions(+), 835 deletions(-)
---
diff --git a/src/mousetrap/app/addons/cpu.py b/src/mousetrap/app/addons/cpu.py
index 84ad289..63dd4ff 100644
--- a/src/mousetrap/app/addons/cpu.py
+++ b/src/mousetrap/app/addons/cpu.py
@@ -33,19 +33,22 @@ a_settings = {}
 class Addon(AddonsBase):
 
     def __init__(self, controller):
-        AddonsBase.__init__(self, controller)
+        super(Addon, self).__init__(controller)
 
         GObject.timeout_add(1000, self.check_cpu)
         debug.debug("addon.cpu", "CPU addon started")
 
     def check_cpu(self):
         """
-        Checks the CPU usage.
-
-        Arguments:
-        - self: The main object pointer.
+        Checks the CPU usage for the MouseTrap process and sets it as a message
+        in the status bar.
         """
-        cpu = (Popen("ps -e -o pcpu,pid | grep %s" % str(env.pid), shell=True, 
stdout=PIPE).stdout).read().strip().split(" ")[0]
+        command = "ps -e -o pcpu,pid | grep %s" % env.pid
+
+        process = Popen(command, shell=True, stdout=PIPE)
+
+        cpu = process.stdout.read().strip().split(" ")[0]
 
         self.statusbar_message("CPU: %s" % cpu)
+
         return True
diff --git a/src/mousetrap/app/addons/recalc.py b/src/mousetrap/app/addons/recalc.py
index d767b21..707f4bb 100644
--- a/src/mousetrap/app/addons/recalc.py
+++ b/src/mousetrap/app/addons/recalc.py
@@ -20,7 +20,6 @@
 
 import os
 from gi.repository import Gtk
-from gi.repository import GObject
 import mousetrap.app.debug as debug
 import mousetrap.app.environment as env
 
diff --git a/src/mousetrap/app/ui/dialogs.py b/src/mousetrap/app/ui/dialogs.py
index 591c82a..b2ab60a 100644
--- a/src/mousetrap/app/ui/dialogs.py
+++ b/src/mousetrap/app/ui/dialogs.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
 # MouseTrap
 #
 # Copyright 2009 Flavio Percoco Premoli
@@ -27,6 +29,7 @@ __license__   = "GPLv2"
 from gi.repository import Gtk
 from mousetrap.app.ui.i18n import _
 
+
 def addLabelMessage( dialog, message ):
     """
     Adds a label to the dialog
@@ -38,9 +41,10 @@ def addLabelMessage( dialog, message ):
 
     label = Gtk.Label()
     label.set_use_markup(True)
-    label.set_markup("<span>" + message + "</span>")
+    label.set_markup('<span>' + \
+        message + "</span>")
     label.show()
-#    dialog.hbox.attach(label, left=, top=, width=, height=, )
+    dialog.hbox.pack_start(label, True, True, 0)
 
 def addImage( dialog, stockImage, stock=False):
     """
@@ -59,7 +63,7 @@ def addImage( dialog, stockImage, stock=False):
         pass
     image.set_alignment( 0.0, 0.5 )
     image.show()
-#    dialog.hbox.attach(label, left=, top=, width=, height=, )
+    dialog.hbox.pack_start(image, True, True, 0)
 
 def confirmDialog( message, parent ):
     """
@@ -71,9 +75,9 @@ def confirmDialog( message, parent ):
     """
 
     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))
+                            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()
@@ -120,7 +124,7 @@ def messageDialog( title, message, parent, stockImage, stock = True ):
     - 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))
+                            (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
 
     addImage( dialog, stockImage, stock)
     addLabelMessage( dialog, message )
@@ -150,31 +154,23 @@ def createDialog( title, parent, flags, buttons ):
     - 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 = 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 )
 
-    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)
+    hbox = Gtk.HBox(spacing=4)
 
-    vbox.add(hbox)
-    vbox.attach_next_to(bbox, hbox, Gtk.PositionType.BOTTOM, 1, 1)
-    dialog.add(vbox)
+    dialog.vbox.pack_start(hbox, True, True, 0)
 
-    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):
@@ -188,40 +184,37 @@ class IdmSettings(Gtk.Window):
         cfg: The config object.
         stgs: The idm's settings dict to parse.
         """
-        GObject.GObject.__init__(self)
+        super(IdmSettings, self).__init__()
 
         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.main_vbox = Gtk.VBox(spacing=6)
         self.add_widgets()
 
-        buttons_box = Gtk.Grid()
-        buttons_box.set_row_spacing(6)
+        buttons_box = Gtk.HBox(spacing=6)
 
         button = Gtk.Button( _("Accept"), stock=Gtk.STOCK_OK )
+
         button.connect("clicked", self.accept_button)
-        buttons_box.add(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.add(button)
+        buttons_box.pack_start(button, False, False, 0)
 
         buttons_box.show_all()
 
-        self.main_vbox.add(buttons_box)
+        self.main_vbox.pack_start(buttons_box, False, False, 0)
 
         self.main_vbox.show_all()
-        # Switched the two lines below around.
-        self.add(self.main_vbox)
         self.show_all()
+        self.add(self.main_vbox)
 
         if not self.cfg.has_section(self.idm):
             self.cfg.add_section(self.idm)
@@ -229,290 +222,70 @@ class IdmSettings(Gtk.Window):
     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.
+        """
+        Adds dinamicaly 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))
+            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 label.
+        """
+        Creates a textbox with a lable.
 
         Arguments:
         - self: The main object pointer.
         - key: The parent key.
-        '''
-        hbox = Gtk.Grid()
-        label = Gtk.Label( _(key.capitalize()) )
-        label.set_use_underline(True)
+        """
+        hbox = Gtk.HBox()
+        label = Gtk.Label(_(key.capitalize()))
+
+        label.set_use_underline( True )
         label.show()
-        hbox.add(label)
+
+        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.add(entry)
+        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
+        return hbox
 
 
 class CairoTransGui( Gtk.Window ):
 
     def __init__( self, message ):
-        GObject.GObject.__init__(self)
+        super(CairoTransGui, self).__init__()
 
         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)
 
@@ -521,7 +294,6 @@ class CairoTransGui( Gtk.Window ):
         self.show_all()
 
     def expose( self, widget, event):
-
         cr = widget.window.cairo_create()
 
         cr.set_operator(1)
@@ -538,3 +310,4 @@ class CairoTransGui( Gtk.Window ):
     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 e120a11..88c6600 100644
--- a/src/mousetrap/app/ui/main.py
+++ b/src/mousetrap/app/ui/main.py
@@ -25,7 +25,6 @@ __copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
 __license__   = "GPLv2"
 
 from gi.repository import Gdk
-from gi.repository import GObject
 from gi.repository import Gtk
 from gi.repository import GdkPixbuf
 from mousetrap.app.ui import dialogs
@@ -49,7 +48,8 @@ class MainGui( Gtk.Window ):
         - controller: The mouseTrap's controller.
         '''
 
-        GObject.GObject.__init__( self )
+        super(MainGui, self).__init__()
+
         self.ctr    = controller
         self.cfg    = controller.cfg
         self.script = self.ctr.script()
diff --git a/src/mousetrap/app/ui/settings_gui.py b/src/mousetrap/app/ui/settings_gui.py
index 543bc4c..0b1aac6 100644
--- a/src/mousetrap/app/ui/settings_gui.py
+++ b/src/mousetrap/app/ui/settings_gui.py
@@ -28,7 +28,6 @@ __date__      = "$Date$"
 __copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
 __license__   = "GPLv2"
 
-from gi.repository import GObject
 from gi.repository import Gtk
 from mousetrap.app.ui import dialogs
 from mousetrap.app.ui.i18n import _
@@ -55,7 +54,7 @@ class PreffGui( Gtk.Window ):
         - mouseTrap: The mouseTrap object pointer.
         """
 
-        GObject.GObject.__init__( self )
+        super(PreffGui, self).__init__()
 
         self.ctr = controller
         self.cfg = self.ctr.cfg
diff --git a/src/mousetrap/app/ui/widgets.py b/src/mousetrap/app/ui/widgets.py
index e388b71..0ee4353 100644
--- a/src/mousetrap/app/ui/widgets.py
+++ b/src/mousetrap/app/ui/widgets.py
@@ -41,7 +41,7 @@ BORDER_WIDTH = 0
 class Mapper(Gtk.Widget):
 
     def __init__(self, width, height):
-        GObject.GObject.__init__(self)
+        super(Mapper, self).__init__()
 
         self.width   = width
         self.height  = height
diff --git a/src/mousetrap/ocvfw/dev/camera.py b/src/mousetrap/ocvfw/dev/camera.py
index 1e64dfb..4ba097f 100644
--- a/src/mousetrap/ocvfw/dev/camera.py
+++ b/src/mousetrap/ocvfw/dev/camera.py
@@ -35,7 +35,6 @@ from warnings import *
 from .. import debug
 from .. import commons as co
 from mousetrap.ocvfw import _ocv as ocv
-from gi.repository import GObject
 import numpy
 import cv2
 


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