mousetrap r16 - in trunk: . po src/mouseTrap src/mouseTrap/scripts/profiles



Author: flaper
Date: Fri Dec 26 12:44:43 2008
New Revision: 16
URL: http://svn.gnome.org/viewvc/mousetrap?rev=16&view=rev

Log:
New Mouse Method. Porting to python2.6

Modified:
   trunk/ChangeLog
   trunk/po/es.po
   trunk/src/mouseTrap/cam.py
   trunk/src/mouseTrap/debug.py
   trunk/src/mouseTrap/mTServer.py
   trunk/src/mouseTrap/mainGui.py
   trunk/src/mouseTrap/mouse.py
   trunk/src/mouseTrap/mouseTrap.py
   trunk/src/mouseTrap/prefGui.py
   trunk/src/mouseTrap/scripts/profiles/screenProfile.py

Modified: trunk/src/mouseTrap/cam.py
==============================================================================
--- trunk/src/mouseTrap/cam.py	(original)
+++ trunk/src/mouseTrap/cam.py	Fri Dec 26 12:44:43 2008
@@ -32,8 +32,7 @@
 try:
     import gtk
 except ImportError, e:
-    module = e.message.split()[-1]
-    sys.stderr.write( "\nmouseTrap needs %s to work correctly. " % module  
+    sys.stderr.write( "\nmouseTrap needs %s to work correctly. " % str(e).split(" ")[-1]
     + "\nPlease check if the file exist in " 
     + " the folder or if it is installed.\n" )
     sys.exit(0)
@@ -51,7 +50,7 @@
     from opencv import cv
     from opencv import highgui
 except:
-    print "This modules depends of opencv libraries"
+    print( "This modules depends of opencv libraries" )
 
         
 class Camera( ocvfw.ocvfw ):
@@ -125,7 +124,7 @@
         try:
             self.cmStartCamera( self.settings.getint( "cam", "inputDevIndex" ) )
             
-            if( self.capture ):
+            if self.capture:
                 gobject.timeout_add(100, self._checkImg)
                 
         except:
@@ -239,6 +238,9 @@
         self.foreheadLast = self.forehead
         
     def checkBlink( self ):
+        """
+        Under Development
+        """
         points = self.cmGetMotionPoints( cv.cvRect( self.forehead.x - 100, 
                                                     self.forehead.y, 
                                                     100, 70) )
@@ -250,7 +252,7 @@
             if self.blink:
                 self.blink = False
                 if curTime - self.lastBlink > 0.5 and curTime - self.lastBlink < 2.5:
-                    print point
+                    print( point )
             else:
                 self.blink = True
                 self.lastBlink = time.time()

Modified: trunk/src/mouseTrap/debug.py
==============================================================================
--- trunk/src/mouseTrap/debug.py	(original)
+++ trunk/src/mouseTrap/debug.py	Fri Dec 26 12:44:43 2008
@@ -48,9 +48,12 @@
 
     level = logging.DEBUG
 
-    if mouseTrap.settings:
-        level = mouseTrap.settings.getint("main", "debugLevel")
-
+    try:
+        if getattr( mouseTrap, "settings" ):
+            level = mouseTrap.settings.getint("main", "debugLevel")
+    except:
+        level = logging.DEBUG
+        
     formatter = logging.Formatter("%(levelname)s: %(name)s -> %(message)s")
 
     cli = logging.StreamHandler( )

Modified: trunk/src/mouseTrap/mTServer.py
==============================================================================
--- trunk/src/mouseTrap/mTServer.py	(original)
+++ trunk/src/mouseTrap/mTServer.py	Fri Dec 26 12:44:43 2008
@@ -34,7 +34,7 @@
 import gobject
 import BaseHTTPServer
 
-import debug
+from . import debug
 
 class _HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
     """
@@ -70,7 +70,7 @@
                 print X + " " + Y
                 self.send_response(200, 'OK')
         else:
-            print "mal"
+            print( "mal" )
 
 #class _HTTPRequestThread(threading.Thread):
 class mTServer:
@@ -99,7 +99,7 @@
                 #debug.log( debug.MODULES, "Highest")
 
         if not connected:
-            print "problems"
+            print( "problems" )
         else:
             thread.start_new_thread(self.__handler, ())
             

Modified: trunk/src/mouseTrap/mainGui.py
==============================================================================
--- trunk/src/mouseTrap/mainGui.py	(original)
+++ trunk/src/mouseTrap/mainGui.py	Fri Dec 26 12:44:43 2008
@@ -432,7 +432,7 @@
 	"""
         for area in self.areas:
             self.drawRectangle( self.context,  area.xInit, area.yInit, 
-                                area.width, area.height, (255, 255, 255))
+                                area.width, area.height, (0, 0, 102))
 	    if area.drawCorners:
 		self.drawCorners( area )
  		

