scripts/GizmodDispatcher.py

00001     #***
00002   #*********************************************************************
00003 #*************************************************************************
00004 #*** 
00005 #*** GizmoDaemon Config Script
00006 #***    GizmodDispatcher.py
00007 #***
00008 #*****************************************
00009   #*****************************************
00010     #***
00011 
00012 """
00013 
00014   Copyright (c) 2007, Gizmo Daemon Team
00015   Licensed under the Apache License, Version 2.0 (the "License");
00016   you may not use this file except in compliance with the License.
00017   You may obtain a copy of the License at 
00018 
00019         http://www.apache.org/licenses/LICENSE-2.0
00020 
00021   Unless required by applicable law or agreed to in writing, software
00022   distributed under the License is distributed on an "AS IS" BASIS,
00023   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00024   See the License for the specific language governing permissions and 
00025   limitations under the License. 
00026   
00027 """
00028 
00029 ############################
00030 # Imports
00031 ##########################
00032 
00033 from GizmoDaemon import *
00034 from GizmoDeviceClass import *
00035 from GizmoRegistrar import *
00036 
00037 ############################
00038 # GizmodDispatcher Class definition
00039 ##########################
00040 
00041 class GizmodDispatcher(GizmodEventHandler):
00042         """
00043         Main class that handles all of the incoming events
00044         
00045         The idea behind this class is to use it as nothing more than a dispatching
00046         mechanism.  All the events get channeled from GizmoDaemon through here
00047         and this class is intended merely to pass events off the appropriate
00048         module.
00049         """
00050         
00051         ############################
00052         # Public Functions
00053         ##########################
00054 
00055         def getInitialized(self):
00056                 """ Gets whether or not the object has been initialized """
00057 
00058                 return self.initialized
00059 
00060         def initialize(self):
00061                 """
00062                 This python function gets called by GizmoDeamon and is intended to allow for
00063                 user specific initialization code to be executed during program startup.
00064                 """
00065 
00066                 #print "GizmoDaemon Config Script v" + Gizmod.getVersion()  + " -- Initializing"
00067                 self.initialized = True
00068                 
00069         def onDeregisterDevice(self, Device):
00070                 """
00071                 This method is triggered when a device has been deregistered (either at shutdown
00072                 or when Gizmo Daemon detects a device has been disconnected from the computer)
00073                 
00074                 For information regarding the Device properties and methods see the API documention for
00075                 Gizmo* (GizmoStandard, GizmoPowermate, etc)
00076                 """
00077                 
00078                 # GizmoRegistrar is defined in GizmoRegistrar.py for convenience and modularity sake
00079                 GizmoRegistrar(Device).handleDeviceRemoval()
00080 
00081         def onEvent(self, Event, Gizmo = None):
00082                 """
00083                 This method gets called whenever Gizmo Daemon detects an event from a device
00084                  
00085                 The Event object passed in will be of the type associated with that event,
00086                 so for example if it's a Powermate event the Event class will be "GizmoPowermate"
00087                 
00088                 Similarly the Gizmo object will of the class of the device that generated
00089                 the event. Ie, if it's a Powermate event the class will also be "Powermate".  If
00090                 there is no associated Gizmo (ie with WindowFocus events), this field will be
00091                 set to None.
00092                 
00093                 All Event classes share the same base "GizmoEvent" class, and you can use the 
00094                 GizmoEvent class method "getClass" to figure out what type of event it 
00095                 is.  See the C++ API documention (http://gizmod.sourceforge.net/documentation/apidocs)
00096                 on the specific GizmoEvent* type for more details
00097 
00098                 All Gizmo classes share the same base "Gizmo" class, and you can use the Gizmo
00099                 class method "getType" to figure out what type of event it is.  See the C++ API 
00100                 documention on the specific Gizmo* type for more details
00101                 """
00102                 
00103                 # Pass on the event to the user scripts in order of their priority
00104                 #
00105                 # If a user script returns True (signalling that it has handled
00106                 # an event, then it is not passed on to further scripts and the event
00107                 # chain is stopped)
00108                 for UserScript in self.userScripts:
00109                         if UserScript.onEvent(Event, Gizmo):
00110                                 break
00111                                 
00112         def onQueryDeviceClass(self, DeviceInformation):
00113                 """
00114                 This method is triggered when a new device is being registered (either at startup
00115                 or when Gizmo Daemon detects a new device has been plugged in to the computer)
00116                 
00117                 For information regarding the DeviceInformation fields see the API documention for
00118                 H::DeviceInfo
00119                 
00120                 This method should return the GizmoClass of the device
00121                 """
00122                 
00123                 # GizmoDeviceType is defined in GizmoDeviceType.py for convenience and modularity sake
00124                 return GizmoDeviceClass(DeviceInformation).DeviceClass
00125 
00126         def onRegisterDevice(self, Device):
00127                 """
00128                 This method is triggered when a new device (of the type returned in onQueryDeviceType) 
00129                 has been registered (either at startup or when Gizmo Daemon detects a new device has 
00130                 been plugged in to the computer)
00131                 
00132                 For information regarding the Device properties and methods see the API documention for
00133                 Gizmo* (GizmoStandard, GizmoPowermate, etc)
00134                 """
00135                 
00136                 # GizmoRegistrar is defined in GizmoRegistrar.py for convenience and modularity sake
00137                 GizmoRegistrar(Device).handleDeviceAddition()
00138 
00139         ############################
00140         # Private Functions
00141         ##########################
00142         
00143         def __init__(self):
00144                 """ 
00145                 Default Constructor
00146                 """
00147 
00148                 # version check
00149                 if not Gizmod.checkVersion(VERSION_REQUIRED, True):
00150                         print "Script Version mismatch -- Gizmo Daemon v" + str(VERSION_REQUIRED) + " Required."
00151                         Gizmod.signalShutdown()
00152 
00153                 # Must explicitely call the base's constructor
00154                 GizmodEventHandler.__init__(self)
00155                 
00156                 # Module specific initialization
00157                 self.initialized = False
00158                 self.userScripts = list()               # list of user scripts
00159                 
00160                 Gizmod.Keyboards = list()               # list of keyboards
00161                 Gizmod.Mice = list()                    # list of mice
00162                 Gizmod.Powermates = list()              # list of Powermates
00163                 Gizmod.ATIX10Remotes = list()           # list of ATI X10 Remotes
00164 
00165 ############################
00166 # GizmodDispatcher class end
00167 ##########################
00168 
00169 # To run user defined code post initializing, see User.py which is executed 
00170 # after this file is parsed, and:
00171 #
00172 # - An interface to the main C++ program core is availabe via the 
00173 #   object "Gizmod"
00174 # - An instantiation of the GizmodDispatcher is available as "Dispatcher"

Generated on Wed Nov 7 10:04:16 2007 for gizmod by  doxygen 1.5.3