SmartBody : Controlling the User Interface in sbgui via Python

Mouse and Keyboard Interactions

The GUI for sbgui can be controlled by issuing Python commands that respond to mouse clicks and movements, as well as for keyboard touches.

To respond to a mouse of keyboard touch, you can override the behavior by creating a Python class as follows:

 

import GUIInterface
 
class MyInterface (GUIInterface.SBInterfaceListener):
	def onStart(self):
		# triggered when the interface is first loaded from the interface manager
	def onMouseClick(self, x, y, button):
		# triggered when a mouse button is clicked
		# x and y are screen pixel coordinates of the mouse location
		# button is the number of the mouse button (1 = left, 2 = middle, 3 = right)
		# return False if you want sbgui to handle this mouse click as it ordinarily does
		# return False if you want sbgui to stop any further handling of the mouse click
		return False
 
	def onMouseMove(self, x, y):
		# triggered when a mouse button is clicked
		# x and y are screen pixel coordinates
		# return False if you want sbgui to handle this mouse movement as it ordinarily does
		# return False if you want sbgui to stop any further handling of the mouse movement
		return False
 
	def onMouseRelease(self, x, y, button):
		# triggered when a mouse button is released
		# x and y are screen pixel coordinates of the mouse location
		# button is the number of the mouse button (1 = left, 2 = middle, 3 = right)
		# return False if you want sbgui to handle this mouse release as it ordinarily does
		# return False if you want sbgui to stop any further handling of the mouse release 
		return False
 
	def onMouseDrag(self, x, y):
		# triggered when a mouse is moved while a button is pressed
		# x and y are screen pixel coordinates
		# return False if you want sbgui to handle this mouse drag it ordinarily does
		# return False if you want sbgui to stop any further handling of the mouse drag
		return False	

	def onKeyboardPress(self, c):
		# triggered when a key is pressed
		# c is the character pressed
		# return False if you want sbgui to handle this keyboard press it ordinarily does
		# return False if you want sbgui to stop any further handling of the keyboard press
		return False	

	def onKeyboardRelease(self, c):
		# triggered when a key is release
		# c is the character released
		# return False if you want sbgui to handle this keyboard release it ordinarily does
		# return False if you want sbgui to stop any further handling of the keyboard release
		return False	
 
	def onEnd(self):
		# triggered when the interface is unloaded from the interface manager
# create an instance of the interface 
myinterface = MyInterface()
# get the interface manager
m = GUIInterface.getInterfaceManager()
# add the interface to the interface manager
m.addInterfaceListener(t)
# if you want to remove that interface:
#m.removeInterfaceListener(t)

 

As an example, here is a simple class that prints out the location of mouse clicks and which button is pressed:

 

import GUIInterface
class TestInterface(GUIInterface.SBInterfaceListener):
   def onMouseClick(self, x,y,button):
      print str(x) + " " + str(y) + " " + str(button)
      return False
t = TestInterface()
m = GUIInterface.getInterfaceManager()
m.addInterfaceListener(t)