Modified: trunk/src/mouseTrap/mouse.py
==============================================================================
--- trunk/src/mouseTrap/mouse.py	(original)
+++ trunk/src/mouseTrap/mouse.py	Fri Dec 26 12:44:43 2008
@@ -28,6 +28,7 @@
 __license__   = "GPLv2"
 
 import gtk
+import debug
 import pyatspi
 import environment as env
 import Xlib.ext.xtest as xtest
@@ -53,7 +54,7 @@
 isGnome = False
 if env.desktop == "gnome":
     isGnome = True
-    debug.debug( "mousetrap.mouse", _( "GNOME desktop has been detected" ) )
+    debug.debug( "mousetrap.mouse", "GNOME desktop has been detected" )
     
     ## pyatspi registry for gnome users
     reg = pyatspi.Registry

Modified: trunk/src/mouseTrap/mouseTrap.py
==============================================================================
--- trunk/src/mouseTrap/mouseTrap.py	(original)
+++ trunk/src/mouseTrap/mouseTrap.py	Fri Dec 26 12:44:43 2008
@@ -31,10 +31,10 @@
 import os 
 
 try:
-    import debug
-    import dialogs
+    from . import debug
+    from . import dialogs
 except ImportError, e:
-    sys.stderr.write( "\nmouseTrap needs %s to work correctly. " % e.message.split()[-1]
+    sys.stderr.write( "\nmouseTrap needs %s to work correctly. " % str(e).split(" ")[-1]
     + "\nPlease check if the file exist in " 
     + " the folder or if it is installed.\n" )
     sys.exit(0)
@@ -44,23 +44,24 @@
 from mTi18n import _
 
 try:
-    import mouse
+    from . import mouse
     import shutil
     import getopt
     import gobject
-    import mTSettings
+    from . import mTSettings
     import mouseTrapPref as mTPref
 except ImportError, e:
+    print( e.args[0] )
     dialogs.errorDialog( 
-            "mouseTrap needs <b>%s</b> to work correctly. " % e.message.split()[-1]
+            "mouseTrap needs <b>%s</b> to work correctly. " % str(e).split(" ")[-1]
             + "\nPlease check if the file exist in "  
             + " the folder or if it is installed.", None )
-    debug.exception( "mousetrap", "ImportError: %s" % e.message.split()[-1] )
+    debug.exception( "mousetrap", "ImportError: %s" % str(e).split(" ")[-1] )
     sys.exit(0)
     
 # We don't want mouseTrap to fail for it.
 try:
-    import profiling
+    from . import profiling
 except:
     pass
 
@@ -266,8 +267,7 @@
     if needed.
     """
     
-    if settings.get( "main", "startCam" ):
-        modules["cam"].cmCleanLKPoints()
+    modules["cam"].cmCleanLKPoints() if settings.get( "main", "startCam" ) else None
 
 # For Profiling pourpouse uncoment the next line
 # The profile file will be saved in the user config folder
@@ -302,8 +302,7 @@
         for opt, val in opts:
             
             # This will change the default video device input
-            if opt in ("-i"):
-                settings.set( "cam", "inputDevIndex", val )
+            settings.set( "cam", "inputDevIndex", val ) if opt in ("-i") else None
                 
             if opt in ("-e", "--enable"):
                 value = val.strip()
@@ -338,7 +337,7 @@
             # Whe the timeout is reached the listener will attempt
             # to get the nearest icon in case the listener is enabled.
             if opt in ("-v", "--version"):
-                print env.version
+                print( env.version )
                 quit(0)
                     
             # This will show the usage of mouseTrap
@@ -352,7 +351,7 @@
               #  quit(0)
                 
     except getopt.GetoptError, err:
-        print str(err)
+        print( str(err) )
         usage()
         quit(2)
 
@@ -365,7 +364,7 @@
         gobject.threads_init()
         loop.run()
     except KeyboardInterrupt:
-        print "KeyboardInterrupt"
+        print("KeyboardInterrupt")
         quit(0)
     except:
         debug.exception( "mousetrap", "Mousetrap failed starting the loops" )
@@ -375,7 +374,7 @@
     """
     This function shows the usage and the mouseTraps options.
     """
-    print _("Usage: mouseTrap [OPTION...]")
+    print( _("Usage: mouseTrap [OPTION...]") )
     
     # '-?, --help' that is used to display usage information.
     #
@@ -385,32 +384,32 @@
     
     # Option:
     # '-i' that is used to set the input camera index. E.g: -i 0
-    print "-i                    " + \
-            _("              Input video device index. E.g -i 0")
+    print( "-i                    " + \
+            _("              Input video device index. E.g -i 0") )
 
     # Options:
     # -e, --enable Allow the users to enable modules not permantly
-    print "-e, --enable=[" \
+    print( "-e, --enable=[" \
         + _("main-window") + "|" \
-        + _("cam") + "]",
+        + _("cam") + "]" ),
     
-    print _("     Enable the selected options")
+    print( _("     Enable the selected options") )
     
     # Options:
     # -d, --disable Allow the users to disable modules not permanently.
-    print "-d, --disable=[" \
+    print( "-d, --disable=[" \
         + _("main-window") + "|" \
-        + _("cam") + "]",
+        + _("cam") + "]" ),
         
-    print _("    Disable the selected options")
+    print( _("    Disable the selected options") )
     
     # Options:
     # -t --timeout To change the mouse timeout not permanently.
-    print "-v, --version      " + \
-            _("                 Shows mouseTrap version")
+    print( "-v, --version      " + \
+            _("                 Shows mouseTrap version") )
     
-    print
-    print _("Report bugs to flaper87 flaper87 org")
+    print("")
+    print( _("Report bugs to flaper87 flaper87 org") )
     
     
 def quit( exitcode=1 ):  
@@ -421,7 +420,5 @@
     - exitcode: The exitcode number. It helps to handle some quit events.
     """
 
-    if settings.getboolean( "main", "startCam"): 
-        modules["events"].stopMapperListener()
-
+    modules["events"].stopMapperListener() if settings.getboolean( "main", "startCam") else None
     sys.exit(exitcode)

Modified: trunk/src/mouseTrap/prefGui.py
==============================================================================
--- trunk/src/mouseTrap/prefGui.py	(original)
+++ trunk/src/mouseTrap/prefGui.py	Fri Dec 26 12:44:43 2008
@@ -330,7 +330,7 @@
 
     def _checkToggled( self, widget, section, option ):
         """
-        Sets the new value in the settings object for the toggled checkbox
+0        Sets the new value in the settings object for the toggled checkbox
 
         Arguments:
         - self: The main object pointer.

Modified: trunk/src/mouseTrap/scripts/profiles/screenProfile.py
==============================================================================
--- trunk/src/mouseTrap/scripts/profiles/screenProfile.py	(original)
+++ trunk/src/mouseTrap/scripts/profiles/screenProfile.py	Fri Dec 26 12:44:43 2008
@@ -40,7 +40,8 @@
 setName = "screen"
 
 ## Internal Modes
-modes = { "screen|none"  :  _( "Mouse Screen Mode" ) }
+modes = { "screen|abs"  :  _( "Mouse Absolute Movements" ),
+          "screen|rel"  :  _( "Mouse Relative Movements")}
 
 
 class Profile:
@@ -59,20 +60,31 @@
 
         ## Preference Vars and WidgetsTypes
         self.pref = { "vScreen" : "label" }
-        
+
+        self.gui      = gui
         self.mTp      = mouseTrap
         self.settings = mouseTrap.settings
-        self.gui = gui
 
-        self.last = time.time()
+        self.locked   = False
+        self.lastLock = time.time()
+
+        self.last    = time.time()
         self.mpClick = [ 0, 0, 0, 0, 0, 0 ]
         
         self._loadSettings()
 
-        self.area = MapperArea()
-
+        self.area     = MapperArea()
+        self.brCorner = MapperArea()
+        self.trCorner = MapperArea()
+        self.blCorner = MapperArea()
+        self.tlCorner = MapperArea()
+        
         self.area.area( self.vScreen["startX"], self.vScreen["startY"], self.vScreen["endX"], self.vScreen["endY"] )
-            
+        self.brCorner.area( self.vScreen["endX"] - 15, self.vScreen["endY"] - 15, self.vScreen["endX"], self.vScreen["endY"] )
+        self.trCorner.area( self.vScreen["endX"] - 15, self.vScreen["startY"], self.vScreen["endX"], self.vScreen["startY"] + 15 )
+        self.blCorner.area( self.vScreen["startX"], self.vScreen["endY"] - 15, self.vScreen["startX"] + 15, self.vScreen["endY"] )
+        self.tlCorner.area( self.vScreen["startX"], self.vScreen["startY"], self.vScreen["startX"] + 15, self.vScreen["startY"] + 15 )
+
         self._registerMapperEvents()
 
     def _loadSettings( self ):
@@ -117,7 +129,20 @@
 
         self.area.connect( "point-move", self._moveScreenMode, out = False )
         self.area.connect( "point-move", self._timeUpdate, out = True )
+        self.brCorner.connect( "point-move", self._mouseLocker, out = False )
+        self.trCorner.connect( "point-move", self._mouseLocker, out = False )
+        self.blCorner.connect( "point-move", self._mouseLocker, out = False )
+        self.tlCorner.connect( "point-move", self._mouseLocker, out = False )
         self.gui.mapper.registerArea( self.area  )
+        self.gui.mapper.registerArea( self.brCorner )
+        self.gui.mapper.registerArea( self.trCorner )
+        self.gui.mapper.registerArea( self.blCorner )
+        self.gui.mapper.registerArea( self.tlCorner )
+
+    def _mouseLocker( self, *args, **kwds ):
+        if time.time() - self.lastLock > 3:
+            self.locked   = not self.locked
+            self.lastLock = time.time()
         
     def _timeUpdate( self, *args, **kwds ):
         """
@@ -142,6 +167,10 @@
             self.last = time.time()
             return
         
+        if self.settings.get( "cam", "mouseMode" ).endswith("rel"):
+            self._relMovement()
+            return
+        
         diff = mouseTrap.getModVar( "cam", "foreheadDiff")
         
         if time.time() - self.last >= 0.2 and not abs(diff.x) >= 3 and not abs(diff.y) >= 3:
@@ -162,6 +191,24 @@
             self.last = time.time()
             mouseTrap.mice( "move", newX, newY )
 
+    def  _relMovement( self ):
+        """
+        Performs relative mouse movements
+        """
+
+        if self.locked:
+            return False
+
+        diff = mouseTrap.getModVar( "cam", "foreheadDiff" )
+
+        curX, curY = mouseTrap.mice( "position" )
+        
+        newX, newY = ( curX + diff.x, curY - diff.y )
+
+        if not curX == newX or not curY == newY:
+            self.last = time.time()
+            mouseTrap.mice( "move", newX, newY)
+        
     def prefTab( self, prefGui ):
         """
         This is the preferences tab function for the Screen Mode Profile.



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