mousetrap r10 - in trunk/src/mouseTrap: . scripts/profiles
- From: flaper svn gnome org
- To: svn-commits-list gnome org
- Subject: mousetrap r10 - in trunk/src/mouseTrap: . scripts/profiles
- Date: Sun, 28 Sep 2008 19:51:53 +0000 (UTC)
Author: flaper
Date: Sun Sep 28 19:51:53 2008
New Revision: 10
URL: http://svn.gnome.org/viewvc/mousetrap?rev=10&view=rev
Log:
Tasks #14 and #15 Closed. Version 0.4 released.
Added:
trunk/src/mouseTrap/mTSettings.py (contents, props changed)
Modified:
trunk/src/mouseTrap/cam.py
trunk/src/mouseTrap/debug.py
trunk/src/mouseTrap/dialogs.py
trunk/src/mouseTrap/environment.py.in
trunk/src/mouseTrap/events.py
trunk/src/mouseTrap/mTDbus.py
trunk/src/mouseTrap/mainGui.py
trunk/src/mouseTrap/mouse.py
trunk/src/mouseTrap/mouseTrap.py
trunk/src/mouseTrap/mouseTrapPref.py
trunk/src/mouseTrap/mousetrap.in
trunk/src/mouseTrap/ocvfw.py
trunk/src/mouseTrap/prefGui.py
trunk/src/mouseTrap/scripts.py
trunk/src/mouseTrap/scripts/profiles/dragProfile.py
trunk/src/mouseTrap/scripts/profiles/holdProfile.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 Sun Sep 28 19:51:53 2008
@@ -83,7 +83,7 @@
# MOTION RELATED VARIABLES #
##############################
- self.step = self.settings.stepSpeed
+ self.step = self.settings.getint( "mouse", "stepSpeed" )
self.forehead = None
self.foreheadLast = None
self.foreheadOrig = None
@@ -123,13 +123,13 @@
"""
try:
- self.cmStartCamera( self.settings.inputDevIndex )
+ self.cmStartCamera( self.settings.getint( "cam", "inputDevIndex" ) )
if( self.capture ):
gobject.timeout_add(100, self._checkImg)
except:
- debug.exception( "mouseTrap.cam", _( "The Camera Module load failed." ) )
+ debug.exception( "mouseTrap.cam", "The Camera Module load failed." )
def _checkImg( self ):
@@ -140,7 +140,7 @@
- self: The main object pointer.
"""
- self.cmQueryCapture( flip = self.settings.flipImage )
+ self.cmQueryCapture( flip = self.settings.getboolean( "cam", "flipImage" ) )
# create a self.gray version of the self.img
cv.cvCvtColor (self.img, self.grey, cv.CV_BGR2GRAY)
@@ -229,7 +229,7 @@
self.mpPointer = cv.cvPoint( 100 - (self.forehead.x - self.foreheadOrig.x),
80 + (self.forehead.y - self.foreheadOrig.y))
-
+
#if abs(self.foreheadLast.x - self.forehead.x) >= 15 or \
# abs(self.foreheadLast.y - self.forehead.y) >= 15:
Modified: trunk/src/mouseTrap/debug.py
==============================================================================
--- trunk/src/mouseTrap/debug.py (original)
+++ trunk/src/mouseTrap/debug.py Sun Sep 28 19:51:53 2008
@@ -34,6 +34,8 @@
import environment as env
+modules = {}
+
def checkModule( module ):
"""
Get's a new logger for modules.
@@ -41,15 +43,17 @@
Arguments:
- module: The module requesting a logger.
"""
-
- if module == "mousetrap":
- level = logging.DEBUG
- else:
- level = mouseTrap.settings.debugLevel
+
+ global modules
+
+ level = logging.DEBUG
+
+ if mouseTrap.settings:
+ level = mouseTrap.settings.getint("main", "debugLevel")
formatter = logging.Formatter("%(levelname)s: %(name)s -> %(message)s")
- cli = logging.StreamHandler()
+ cli = logging.StreamHandler( )
cli.setLevel( level )
cli.setFormatter(formatter)
@@ -58,10 +62,9 @@
file.setFormatter(formatter)
modules[module] = logging.getLogger( module )
- modules[module].setLevel( level )
modules[module].addHandler(cli)
modules[module].addHandler(file)
-
+ modules[module].setLevel( level )
def debug( module, message ):
"""
Modified: trunk/src/mouseTrap/dialogs.py
==============================================================================
--- trunk/src/mouseTrap/dialogs.py (original)
+++ trunk/src/mouseTrap/dialogs.py Sun Sep 28 19:51:53 2008
@@ -302,6 +302,8 @@
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 ):
"""
@@ -312,6 +314,7 @@
- args: The event arguments
"""
self.hide()
+ mouseTrap.setState( "active" )
def pressButton( self, *args ):
"""
@@ -368,6 +371,7 @@
"""
self.gui.clickDlgHandler( button )
+ self.hidePanel()
def _newImageButton( self, label, image ):
"""
Modified: trunk/src/mouseTrap/environment.py.in
==============================================================================
--- trunk/src/mouseTrap/environment.py.in (original)
+++ trunk/src/mouseTrap/environment.py.in Sun Sep 28 19:51:53 2008
@@ -72,7 +72,7 @@
profilesPath = "%s/profiles/" % scriptsPath
## The config file
-configFile = configPath + "userSettings.py"
+configFile = configPath + "userSettings.cfg"
## The debug file
debugFile = configPath + "mouseTrap_DEBUG.log"
@@ -98,3 +98,15 @@
## Mose Movement Modes
mouseModes = { }
+
+###################################################
+# #
+# MOUSETRAP'S STATES DEFINITION #
+# #
+###################################################
+
+## Mousetrap is active and the mouse pointer can be moved
+ACTIVE = "active"
+
+## Mousetrap is active and the click dialog is not hidden.
+CLKDLG = "clk-dialog"
Modified: trunk/src/mouseTrap/events.py
==============================================================================
--- trunk/src/mouseTrap/events.py (original)
+++ trunk/src/mouseTrap/events.py Sun Sep 28 19:51:53 2008
@@ -33,8 +33,7 @@
import gobject
import mouseTrap
-#from mouseTrap import settings
-
+from mouseTrap import settings
# The Locker for the event listener
RUN = True
@@ -45,12 +44,152 @@
# A dictionary for the events registered
mapperEvents = dict()
+# A list for the registered events
+regEvents = []
+
+# A list for the registered triggers
+regTriggers = []
+
# A dictionary for the conditions that can exist.
conditions = dict()
+
+eventTypes = [ "point-move",
+ "top-left-corner",
+ "top-right-corner",
+ "bottom-left-corner",
+ "bottom-right-corner" ]
+
+def registerArea( area ):
+ """
+ This function register new events for the Mapper that are going
+ to be executed if the mapper pointer is located inseide the range area
+ created by the initCoords and the endCoords selected.
+
+ Arguments:
+ - area: The area to be registered.
+ """
+
+ global regEvents
+
+ regEvents.append( area )
+ debug.debug( "events", "New Area Listener Added" )
+
+def registerTrigger( trigger ):
+ """
+ This functions is used to register a new trigger.
+
+ Arguments:
+ - trigger: A dictionary with the trigger information.
+ """
+
+ global regTriggers
+
+ regTriggers.append( trigger )
+def checkEvents( ):
+ """
+ Checks if an event is being executed and calls the callback function if
+ the conditions supplied are right.
+ """
+
+ for area in regEvents:
+ for ev in eventTypes:
+ for i, reg in enumerate( area.events[ev] ):
+ event = area.events[ev][i]
+ if event["state"] == mouseTrap.getState() and checkCond( ev, area, i ):
+ event["callback"]( *event["args"], **event["kwds"] )
+
+ for trigger in regTriggers:
+ if isAbove( trigger["X"], trigger["Y"]) and isOnTime( trigger["last"], 2):
+ trigger["last"] = time.time()
+ trigger["callback"]( trigger["args"], trigger["kwds"] )
+
+ return RUN
+
+def isOnTime( last, delay ):
+ """
+ Check if the event can be executed based on the delay time.
+
+ Arguments:
+ - last: The last time the event was executed.
+ - delay: The delay in seconds
+ """
+ if time.time() - last >= delay:
+ return True
+
+ return False
+
+def isAbove( X, Y ):
+ """
+ Check if the mouse possition is equal to the X and Y coords
+
+ It use a range of ( x - 2, x + 2) and ( y -2, y + 2 ) so it
+ is easier to access the point.
+
+ Arguments:
+ - X: The X possition.
+ - Y: The Y possition.
+ """
+
+ if mapper.pointer[0] in xrange( X - 2, X + 2) and mapper.pointer[1] in xrange( Y - 2, Y + 2):
+ return True
+
+ return False
+
+def checkCond( ev, area, i ):
+ """
+ Checks if any of the possible conditions is being fired.
+
+ Arguments:
+ - ev: The event type to check
+ - area: The area that is being checked.
+ - i: The index in the events to check.
+ """
+
+ if ev == "point-move":
+ if area.events[ ev ][i]["kwds"]["out"] and isInside( area ):
+ return False
+ elif not area.events[ ev ][i]["kwds"]["out"] and not isInside( area ):
+ return False
+ return True
+ elif ev == "top-left-corner":
+ if mapper.pointer[0] in xrange( area.xInit, area.xInit + 2) \
+ and mapper.pointer[1] in xrange( area.yInit, area.yInit + 2):
+ return True
+ return False
+
+ elif ev == "top-right-corner":
+ if mapper.pointer[0] in xrange( area.xInit + area.width - 2, area.xInit + area.width) \
+ and mapper.pointer[1] in xrange( area.yInit, area.yInit + 2):
+ return True
+ return False
+
+ elif ev == "bottom-left-corner":
+ if mapper.pointer[0] in xrange( area.xInit + area.width - 2, area.xInit + area.width) \
+ and mapper.pointer[1] in xrange( area.yInit + area.height - 2, area.yInit + area.height):
+ return True
+ return False
+
+ elif ev == "bottom-right-corner":
+ if mapper.pointer[0] in xrange( area.xInit, area.xInit + 2) \
+ and mapper.pointer[1] in xrange( area.yInit + area.height - 2, area.yInit + area.height ):
+ return True
+ return False
+
+def isInside( area ):
+ """
+ Checks if the mapper point is inside the requested area.
+
+ Arguments:
+ - area: The requested area to check.
+ """
+ if mapper.pointer[0] in xrange( area.xInit, area.xEnd ) and mapper.pointer[1] in xrange( area.yInit, area.yEnd):
+ return True
+ return False
+
def hasMapperEvent( eventName ):
"""
- Let us know if an event with the name "eventName" has been registered.
+ Let us know if an event with the name 'eventName' has been registered.
Arguments:
- eventName: The name of the event to check.
@@ -62,38 +201,6 @@
return True
return False
-def registerMapperEvent( eventName, initCoords, endCoords, inside, eventCond, eventAction, timeout, *args, **kw):
- """
- This function register new events for the Mapper that are going
- to be executed if the mapper pointer is located inseide the range area
- created by the initCoords and the endCoords selected.
-
- Arguments:
- - eventName: The name of the event to register.
- - initCoords: The initial coordinates where the event can be recognized.
- - endCoords: The final coordinates where the event can be recognized.
- - inside: True if the pointer has to be inside the selected area.
- - eventCond: The conditions that should exist to executed the event.
- - eventAction: The callback function.
- - timeout: The callback function timeout.
- - *args: The areguments that are going to be passed to the callback.
- """
-
- #if mapperEvents.has_key( eventName ):
- # debug.log( debug.MODULES, _( "Warning" ) )
- # sys.stderr.write( "\nThe event name %s is already in use\n" % eventName )
-
- mapperEvents[eventName] = { "eventCond" : eventCond,
- "function" : eventAction,
- "initCoords" : initCoords,
- "endCoords" : endCoords,
- "inside" : inside,
- "timeout" : timeout,
- "last" : time.time(),
- "args" : args,
- "kw" : kw
- }
-
def startMapperListener( mapperObj ):
"""
Starts the MapperListener creating a new timeout object that
@@ -113,51 +220,11 @@
"clickDlgVisible" : "mouseTrap.modules['gui'].clickDialog.props.visible"}
try:
- gobject.timeout_add( 10, _checkMapperEvents )
+ gobject.timeout_add( 40, checkEvents )
except:
- debug.exception( "mouseTrap.events", _( "The events module load failed" ) )
+ debug.exception( "events", _( "The events module load failed" ) )
-def _checkMapperEvents():
- """
- Checks if an event is being executed and calls the callback function if
- the conditions supplied are right.
- """
-
- for event,prop in mapperEvents.iteritems():
- _controlEvent( event, prop )
- return RUN
-
-def _controlEvent( event, prop ):
- """
- Executes the control for each event registered.
-
- Arguments:
- - event: The event to check
- - prop: The event properties.
- """
-
- if mapper.pointer[0] in xrange( prop["initCoords"][0], prop["endCoords"][0]) and \
- mapper.pointer[1] in xrange( prop["initCoords"][1], prop["endCoords"][1]) and prop["inside"]:
- for cond in prop["eventCond"]:
- if not cond.split(":")[1] in str(eval(conditions[cond.split(":")[0]])):
- return False
- if not time.time() - prop["last"] >= prop["timeout"]:
- return False
- prop["function"]( *prop["args"], **prop["kw"] )
- prop["last"] = time.time()
- elif ( mapper.pointer[0] not in xrange( prop["initCoords"][0], prop["endCoords"][0]) or \
- mapper.pointer[1] not in xrange( prop["initCoords"][1], prop["endCoords"][1])) and not prop["inside"]:
- for cond in prop["eventCond"]:
- if not cond.split(":")[1] in str(eval(conditions[cond.split(":")[0]])):
- return False
- if not time.time() - prop["last"] >= prop["timeout"]:
- return False
- prop["function"]( *prop["args"], **prop["kw"] )
- prop["last"] = time.time()
-
- return True
-
def stopMapperListener():
"""
This will stop the Mapper Event Listener changing the value
@@ -167,3 +234,4 @@
global RUN
RUN = False
+ debug.debug("events", "Event's handler has been stoped" )
Modified: trunk/src/mouseTrap/mTDbus.py
==============================================================================
--- trunk/src/mouseTrap/mTDbus.py (original)
+++ trunk/src/mouseTrap/mTDbus.py Sun Sep 28 19:51:53 2008
@@ -79,7 +79,7 @@
try:
dbusserver = mTDbusServer()
except:
- debug.exception( "mouseTrap.mTDbus", _( "The dbus server load failed" ) )
+ debug.exception( "mouseTrap.mTDbus", "The dbus server load failed" )
def shutdown():
Added: trunk/src/mouseTrap/mTSettings.py
==============================================================================
--- (empty file)
+++ trunk/src/mouseTrap/mTSettings.py Sun Sep 28 19:51:53 2008
@@ -0,0 +1,8 @@
+import ConfigParser
+
+
+class Settings( ConfigParser.ConfigParser ):
+
+ def optionxform( self, optionstr ):
+ return optionstr
+
Modified: trunk/src/mouseTrap/mainGui.py
==============================================================================
--- trunk/src/mouseTrap/mainGui.py (original)
+++ trunk/src/mouseTrap/mainGui.py Sun Sep 28 19:51:53 2008
@@ -30,6 +30,7 @@
import gtk
import debug
+import events
import scripts
import dialogs
import mouseTrap
@@ -125,13 +126,13 @@
hBox = gtk.HBox()
showMapper = gtk.CheckButton( _("Start Point Mapper: ") )
- showMapper.set_active( self.settings.showPointMapper )
+ showMapper.set_active( self.settings.getboolean( "gui", "showPointMapper" ) )
showMapper.connect("toggled", lambda x: self.mapper.show()
if x.get_active() else self.mapper.hide())
hBox.pack_start( showMapper, False, False )
showCapture = gtk.CheckButton( _("Show Capture: ") )
- showCapture.set_active( self.settings.showCapture )
+ showCapture.set_active( self.settings.getboolean( "gui", "showCapture" ) )
showCapture.connect("toggled", lambda x: self.capture.show()
if x.get_active() else self.capture.hide())
hBox.pack_start( showCapture, False, False )
@@ -259,7 +260,7 @@
except ImportError:
dialogs.errorDialog(
"mouseTrap needs <b>gnome</b> module to show the help. Please install gnome-python and try again.", None )
- debug.exception( "mousetrap.mainGui", _( "The help load failed" ) )
+ debug.exception( "mainGui", "The help load failed" )
def close( self, *args ):
"""
@@ -295,14 +296,15 @@
self.mTp = mouseTrap
self.settings = mouseTrap.settings
+ self.areas = []
+ self.axis = False
self.context = None
self.set_size_request(200, 160)
self.add_events( gtk.gdk.BUTTON_PRESS_MASK |
gtk.gdk.BUTTON_RELEASE_MASK |
gtk.gdk.BUTTON1_MOTION_MASK )
- self.triggers = { 'scU' : 'orange',
- 'scD' : 'orange' }
+ self.triggers = []
self.connect("expose_event", self.expose)
@@ -310,8 +312,48 @@
self.desp = 0
self.pointer = [ 0, 0 ]
+
+ def registerArea( self, area ):
+ """
+ Registers a new area.
+
+ Arguments:
+ - self: The main object pointer.
+ - area: The area to register
+ """
+ self.areas.append( area )
+
+ def registerTrigger( self, X, Y, size, callback, *args, **kwds ):
+ """
+ Registers a new trigger.
+
+ Arguments:
+ - self: The main object pointer.
+ - X: The X possition.
+ - Y: The Y possition.
+ - size: The trigger point size.
+ - callback: The callback function
+ - *args: Extra arguments to pass to the callback function.
+ - **kwds: Extra keywords to pass to the callback function.
+ """
+ self.triggers.append( { "X" : X, "Y" : Y, "size" : size } )
+
+ events.registerTrigger( { "X" : X, "Y" : Y, "size" : size, "last" : 0,
+ "callback" : callback, "args" : args, "kwds" : kwds })
def drawRectangle( self, context, initX, initY, width, height, color ):
+ """
+ Draws a rectangle in the DrawingArea.
+
+ Arguments:
+ - context: The Cairo Context.
+ - initX: The initial X possition.
+ - initY: The initial Y possition.
+ - width: The rectangle width.
+ - height: The rectangle height.
+ - color: An RGB color tuple. E.g: ( 255, 255, 255 )
+ """
+
r, g, b = color
context.set_source_rgb(r, g, b)
context.rectangle( initX, initY, width, height)
@@ -346,37 +388,108 @@
event.area.width, event.area.height)
self.context.clip()
- scripts.loaded.drawMapper( self.context )
-
+ if "clk-dialog" in mouseTrap.getState():
+ self.dialogMapper()
+ return True
+
+ if self.axis:
+ self.drawAxis()
+
+ self.drawAreas()
+ self.drawTriggers()
+
pointer = mouseTrap.getModVar( "cam", "mpPointer" )
if pointer:
- self.drawPoint(self.context, pointer.x, pointer.y, 4)
+ self.drawPoint( pointer.x, pointer.y, 4 )
return True
+
+ def drawTriggers( self ):
+ """
+ Draws the registered triggers.
+
+ Arguments:
+ - self: The main object pointer.
+ """
+ for trigger in self.triggers:
+
+ color = "orange"
+
+ if self.pointer[0] in xrange( trigger["X"] - 2, trigger["X"] + 2 ) \
+ and self.pointer[1] in xrange( trigger["Y"] - 2, trigger["Y"] + 2 ):
+ color = "blue"
+
+ self.drawPoint( trigger["X"], trigger["Y"], trigger["size"], color )
+
+ def drawAreas( self ):
+ """
+ Draws the areas and the parts requested ( Corner's Points, Axis)
+
+ Arguments:
+ - self: The main object pointer.
+ """
+ for area in self.areas:
+ self.drawRectangle( self.context, area.xInit, area.yInit,
+ area.width, area.height, (255, 255, 255))
+ if area.drawCorners:
+ self.drawCorners( area )
+
+
+ def drawAxis( self ):
+ """
+ Draws the axis of the plane
+
+ Arguments:
+ - self: The main object pointer
+ """
+
+ self.drawLine( self.context, 100, 0, 100, 160, (255, 255, 255))
+
+ self.drawLine( self.context, 0, 80, 200, 80, (255, 255, 255))
+
+ def drawCorners( self, area):
+ """
+ Draw the corner's points for the given area.
+
+ Arguments:
+ - self: The main object pointer.
+ - area: The area requesting the corners
+ """
+
+ self.drawPoint( area.xInit, area.yInit, 3, "orange")
- def drawPoint(self, context, X, Y, size, color = 'green'):
+ self.drawPoint( area.xEnd, area.yEnd, 3, "orange" )
+
+ self.drawPoint( area.xEnd, area.yInit, 3, "orange" )
+
+ self.drawPoint( area.xInit, area.yEnd, 3, "orange" )
+
+ def drawPoint(self, X, Y, size, color = 'green'):
"""
Draws the point
Arguments:
- self: The main object pointer.
- - context: The Cairo Context
+ - X: The X possition.
+ - Y: The Y possition
+ - size: The point diameter.
+ - color: A RGB color tuple. E.g (255,255,255)
"""
-
+
self.pointer = [ X, Y ]
- context.move_to( X, Y)
- context.arc(X, Y, size, 0, 2 * pi)
+ self.context.move_to( X, Y)
+ self.context.arc(X, Y, size, 0, 2 * pi)
if color == 'green':
- context.set_source_rgb(0.7, 0.8, 0.1)
+ self.context.set_source_rgb(0.7, 0.8, 0.1)
elif color == 'blue':
- context.set_source_rgb(0.5, 0.65, 12)
+ self.context.set_source_rgb(0.5, 0.65, 12)
else:
- context.set_source_rgb(10, 0.8, 0.1)
+ self.context.set_source_rgb(10, 0.8, 0.1)
- context.fill_preserve()
- context.stroke()
+ self.context.fill_preserve()
+ self.context.stroke()
return True
def drawLine( self, ctx, x1, y1, x2, y2, color ):
@@ -399,7 +512,68 @@
ctx.set_source_rgb( color[0], color[1], color[2])
ctx.stroke()
return True
+
+ def dialogMapper( self ):
+
+ reqLim = 10
+
+ self.context.set_font_size( 20 )
+ self.context.set_source_rgb( 255, 255, 255 )
+
+ self.drawRectangle( self.context, 100 - reqLim, 80 - reqLim, reqLim*2, reqLim*2, (255,255,255))
+
+class MapperArea:
+
+ def __init__( self ):
+
+ self.xInit = None
+ self.yInit = None
+ self.xEnd = None
+ self.yEnd = None
+ self.width = None
+ self.height = None
+ self.drawCorners = False
+
+ self.events = None
+
+ self.events = { "point-move" : [],
+ "top-left-corner" : [],
+ "top-right-corner" : [],
+ "bottom-left-corner" : [],
+ "bottom-right-corner" : [] }
+
+
+ self.eventTypes = [ "point-move",
+ "top-left-corner",
+ "top-right-corner",
+ "bottom-left-corner",
+ "bottom-right-corner" ]
+
+ def area( self, xInit, yInit, xEnd, yEnd, corners = False ):
+
+ if not int(xInit) or not int(yInit) or not int(xEnd) or not int(yEnd):
+ debug.error( "mainGui", "All arguments must be INT" )
+
+ self.xInit = xInit
+ self.yInit = yInit
+ self.xEnd = xEnd
+ self.yEnd = yEnd
+
+ self.width = xEnd - xInit
+ self.height = yEnd - yInit
+ self.drawCorners = corners
+
+ def connect( self, eventType, callback, state = "active",*args, **kwds ):
+
+ self.events[ eventType ].append( { "callback" : callback,
+ "state" : state,
+ "args" : args,
+ "kwds" : kwds } )
+
+ events.registerArea( self )
+
+
def showMainGui( ):
"""
Loads the mainGUI components and launch it.
Modified: trunk/src/mouseTrap/mouse.py
==============================================================================
--- trunk/src/mouseTrap/mouse.py (original)
+++ trunk/src/mouseTrap/mouse.py Sun Sep 28 19:51:53 2008
@@ -35,7 +35,7 @@
from Xlib import X, display
clickVal = { X.ButtonPress : 0,
- X.ButtonRelease : 5}
+ X.ButtonRelease : 5 }
clickType = { 'p' : [ X.ButtonPress ],
'r' : [ X.ButtonRelease ],
@@ -53,6 +53,7 @@
isGnome = False
if env.desktop == "gnome":
isGnome = True
+ debug.debug( "mousetrap.mouse", _( "GNOME desktop has been detected" ) )
## pyatspi registry for gnome users
reg = pyatspi.Registry
@@ -60,10 +61,6 @@
## Is the D&D click being used ?
dragging = False
-def handler( func ):
- def wrapper( *arg, **kw ):
- return dsp[arg[0]]( *arg[1:], **kw )
- return wrapper
def position( *arg ):
"""
@@ -74,7 +71,18 @@
return list(gtkDisplay.get_pointer()[1:3])
def click( x = None, y = None, button = "bc1" ):
-
+ """
+ Execute Mouse Clicks. If the mouse is dragging an object
+ then the release click will be performed.
+
+ Arguments:
+ - x: The X coordinate in the screen.
+ - y: The Y coordinate in the screen.
+ - button: The button click that has to be performed.
+
+ Return True
+ """
+
global isGnome
global dragging
@@ -125,4 +133,26 @@
# Dictionary Dispatcher
dsp = { "move" : move,
"click" : click,
- "position" : position }
+ "position" : position }
+
+def handler( func ):
+ """
+ Mouse functions decorator.
+
+ Arguments:
+ - func: The function called to access the decorator.
+
+ Return The wrapper
+ """
+
+ def wrapper( *arg, **kw ):
+ """
+ Wrapper function.
+
+ This functions will execute the required function passing the arguments to it.
+
+ Return the function executed
+ """
+ return dsp[arg[0]]( *arg[1:], **kw )
+
+ return wrapper
Modified: trunk/src/mouseTrap/mouseTrap.py
==============================================================================
--- trunk/src/mouseTrap/mouseTrap.py (original)
+++ trunk/src/mouseTrap/mouseTrap.py Sun Sep 28 19:51:53 2008
@@ -48,13 +48,14 @@
import shutil
import getopt
import gobject
+ import mTSettings
import mouseTrapPref as mTPref
except ImportError, e:
dialogs.errorDialog(
"mouseTrap needs <b>%s</b> to work correctly. " % e.message.split()[-1]
+ "\nPlease check if the file exist in "
+ " the folder or if it is installed.", None )
- debug.log( debug.LOAD, _( "Highest" ) )
+ debug.exception( "mousetrap", "ImportError: %s" % e.message.split()[-1] )
sys.exit(0)
# We don't want mouseTrap to fail for it.
@@ -74,10 +75,17 @@
## Settings Container
settings = None
+## MouseTrap's state ( Active, clk-mode )
+state = "active"
+
@mouse.handler
def mice( *args ):
+ """
+ The mice function pass the args to its decorator. The decorator will
+ execute the required function.
+ """
pass
-
+
def getModVar( module, attr ):
"""
Allow modules to share variables
@@ -117,7 +125,22 @@
return func
except:
return False
-
+
+def getState():
+ """
+ Gets the current mousetrap's state
+ """
+ return state
+
+def setState( newState ):
+ """
+ Sets a new mousetrap's state
+ """
+ global state
+
+ state = newState
+ debug.debug( "mousetrap", "MouseTrap's state changed")
+
def updateView( img ):
"""
This function calls the gui's updateView function
@@ -142,10 +165,11 @@
globals(),
locals(),
[''])
- if settings.showMainGui:
+ if settings.getboolean( "gui", "showMainGui" ):
modules["gui"] = gui.showMainGui( )
+ debug.debug( "mouseTrap", "MainGui has been started" )
except:
- debug.exception( "mosuetrap", _( "Main Gui load failed" ) )
+ debug.exception( "mousetrap", "Main Gui load failed" )
def startCam( ):
"""
@@ -161,12 +185,16 @@
modules["cam"] = cam.Camera()
- if settings.startCam:
+ if settings.getboolean( "main", "startCam" ):
modules["cam"].start()
+ debug.debug( "mouseTrap", "Camera Module has been started" )
except:
- debug.exception( "mousetrap", _( "Camera Module load failed" ) )
+ debug.exception( "mousetrap", "Camera Module load failed" )
def startEventsHandler():
+ """
+ Starts the events handlers script
+ """
global modules
try:
@@ -174,10 +202,11 @@
globals(),
locals(),
[''])
- if settings.startCam:
+ if settings.getboolean( "main", "startCam"):
modules["events"].startMapperListener( modules["gui"].mapper )
+ debug.debug( "mouseTrap", "Events handler has been started" )
except:
- debug.exception( "mosuetrap", _( "Events Handler Load Failed" ) )
+ debug.exception( "mousetrap", "Events Handler Load Failed" )
def startDBus( ):
"""
@@ -192,8 +221,9 @@
locals(),
[''])
dbus.start()
+ debug.debug( "mouseTrap", "DBus Service has been started" )
except:
- debug.exception( "mousetrap", _( "DBus Service Load Failed" ) )
+ debug.exception( "mousetrap", "DBus Service Load Failed" )
def loadSettings( ):
"""
@@ -211,11 +241,13 @@
if not os.path.exists( env.scriptsPath ):
shutil.copytree( "%s/scripts/" % \
env.appPath, env.scriptsPath )
-
- os.chdir(env.configPath)
- settings = __import__( "userSettings" )
+
+ settings = mTSettings.Settings()
+ settings.readfp(open( env.configFile ))
+
+ debug.debug( "mouseTrap", "Settings have been loaded" )
except:
- debug.exception( "mousetrap", _( "Mousetrap Settings load failed." ) )
+ debug.exception( "mousetrap", "Mousetrap Settings load failed." )
sys.exit(0)
else:
try:
@@ -225,7 +257,7 @@
if getattr( modules[mod], "restart" ):
modules[mod].restart()
except:
- debug.exception( "mousetrap", _("Mousetrap Settings reload failed") )
+ debug.exception( "mousetrap", "Mousetrap Settings reload failed" )
def calcPoint():
@@ -234,7 +266,7 @@
if needed.
"""
- if settings.startCam:
+ if settings.get( "main", "startCam" ):
modules["cam"].cmCleanLKPoints()
# For Profiling pourpouse uncoment the next line
@@ -271,7 +303,7 @@
# This will change the default video device input
if opt in ("-i"):
- settings.inputDevIndex = val
+ settings.set( "cam", "inputDevIndex", val )
if opt in ("-e", "--enable"):
value = val.strip()
@@ -279,13 +311,13 @@
# This allows us to disable the main window
# of mouseTrap to have a clearer desktop.
if value == "main-window":
- settings.showMainGui = True
+ settings.set( "gui", "showMainGui", "True" )
# This allows us to enable the webCam
# feature in case it has been disabled.
elif value == "cam":
- settings.startCam = False
+ settings.set( "main", "startCam", "False" )
else:
usage()
quit(2)
@@ -294,9 +326,9 @@
value = val.strip()
if value == "main-window":
- settings.showMainGui = False
+ settings.set( "gui", "showMainGui", "False" )
elif value == "cam":
- settings.startCam = False
+ settings.set( "main", "startCam", "False" )
else:
usage()
quit(2)
@@ -388,4 +420,8 @@
Arguments:
- exitcode: The exitcode number. It helps to handle some quit events.
"""
+
+ if settings.getboolean( "main", "startCam"):
+ modules["events"].stopMapperListener()
+
sys.exit(exitcode)
Modified: trunk/src/mouseTrap/mouseTrapPref.py
==============================================================================
--- trunk/src/mouseTrap/mouseTrapPref.py (original)
+++ trunk/src/mouseTrap/mouseTrapPref.py Sun Sep 28 19:51:53 2008
@@ -31,94 +31,31 @@
from mTi18n import _
-userPref = { 'showMainGui' : 'checkButton',
- 'startCam' : 'checkButton',
- 'showPointMapper' : 'checkButton',
- 'showCapture' : 'checkButton',
- 'flipImage' : 'checkButton',
- 'stepSpeed' : 'spinButton',
- 'debugLevel' : 'spinButton',
- 'inputDevIndex' : 'spinButton',
- 'mouseMode' : 'label',
- 'defClick' : 'label'}
-
-
-def writePref( widgets ):
- """
- Writes the prefferences into the user prefferences file.
-
- Arguments:
- - widgets: A dict() with all the preference widgets objects
- """
-
- prefFile = open( env.configFile, 'w' )
-
- _writeHeader( prefFile)
-
- for uP in userPref.keys():
- prefFile.write("\n\n#" + uP)
- if userPref[uP] == 'checkButton':
- prefFile.write("\n%s = %s" % (uP, str(widgets[uP].get_active())))
- elif userPref[uP] == 'spinButton':
- prefFile.write("\n%s = %s" % (uP, str(widgets[uP].get_value_as_int())))
- elif userPref[uP] == 'label':
- prefFile.write("\n%s = \"%s\"" % (uP, str(widgets[uP].get_label())))
-
- prefFile.write("\n")
- prefFile.close()
-
-
-def _writeHeader( prefFile ):
- """
- Writes the header comments of the preference file.
-
- Arguments:
- - prefFile: The opened prefferences file object
- """
-
- prefFile.write("# -*- coding: utf-8 -*-")
- prefFile.write( _( "\n# This is the user settings File" ) )
- prefFile.write( _( "\n# Please Try to don't edit this file manually" ) )
- prefFile.write( _( "\n# Use the preffGui of mouseTrap.\n" ) )
def writeFirstConf():
prefFile = open( env.configFile, 'w' )
-
- _writeHeader( prefFile)
-
- prefFile.write("\n#flipImage\n")
- prefFile.write("flipImage = False\n")
-
- prefFile.write("\n#showCapture\n")
- prefFile.write("showCapture = True\n")
-
- prefFile.write("\n#stepSpeed\n")
- prefFile.write("stepSpeed = 5\n")
-
- prefFile.write("\n#showPointMapper\n")
- prefFile.write("showPointMapper = True\n")
-
- prefFile.write("\n#startCam\n")
- prefFile.write("startCam = True\n")
- prefFile.write("\n#reqMovement\n")
- prefFile.write("reqMovement = 10\n")
+ prefFile.write( "[gui]\n" )
+ prefFile.write( "showCapture = True\n" )
+ prefFile.write( "showMainGui = True\n" )
+ prefFile.write( "showPointMapper = True\n" )
+
+ prefFile.write( "[access]\n" )
+ prefFile.write( "reqMovement = 10\n" )
+
+ prefFile.write( "[cam]\n" )
+ prefFile.write( "mouseMode = drag|none\n" )
+ prefFile.write( "inputDevIndex = 0\n" )
+ prefFile.write( "flipImage = False\n" )
+
+ prefFile.write( "[main]\n" )
+ prefFile.write( "debugLevel = 10\n" )
+ prefFile.write( "startCam = True\n" )
+
+ prefFile.write( "[mouse]\n" )
+ prefFile.write( "defClick = b1c\n" )
+ prefFile.write( "stepSpeed = 5\n" )
- prefFile.write("\n#mouseMode\n")
- prefFile.write("mouseMode = 'screen|none'\n")
-
- prefFile.write("\n#inputDevIndex\n")
- prefFile.write("inputDevIndex = 0\n")
-
- prefFile.write("\n#debugLevel\n")
- prefFile.write("debugLevel = 10\n")
-
- prefFile.write("\n#defClick\n")
- prefFile.write("defClick = 'b1c'\n")
-
- prefFile.write("\n#showMainGui\n")
- prefFile.write("showMainGui = True\n")
-
prefFile.write("\n")
prefFile.close()
Modified: trunk/src/mouseTrap/mousetrap.in
==============================================================================
--- trunk/src/mouseTrap/mousetrap.in (original)
+++ trunk/src/mouseTrap/mousetrap.in Sun Sep 28 19:51:53 2008
@@ -74,7 +74,7 @@
cleanup()
{
USERID=`id | cut -f2 -d= | cut -f1 -d\(`
- PIDS=`ps -eo pid,ruid,args | egrep "mouseTrap[.]mouseTrap" | grep -v grep | awk '{print $1}'`
+ PIDS=`ps -eo pid,ruid,args | grep $USERID | egrep "mouseTrap[.]mouseTrap" | grep -v grep | awk '{print $1}'`
IFS='
'
@@ -186,7 +186,6 @@
mouseTrap &
mouseTrap_pid=$!
wait $mouseTrap_pid
- echo pasa
RUN=$? # quit on a normal exit status from mouseTrap
@@ -215,6 +214,10 @@
kill_watchdog
}
+
+trap kill_mouseTrap QUIT TERM INT ABRT
+trap hup_mouseTrap HUP
+
if [ "x$RUNONCE" = "xfalse" -a "x$ARGS" = "x" ]
then
main
@@ -231,14 +234,14 @@
# erroneously types an illegal command line argument, the
# help text is emitted and the other mouseTrap is not killed.
#
- if [ `egrep -c "\-d|\-e|\-t" <<< $ARGS` -eq 0 ]
+ if [ `egrep -c "\-h|\-d|\-e|\-t" <<< $ARGS` -eq 0 ]
then
- #if [ `egrep -c "\-h" <<< $ARGS` -eq 0 ]
- #then
- # mouseTrap "NO_CLEANUP"
- #else
+ if [ `egrep -c "\-h" <<< $ARGS` -eq 0 ]
+ then
mouseTrap "NO_CLEANUP"
- #fi
+ else
+ mouseTrap
+ fi
else
mouseTrap &
mouseTrap_pid=$!
Modified: trunk/src/mouseTrap/ocvfw.py
==============================================================================
--- trunk/src/mouseTrap/ocvfw.py (original)
+++ trunk/src/mouseTrap/ocvfw.py Sun Sep 28 19:51:53 2008
@@ -100,12 +100,14 @@
points = cv.cvHaarDetectObjects( self.smallImg, cascade, self.storage,
1.2, 2, method, cv.cvSize(20,20) )
else:
- debug.exception( "mouseTrap.ocvfw", _("The Haar Classifier Cascade load failed") )
+ debug.exception( "ocvfw", "The Haar Classifier Cascade load failed" )
if points:
matches = [ [ cv.cvPoint( int(r.x*self.imageScale), int(r.y*self.imageScale)), \
cv.cvPoint( int((r.x+r.width)*self.imageScale), int((r.y+r.height)*self.imageScale) )] \
for r in points]
+
+ debug.debug( "ocvfw", "cmGetHaarPoints: detected some matches" )
return matches
def cmGetHaarROIPoints( self, haarCascade, rect, origSize = (0,0), method = cv.CV_HAAR_DO_CANNY_PRUNING ):
@@ -130,12 +132,14 @@
points = cv.cvHaarDetectObjects( imageROI, cascade, self.storage,
1.2, 2, method, cv.cvSize(20,20) )
else:
- debug.exception( "mouseTrap.ocvfw", _( "The Haar Classifier Cascade load Failed (ROI)" ) )
+ debug.exception( "ocvfw", "The Haar Classifier Cascade load Failed (ROI)" )
if points:
matches = [ [ cv.cvPoint( int(r.x+origSize[0]), int(r.y+origSize[1])), \
cv.cvPoint( int(r.x+r.width+origSize[0]), int(r.y+r.height+origSize[1] ))] \
for r in points]
+
+ debug.debug( "ocvfw", "cmGetHaarROIPoints: detected some matches" )
return matches
def cmSetLKPoints( self, label, point):
@@ -162,6 +166,8 @@
if len(self.imgLKPoints["last"]) > 0:
self.imgLKPoints["last"].append( self.imgLKPoints["current"][0] )
+
+ debug.debug( "ocvfw", "cmSetLKPoints: New LK Point Added" )
else:
self.imgLKPoints["current"] = []
@@ -208,6 +214,9 @@
# increment the counter
counter += 1
+
+ #debug.debug( "ocvfw", "cmShowLKPoints: Showing %d LK Points" % counter )
+
# set back the self.imgPoints we keep
self.imgLKPoints["current"] = new_points
@@ -242,6 +251,7 @@
- params: A list with the capture properties. NOTE: Not implemented yet.
"""
self.capture = highgui.cvCreateCameraCapture( int(input) )
+ debug.debug( "ocvfw", "cmStartCamera: Camera Started" )
def cmQueryCapture( self, bgr = False, flip = False ):
"""
Modified: trunk/src/mouseTrap/prefGui.py
==============================================================================
--- trunk/src/mouseTrap/prefGui.py (original)
+++ trunk/src/mouseTrap/prefGui.py Sun Sep 28 19:51:53 2008
@@ -148,8 +148,8 @@
mainGuiBox = gtk.VBox( spacing = 6 )
mWindowActive = gtk.CheckButton( _("Show main window") )
- mWindowActive.set_active( self.settings.showMainGui )
- self.preffWidgets['showMainGui'] = mWindowActive
+ mWindowActive.set_active( self.settings.getboolean( "gui", "showMainGui" ) )
+ mWindowActive.connect( "toggled", self._checkToggled, "gui", "showMainGui" )
mainGuiBox.pack_start( mWindowActive, False, False )
@@ -173,30 +173,30 @@
camBox = gtk.VBox( spacing = 6 )
cAmActive = gtk.CheckButton( _("Activate Camera module") )
- cAmActive.set_active( self.settings.startCam )
- self.preffWidgets['startCam'] = cAmActive
+ cAmActive.set_active( self.settings.getboolean( "main", "startCam" ) )
+ cAmActive.connect( "toggled", self._checkToggled, "main", "startCam" )
camBox.pack_start( cAmActive, False, False )
flipImage = gtk.CheckButton( _("Flip Image") )
- flipImage.set_active( self.settings.flipImage )
- self.preffWidgets['flipImage'] = flipImage
+ flipImage.set_active( self.settings.getboolean( "cam", "flipImage" ) )
+ flipImage.connect( "toggled", self._checkToggled, "cam", "flipImage" )
camBox.pack_start( flipImage, False, False )
mapperActive = gtk.CheckButton( _("Show Point Mapper") )
- mapperActive.set_active( self.settings.showPointMapper )
- self.preffWidgets['showPointMapper'] = mapperActive
+ mapperActive.set_active( self.settings.getboolean( "gui", "showPointMapper" ) )
+ mapperActive.connect( "toggled", self._checkToggled, "gui", "showPointMapper" )
camBox.pack_start( mapperActive, False, False )
showCapture = gtk.CheckButton( _("Show Capture") )
- showCapture.set_active( self.settings.showCapture )
- self.preffWidgets['showCapture'] = showCapture
+ showCapture.set_active( self.settings.getboolean( "gui", "showCapture" ) )
+ showCapture.connect( "toggled", self._checkToggled, "gui", "showCapture" )
camBox.pack_start( showCapture, False, False )
- inputDevIndex = self.addSpin( _("Input Video Device Index: "), "inputDevIndex", self.settings.inputDevIndex, 0)
+ inputDevIndex = self.addSpin( _("Input Video Device Index: "), "inputDevIndex", self.settings.getint( "cam", "inputDevIndex" ), "cam", "inputDevIndex", 0)
camBox.pack_start( inputDevIndex, False, False )
camBox.show_all()
@@ -218,7 +218,7 @@
camBox = gtk.VBox( spacing = 6 )
- reqMov = self.addSpin( _("Step Speed: "), "stepSpeed", self.settings.stepSpeed)
+ reqMov = self.addSpin( _("Step Speed: "), "stepSpeed", self.settings.getint( "mouse", "stepSpeed" ), "mouse", "stepSpeed" )
camBox.pack_start( reqMov, False, False )
defClickF = gtk.Frame( _( "Default Click:" ) )
@@ -231,17 +231,17 @@
defClicksInv = dict((v,k) for k,v in defClicks.iteritems())
defClick = gtk.combo_box_new_text()
- defClick.append_text(defClicks[self.settings.defClick])
+ defClick.append_text(defClicks[self.settings.get( "mouse", "defClick" )])
- defClicklBl = gtk.Label(self.settings.defClick)
+ defClicklBl = gtk.Label(self.settings.get( "mouse", "defClick" ))
self.preffWidgets['defClick'] = defClicklBl
for mode in defClicks:
- if mode == self.settings.defClick:
+ if mode == self.settings.get( "mouse", "defClick" ):
continue
defClick.append_text( defClicks[mode] )
- defClick.connect('changed', self.comboChanged, 'defClick', defClicksInv)
+ defClick.connect('changed', self._comboChanged, "mouse", "defClick", defClicksInv)
defClick.set_active(0)
defClickF.add( defClick)
@@ -255,37 +255,21 @@
mouseModesInv = dict((v,k) for k,v in mouseModes.iteritems())
mouseMod = gtk.combo_box_new_text()
- mouseMod.append_text(mouseModes[self.settings.mouseMode])
+ mouseMod.append_text(mouseModes[self.settings.get( "cam", "mouseMode" )])
- mouseModlBl = gtk.Label(self.settings.mouseMode)
+ mouseModlBl = gtk.Label(self.settings.get( "cam", "mouseMode" ))
self.preffWidgets['mouseMode'] = mouseModlBl
for mode in mouseModes:
- if mode == self.settings.mouseMode:
+ if mode == self.settings.get( "cam", "mouseMode" ):
continue
mouseMod.append_text( mouseModes[mode] )
- mouseMod.connect('changed', self.comboChanged, 'mouseMode', mouseModesInv)
+ mouseMod.connect('changed', self._comboChanged, "cam", "mouseMode", mouseModesInv)
mouseMod.set_active(0)
mouseModF.add( mouseMod)
camBox.pack_start( mouseModF, False, False )
-
- #hbox = gtk.HBox( spacing = 6 )
-
- #startX = self.addSpin( _("Initial X: "), "stepSpeed", self.settings.stepSpeed)
- #hbox.pack_start( startX, False, False )
-
- #startY = self.addSpin( _("Initial Y: "), "stepSpeed", self.settings.stepSpeed)
- #hbox.pack_start( startY, False, False )
-
- #width = self.addSpin( _("Width: "), "stepSpeed", self.settings.stepSpeed)
- #hbox.pack_start( width, False, False )
-
- #height = self.addSpin( _("Height: "), "stepSpeed", self.settings.stepSpeed)
- #hbox.pack_start( height, False, False )
-
- #camBox.pack_start( hbox, False, False )
camBox.show_all()
@@ -314,11 +298,11 @@
levellabel.show()
levelHbox.pack_start( levellabel, False, False )
- adj = gtk.Adjustment( self.settings.debugLevel, 10, 50, 10, 1, 0)
+ adj = gtk.Adjustment( self.settings.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 )
- self.preffWidgets['debugLevel'] = levelSpin
+ levelSpin.connect( "value-changed", self._spinChanged, "main", "debugLevel" )
debugBox.pack_start( levelHbox, False, False )
@@ -340,14 +324,34 @@
- *args: The button event arguments
"""
- try:
- mTPref.userPref.update( scripts.loaded.pref )
- except:
- # The loaded profile doesn't have preferences.
- pass
-
- mTPref.writePref( self.preffWidgets )
+ self.settings.write( open( env.configPath + "userSettings.cfg", "w" ) )
self.destroy()
+
+
+ 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.settings.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.settings.set( section, option, str(widget.get_value_as_int()))
+
def applyButtonClick( self, *args):
"""
@@ -357,16 +361,9 @@
- self: The main object pointer.
- *args: The button event arguments
"""
+ self.settings.write( open( env.configPath + 'userSettings.cfg', "w" ) )
- try:
- mTPref.userPref.update( scripts.loaded.pref )
- except:
- # The loaded profile doesn't have preferences.
- pass
-
- mTPref.writePref( self.preffWidgets )
-
- def comboChanged( self, widget, var, modes ):
+ def _comboChanged( self, widget, section, option, modes ):
"""
On combo change. This function is the callback for the on_change
event.
@@ -377,15 +374,16 @@
Arguments:
- self: The main object pointer.
- widget: The widget pointer.
- - var: The variable corresponding to the widget.
+ - 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()
- self.preffWidgets[var].set_text( modes[model[index][0]] )
+ self.settings.set( section, option, modes[model[index][0]] )
- def addSpin( self, label, var, startValue, min = 1, max = 15):
+ def addSpin( self, label, var, startValue, section, option, min = 1, max = 15):
"""
Creates a new spin button inside a HBox and return it.
@@ -406,8 +404,8 @@
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 )
- self.preffWidgets[var] = spinButton
spinLbl.set_mnemonic_widget( spinButton )
Modified: trunk/src/mouseTrap/scripts.py
==============================================================================
--- trunk/src/mouseTrap/scripts.py (original)
+++ trunk/src/mouseTrap/scripts.py Sun Sep 28 19:51:53 2008
@@ -28,9 +28,7 @@
__license__ = "GPLv2"
import os
-import gtk
import debug
-import events
import environment as env
from mouseTrap import settings
@@ -58,8 +56,9 @@
prof = __import__( mod, globals(), locals(), [''] )
modes[prof.setName] = prof.Profile
env.mouseModes.update( prof.modes )
+ debug.debug( "scripts", "Mousetrap %s Profile has been loaded" % mod )
except:
- debug.exception( "mouseTrap.scripts", _( "The Profile load failed" ) )
+ debug.exception( "scripts", "The Profile load failed" )
def loadProfile( gui ):
"""
@@ -73,4 +72,6 @@
if not modes:
_loadThirdProfiles()
- loaded = modes[settings.mouseMode.split("|")[0]]( gui )
+ loaded = modes[settings.get( "cam", "mouseMode" ).split("|")[0]]( gui )
+ debug.debug( "scripts", "Profile Started" )
+
Modified: trunk/src/mouseTrap/scripts/profiles/dragProfile.py
==============================================================================
--- trunk/src/mouseTrap/scripts/profiles/dragProfile.py (original)
+++ trunk/src/mouseTrap/scripts/profiles/dragProfile.py Sun Sep 28 19:51:53 2008
@@ -27,11 +27,15 @@
__copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
__license__ = "GPLv2"
+import gtk
+import time
import mouseTrap.events as events
import mouseTrap.environment as env
import mouseTrap.mouseTrap as mouseTrap
+from mouseTrap.mainGui import MapperArea
from mouseTrap.mTi18n import _
+from opencv import cv
# The name given for the config file
setName = "drag"
@@ -57,10 +61,16 @@
self.mTp = mouseTrap
self.settings = mouseTrap.settings
- self.step = self.settings.stepSpeed
- self.active = False
+ self.active = True
self._loadSettings()
+
+ self.horArea = MapperArea()
+ self.horArea.area( 0, 60, 100, 80, False )
+
+ self.verArea = MapperArea()
+ self.verArea.area( 100, 0, 120, 160, False )
+
self._registerMapperEvents()
def _registerMapperEvents( self ):
@@ -71,44 +81,18 @@
- self: The main object pointer.
"""
- events.registerMapperEvent( "dragHor", [ 0, 60 ], [ 100, 80 ],
- True, ["moveMode:drag", "clickDlgVisible:False"],
- self._moveDragDropMode, 0, "hor")
-
- events.registerMapperEvent( "dragVer", [100, 0], [ 120, 160],
- True, ["moveMode:drag", "clickDlgVisible:False"],
- self._moveDragDropMode, 0, "ver")
-
- events.registerMapperEvent( "activeDrag", [98, 80], [ 100, 82],
- True, ["moveMode:drag", "clickDlgVisible:False"],
- self._startStopMove, 2)
-
- events.registerMapperEvent( "clickPanel", [28, 98], [32, 102],
- True, ["moveMode:drag", "clickDlgVisible:False"],
- self.gui.clickDlgHandler, 0.5)
-
- #########################
- # CLICK DIALOG EVENTS #
- #########################
+ self.horArea.connect( "point-move", self._moveDragDropMode, env.ACTIVE, "hor", out = False )
+ self.verArea.connect( "point-move", self._moveDragDropMode, env.ACTIVE, "ver", out = False )
+ self.gui.mapper.registerTrigger( 100, 80, 4, self._startStopMove )
+ #self.gui.mapper.drawPoint( 30, 100, 3, "orange")
+ self.gui.mapper.registerArea( self.horArea )
+ self.gui.mapper.registerArea( self.verArea )
+
+ #self.area.connect( "point-move", self._clickDialog, env.CLKDLG, out = True )
- events.registerMapperEvent( "clickDlgPrev", [0, 0],
- [ 30 - self.settings.reqMovement, 160],
- True, ["moveMode:drag", "clickDlgVisible:True"],
- self.gui.clickDialog.prevBtn, 2)
-
- events.registerMapperEvent( "clickDlgNext", [30 + self.settings.reqMovement, 0],
- [ 200, 160], True, ["moveMode:drag", "clickDlgVisible:True"],
- self.gui.clickDialog.nextBtn, 2)
-
- events.registerMapperEvent( "clickDlgAccept", [0, 0],
- [ 200, 100 - self.settings.reqMovement],
- True, ["moveMode:drag", "clickDlgVisible:True"],
- self.gui.clickDialog.pressButton, 2)
-
- events.registerMapperEvent( "clickDlgCancel",
- [0, 100 + self.settings.reqMovement],[ 200, 160],
- True, ["moveMode:drag", "clickDlgVisible:True"],
- self.gui.clickDialog.hidePanel, 2)
+ ## events.registerMapperEvent( "activeDrag", [98, 80], [ 100, 82],
+## True, ["moveMode:drag", "clickDlgVisible:False"],
+## self._startStopMove, 2)
def _loadSettings( self ):
"""
@@ -117,13 +101,16 @@
Arguments:
- self: The main object pointer.
"""
-
try:
- getattr( self.settings, "reqMovement")
+ self.reqMovement = self.settings.getint( "access", "reqMovement" )
except:
- self.settings.reqMovement = 10
-
- def _startStopMove( self, *args ):
+ self.settings.add_section( "access" )
+ self.settings.set( "access", "reqMovement", "10" )
+ self.reqMovement = self.settings.getint( "access", "reqMovement" )
+
+ self.step = self.settings.getint( "mouse", "stepSpeed" )
+
+ def _startStopMove( self, *args, **kwds ):
"""
Allow Users to Enable or Disable the mode.
@@ -133,7 +120,7 @@
"""
self.active = not self.active
- def _moveDragDropMode( self, sense ):
+ def _moveDragDropMode( self, sense, *args, **kwds ):
"""
Perform the mouse pointer movements based on the 'Drag Drop Mode'
@@ -141,11 +128,14 @@
- self: The main object pointer.
- sense: The direction of the movement.
"""
-
+
if not self.active:
return
foreheadDiff = mouseTrap.getModVar( "cam", "foreheadDiff" )
+
+ if not foreheadDiff:
+ return
newX, newY = mouseTrap.mice( "position" )
@@ -156,40 +146,6 @@
mouseTrap.mice( "move", newX, newY )
- def drawMapper( self, context ):
- """
- Calls the drawing function needed
-
- Arguments:
- - self: The main object pointer.
- - context: The Drawing area context to paint.
- """
-
- if self.gui.clickDialog.props.visible:
- self._clickDlgMapper( context )
- else:
- self._drawDragMapper( context )
-
- def _clickDlgMapper( self, context ):
- """
- Draws the mapper acording to the Click Dialog
-
- Arguments:
- - self: The main object pointer.
- - context: The Drawing area context to paint.
- """
-
- reqLim = self.settings.reqMovement
-
- context.set_font_size (20)
- context.set_source_rgb( 255, 255, 255)
-
- self.gui.mapper.drawLine(context, 30 - reqLim, 100 - reqLim, 30 + reqLim, 100 - reqLim, (255, 255, 255))
- self.gui.mapper.drawLine(context, 30 - reqLim, 100 + reqLim, 30 + reqLim, 100 + reqLim, (255, 255, 255))
-
- self.gui.mapper.drawLine(context, 30 - reqLim, 100 - reqLim, 30 - reqLim, 100 + reqLim, (255, 255, 255))
- self.gui.mapper.drawLine(context, 30 + reqLim, 100 - reqLim, 30 + reqLim, 100 + reqLim, (255, 255, 255))
-
def prefTab( self, prefGui ):
"""
This is the preferences tab function for the Drag Mode Profile.
Modified: trunk/src/mouseTrap/scripts/profiles/holdProfile.py
==============================================================================
--- trunk/src/mouseTrap/scripts/profiles/holdProfile.py (original)
+++ trunk/src/mouseTrap/scripts/profiles/holdProfile.py Sun Sep 28 19:51:53 2008
@@ -33,6 +33,7 @@
import mouseTrap.environment as env
import mouseTrap.mouseTrap as mouseTrap
+from mouseTrap.mainGui import MapperArea
from mouseTrap.mTi18n import _
from opencv import cv
@@ -64,7 +65,7 @@
self.gui = gui
self.mTp = mouseTrap
self.settings = mouseTrap.settings
- self.step = self.settings.stepSpeed
+ self.step = self.settings.get( "mouse", "stepSpeed" )
self.reqMovement = None
self.stopMove = None
@@ -76,10 +77,15 @@
self.pref = { 'reqMovement' : 'spinButton' }
- self.clickCorner = cv.cvPoint( 100 - self.settings.reqMovement, 80 - self.settings.reqMovement)
- self.scUpCorner = cv.cvPoint( 100 + self.settings.reqMovement, 80 - self.settings.reqMovement)
- self.scDownCorner = cv.cvPoint( 100 + self.settings.reqMovement, 80 + self.settings.reqMovement)
- self.defClickCorner = cv.cvPoint( 100 - self.settings.reqMovement, 80 + self.settings.reqMovement)
+ self.clickCorner = cv.cvPoint( 100 - self.reqMovement, 80 - self.reqMovement)
+ self.scUpCorner = cv.cvPoint( 100 + self.reqMovement, 80 - self.reqMovement)
+ self.scDownCorner = cv.cvPoint( 100 + self.reqMovement, 80 + self.reqMovement)
+ self.defClickCorner = cv.cvPoint( 100 - self.reqMovement, 80 + self.reqMovement)
+
+
+ self.area = MapperArea()
+ self.area.area( 100 - self.reqMovement, 80 - self.reqMovement, 100 + self.reqMovement, 80 + self.reqMovement, True )
+
self._registerMapperEvents()
def _loadSettings( self ):
@@ -91,9 +97,11 @@
"""
try:
- getattr( self.settings, "reqMovement")
+ self.reqMovement = self.settings.getint( "access", "reqMovement" )
except:
- self.settings.reqMovement = 10
+ self.settings.add_section( "access" )
+ self.settings.set( "access", "reqMovement", "10" )
+ self.reqMovement = self.settings.getint( "access", "reqMovement" )
def _registerMapperEvents( self ):
@@ -104,62 +112,21 @@
- self: The main object pointer.
"""
- events.registerMapperEvent( "holdMove",
- [ 100 - self.settings.reqMovement, 80 - self.settings.reqMovement ],
- [ 100 + self.settings.reqMovement, 80 + self.settings.reqMovement ],
- False, ["moveMode:hold", "clickDlgVisible:False"], self._moveHoldMode, 0)
-
- events.registerMapperEvent( "clickPanel",
- [self.clickCorner.x, self.clickCorner.y],
- [self.clickCorner.x + 2, self.clickCorner.y + 2],
- True, ["moveMode:hold", "clickDlgVisible:False"],
- self.gui.clickDlgHandler , 0.5)
-
- events.registerMapperEvent( "scrollUp",
- [self.scUpCorner.x - 2, self.scUpCorner.y],
- [self.scUpCorner.x, self.scUpCorner.y + 2],
- True, ["moveMode:hold", "clickDlgVisible:False"],
- mouseTrap.mice, 0.5, "click", button = "b4c" )
-
- events.registerMapperEvent( "scrollDown",
- [self.scDownCorner.x - 2, self.scDownCorner.y - 2],
- [self.scDownCorner.x, self.scDownCorner.y],
- True, ["moveMode:hold", "clickDlgVisible:False"],
- mouseTrap.mice, 0.5, "click", button = "b5c" )
-
- events.registerMapperEvent( "defClick",
- [self.defClickCorner.x, self.scDownCorner.y - 2],
- [self.defClickCorner.x + 2, self.scDownCorner.y],
- True, ["moveMode:hold", "clickDlgVisible:False"],
- mouseTrap.mice, 0.5, "click", button = self.settings.defClick )
-
- #########################
- # CLICK DIALOG EVENTS #
- #########################
-
- events.registerMapperEvent( "clickDlgPrev", [0, 0],
- [ 100 - self.settings.reqMovement, 160],
- True, ["moveMode:hold", "clickDlgVisible:True"],
- self.gui.clickDialog.prevBtn, 2)
-
- events.registerMapperEvent( "clickDlgNext",
- [100 + self.settings.reqMovement, 0], [ 200, 160],
- True, ["moveMode:hold", "clickDlgVisible:True"],
- self.gui.clickDialog.nextBtn, 2)
-
- events.registerMapperEvent( "clickDlgAccept",
- [98, 80 - self.settings.reqMovement - 2 ],
- [ 102, 80 - self.settings.reqMovement + 2],
- True, ["moveMode:hold", "clickDlgVisible:True"],
- self.gui.clickDialog.pressButton, 2)
-
- events.registerMapperEvent( "clickDlgCancel",
- [98, 80 + self.settings.reqMovement - 2],
- [ 102, 80 + self.settings.reqMovement - 2 ],
- True, ["moveMode:hold", "clickDlgVisible:True"],
- self.gui.clickDialog.hidePanel, 2)
-
- def _moveHoldMode( self, *args ):
+
+ self.area.connect( "point-move", self._moveHoldMode, env.ACTIVE, out = True )
+ self.area.connect( "top-left-corner", self.gui.clickDlgHandler, env.ACTIVE )
+ self.area.connect( "top-right-corner", mouseTrap.mice, env.ACTIVE, "click", button = "b4c" )
+ self.area.connect( "bottom-left-corner", mouseTrap.mice, env.ACTIVE, "click", button = "b5c" )
+ self.area.connect( "bottom-right-corner", mouseTrap.mice, env.ACTIVE, "click", button = self.settings.get( "mouse", "defClick" ) )
+
+ self.gui.mapper.axis = True
+ self.gui.mapper.registerArea( self.area )
+
+ ## Click's dialog event.
+
+ self.area.connect( "point-move", self._clickDialog, env.CLKDLG, out = True )
+
+ def _moveHoldMode( self, *args, **kwds ):
"""
Perform the movements using the 'HOLD' mode.
@@ -185,7 +152,7 @@
var = dict( [ ( i, self.step*(v/abs(v)))
for i,v in enumerate( [ forehead.x - foreheadOrig.x,
forehead.y - foreheadOrig.y] )
- if abs(v) >= self.settings.reqMovement ] )
+ if abs(v) >= self.settings.getint( "hold_profile", "reqMovement" ) ] )
for i in var:
if i > 0: newPoss[i] += var[i]; continue
@@ -194,7 +161,7 @@
newX, newY = newPoss
- if self.settings.mouseMode.endswith("|acc") and self.startMove > self.stopMove:
+ if self.settings.get( "cam", "mouseMode").endswith("|acc") and self.startMove > self.stopMove:
self.step += ( abs( time.time() - self.startMove) * 3 )
if newPoss != poss:
@@ -205,8 +172,28 @@
else:
self.isMoving = False
self.stopMove = time.time()
- self.step = self.settings.stepSpeed
+ self.step = self.settings.getint( "mouse", "stepSpeed" )
+
+ def _clickDialog( self, *args, **kwds ):
+ """
+ Click's dialog's point-move event callback
+
+ Arguments:
+ - self: The main object pointer.
+ """
+ dialog = mouseTrap.getModVar( "gui", "clickDialog" )
+ mPointer = mouseTrap.getModVar( "cam", "mpPointer" )
+
+ if mPointer.x in xrange( 0, self.area.xInit ):
+ dialog.prevBtn()
+ elif mPointer.x in xrange( self.area.xEnd, 200):
+ dialogs.nextBtn()
+ elif mPointer.y in xrange( 0, self.area.yInit ):
+ dialog.pressButton()
+ elif mPointer.y in xrange( self.area.yEnd, 160):
+ dialog.hidePanel()
+
def prefTab( self, prefGui ):
"""
This is the preferences tab function for Hold Mode Profile.
@@ -219,8 +206,8 @@
holdBox = gtk.VBox( spacing = 6 )
- reqMov = prefGui.addSpin( _("Required Movement: "), "reqMovement", self.settings.reqMovement)
- reqMov.get_children()[1].connect("value_changed", self.spinChanged )
+ reqMov = prefGui.addSpin( _("Required Movement: "), "reqMovement", self.settings.getint( "hold_profile", "reqMovement" ) )
+ reqMov.get_children()[1].connect("value_changed", self._spinChanged )
holdBox.pack_start( reqMov, False, False )
holdBox.show_all()
@@ -231,7 +218,7 @@
prefGui.NoteBook.insert_page(Frame, gtk.Label( _("Hold Mode") ) )
- def spinChanged( self, widget ):
+ def _spinChanged( self, widget ):
"""
This is the callback function for the spin change event.
@@ -240,94 +227,4 @@
- prefgui: the preferences gui pointer.
"""
- self.settings.reqMovement = widget.get_value_as_int()
-
- def drawMapper( self, context ):
- """
- Calls the drawing function needed
-
- Arguments:
- - self: The main object pointer.
- - context: The Drawing area context to paint.
- """
-
- if self.gui.clickDialog.props.visible:
- self._clickDlgMapper( context )
- else:
- self._drawCartesianPlane( context )
-
- def _clickDlgMapper( self, context ):
- """
- Draws the mapper acording to the Click Dialog
-
- Arguments:
- - self: The main object pointer.
- - context: The Drawing area context to paint.
- """
-
- reqLim = self.settings.reqMovement
-
- context.set_font_size (20)
- context.set_source_rgb( 255, 255, 255)
-
- self.gui.mapper.drawLine(context, 100 - reqLim, 80 - reqLim, 100 + reqLim, 80 - reqLim, (255, 255, 255))
- self.gui.mapper.drawLine(context, 100 - reqLim, 80 + reqLim, 100 + reqLim, 80 + reqLim, (255, 255, 255))
-
- self.gui.mapper.drawLine(context, 100 - reqLim, 80 - reqLim, 100 - reqLim, 80 + reqLim, (255, 255, 255))
- self.gui.mapper.drawLine(context, 100 + reqLim, 80 - reqLim, 100 + reqLim, 80 + reqLim, (255, 255, 255))
-
- msgs = { _( "Cancel" ) : { "x" : 80, "y" : 100 + reqLim },
- _( "Accept" ) : { "x" : 80, "y" : 70 - reqLim },
- "-->" : { "x" : 100 + reqLim, "y" : 85},
- "<--" : { "x" : 70 - reqLim, "y" : 85 }
- }
-
- for msg,arr in msgs.iteritems():
- context.move_to ( arr["x"] , arr["y"] )
- context.show_text ( msg )
-
- # Accept Point
- self.gui.mapper.drawPoint( context, 100, 80 - reqLim, 3, "orange")
-
- # Cancel Point
- self.gui.mapper.drawPoint( context, 100, 80 + reqLim, 3, "orange")
-
- def _drawCartesianPlane( self, context ):
- """
- Draws the Cartesian Plane
-
- Arguments:
- - self: The main object pointer.
- - context: The Cairo Context.
- """
-
- reqLim = self.settings.reqMovement
-
-
- #Safe area
-
- # Y Line
- self.gui.mapper.drawLine(context, 100, 0, 100, 160, (255, 255, 255))
-
- # X Line
- self.gui.mapper.drawLine(context, 0, 80, 200, 80, (255, 255, 255))
-
- self.gui.mapper.drawLine(context, 100 - reqLim, 80 - reqLim, 100 + reqLim, 80 - reqLim, (255, 255, 255))
- self.gui.mapper.drawLine(context, 100 - reqLim, 80 + reqLim, 100 + reqLim, 80 + reqLim, (255, 255, 255))
-
- self.gui.mapper.drawLine(context, 100 - reqLim, 80 - reqLim, 100 - reqLim, 80 + reqLim, (255, 255, 255))
- self.gui.mapper.drawLine(context, 100 + reqLim, 80 - reqLim, 100 + reqLim, 80 + reqLim, (255, 255, 255))
-
- # Up/Left ( Click Panel )
- self.gui.mapper.drawPoint( context, 100 - reqLim, 80 - reqLim, 3, "orange")
-
- #Down/Right ( Scroll Button )
- self.gui.mapper.drawPoint( context, 100 + reqLim, 80 + reqLim, 3, self.gui.mapper.triggers['scD'])
-
- #Up/Right ( Scroll Button )
- self.gui.mapper.drawPoint( context, 100 + reqLim, 80 - reqLim, 3, self.gui.mapper.triggers['scU'])
-
- # Down/Left ( Default Click Launcher )
- self.gui.mapper.drawPoint( context, 100 - reqLim, 80 + reqLim, 3, "orange")
-
- return True
+ self.settings.set( "hold_profile", "reqMovement", widget.get_value_as_int() )
Modified: trunk/src/mouseTrap/scripts/profiles/screenProfile.py
==============================================================================
--- trunk/src/mouseTrap/scripts/profiles/screenProfile.py (original)
+++ trunk/src/mouseTrap/scripts/profiles/screenProfile.py Sun Sep 28 19:51:53 2008
@@ -33,6 +33,7 @@
import mouseTrap.environment as env
import mouseTrap.mouseTrap as mouseTrap
+from mouseTrap.mainGui import MapperArea
from mouseTrap.mTi18n import _
# The name given for the config file
@@ -67,6 +68,10 @@
self.mpClick = [ 0, 0, 0, 0, 0, 0 ]
self._loadSettings()
+
+ self.area = MapperArea()
+
+ self.area.area( self.vScreen["startX"], self.vScreen["startY"], self.vScreen["endX"], self.vScreen["endY"] )
self._registerMapperEvents()
@@ -79,9 +84,11 @@
"""
try:
- self.vScreen = eval(self.settings.vScreen)
+ self.vScreen = eval(self.settings.get( "screen_profile", "vScreen" ) )
except:
- self.vScreen = {'startX': 60, 'startY': 50, 'endY': 110, 'endX': 140, 'height': 60.0, 'width': 80.0}
+ self.settings.add_section( "screen_profile" )
+ self.settings.set( "screen_profile", "vScreen", "{'startX': 60, 'startY': 50, 'endY': 110, 'endX': 140, 'height': 60.0, 'width': 80.0}" )
+ self.vScreen = eval(self.settings.get( "screen_profile", "vScreen" ))
def _checkPref( self ):
"""
@@ -93,7 +100,7 @@
try:
- if self.vScreen != eval(self.settings.vScreen):
+ if self.vScreen != eval(self.settings.get( "screen_profile", "vScreen") ):
self._loadSettings()
events.registerMapperEvent( "screeMode", [ self.vScreen["startX"], self.vScreen["startY"] ],
[ self.vScreen["endX"], self.vScreen["endY"] ], True, ["moveMode:screen"], self._moveScreenMode, 0)
@@ -108,71 +115,11 @@
- self: The main object pointer.
"""
-
- self.gui.mapper.connect("button_press_event", self.mouseClick, self.gui.mapper )
- self.gui.mapper.connect("button_release_event", self.mouseClick, self.gui.mapper )
- self.gui.mapper.connect("motion_notify_event", self.mouseMotion, self.gui.mapper )
-
- events.registerMapperEvent( "screeMode", [ self.vScreen["startX"], self.vScreen["startY"] ],
- [ self.vScreen["endX"], self.vScreen["endY"] ], True, ["moveMode:screen"], self._moveScreenMode, 0)
-
- events.registerMapperEvent( "timeupdate", [ self.vScreen["startX"], self.vScreen["startY"] ],
- [ self.vScreen["endX"], self.vScreen["endY"] ], False, ["moveMode:screen"], self._timeUpdate, 0)
-
- def mouseClick( self, widget, event, mapper ):
- """
- This is the callback function for the mouse clicks in the
- mapper.
-
- Arguments:
- - self: The main object pointer.
- - widget: The Drawing area.
- - event: The event information.
- """
-
- if event.button == 1 and event.type.value_name == "GDK_BUTTON_PRESS":
- self.mpClick[0], self.mpClick[1] = [ int(event.x), int(event.y)]
- elif event.button == 1 and event.type.value_name == "GDK_BUTTON_RELEASE":
- self.settings.vScreen = "%s" % {'startX': self.mpClick[0],
- 'startY': self.mpClick[1],
- 'endX': self.mpClick[2],
- 'endY': self.mpClick[3],
- 'width': self.mpClick[4],
- 'height': self.mpClick[5] }
- self.mpClick = [ 0, 0, 0, 0, 0, 0 ]
-
- def mouseMotion( self, widget, event, mapper ):
- """
- This is the calback function for the button1 motion events
- in the mapper
+ self.area.connect( "point-move", self._moveScreenMode, out = False )
+ self.area.connect( "point-move", self._timeUpdate, out = True )
+ self.gui.mapper.registerArea( self.area )
- Arguments:
- - self: The main object pointer.
- - widget: The Drawing area.
- - event: The event information.
- """
- self.mpClick[2] = int( event.x )
- self.mpClick[3] = int( event.y )
- self.mpClick[4] = abs( int(event.x) - self.mpClick[0])
- self.mpClick[5] = abs( int(event.y) - self.mpClick[1] )
- self.gui.mapper.updateView()
-
- def drawMotionRectangle( self, context ):
- """
- This function draws a rectangle during the mouse motion event on the
- mapper when the button 1 is pressed.
-
- Arguments:
- - self: The main object pointer
- - context: Cairo context to draw the rectangle.
- """
-
- if self.mpClick[0] < self.mpClick[2]:
- self.gui.mapper.drawRectangle( context, self.mpClick[0], self.mpClick[1], self.mpClick[4], self.mpClick[5], (10, 0.8, 0.1))
- else:
- self.gui.mapper.drawRectangle( context, self.mpClick[2], self.mpClick[3], self.mpClick[4], self.mpClick[5], (10, 0.8, 0.1))
-
- def _timeUpdate( self, *args ):
+ def _timeUpdate( self, *args, **kwds ):
"""
This function updates the self.last time so the mouse
pointer wont be sticked to the desktop when the mapper
@@ -183,7 +130,7 @@
"""
self.last = time.time()
- def _moveScreenMode( self, *args ):
+ def _moveScreenMode( self, *args, **kwds ):
"""
Perform the movements of the pointer using the 'REAL MOUSE' mode.
@@ -268,8 +215,9 @@
tmp = [ spin.get_value_as_int() for spin in self.spins ]
- self.settings.vScreen = "%s" % {'startX': tmp[0], 'startY': tmp[1], 'endY': tmp[1] + tmp[3],
- 'endX': tmp[0] + tmp[2], 'height': tmp[3], 'width': tmp[2]}
+ self.settings.set( "screen_profile", "vScreen",
+ "%s" % {'startX': tmp[0], 'startY': tmp[1], 'endY': tmp[1] + tmp[3],
+ 'endX': tmp[0] + tmp[2], 'height': tmp[3], 'width': tmp[2]} )
prefGui.preffWidgets["vScreen"].set_text( self.settings.vScreen )
@@ -303,24 +251,3 @@
spinLbl.set_mnemonic_widget( spinButton )
return spinHbox
-
- def drawMapper( self, context ):
- """
- Calls the drawing function needed
-
- Arguments:
- - self: The main object pointer.
- - context: The Drawing area context to paint.
- """
-
- self._checkPref()
-
- if not 0 in self.mpClick:
- self.drawMotionRectangle( context )
-
- if self.vScreen["startX"] < self.vScreen["endX"]:
- self.gui.mapper.drawRectangle(context, self.vScreen["startX"], self.vScreen["startY"],
- self.vScreen["width"], self.vScreen["height"], (255, 255, 255))
- else:
- self.gui.mapper.drawRectangle(context, self.vScreen["endX"], self.vScreen["endY"],
- self.vScreen["width"], self.vScreen["height"], (255, 255, 255))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]