scripts/modules.d/210-Powermate-Firefox.py

00001     #***
00002   #*********************************************************************
00003 #*************************************************************************
00004 #*** 
00005 #*** GizmoDaemon Config Script
00006 #***    Powermate Firefox config
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 GizmoScriptActiveApplication import *
00035 
00036 ENABLED = True
00037 VERSION_NEEDED = 3.2
00038 INTERESTED_CLASSES = [GizmoEventClass.Powermate]
00039 INTERESTED_WINDOWS = ["firefox", "swiftfox", "iceweasel"]
00040 
00041 ############################
00042 # PowermateFirefox Class definition
00043 ##########################
00044 
00045 class PowermateFirefox(GizmoScriptActiveApplication):
00046         """
00047         Firefox Powermate Event Mapping
00048         """
00049         
00050         ############################
00051         # Public Functions
00052         ##########################
00053                         
00054         def onDeviceEvent(self, Event, Gizmo = None):
00055                 """
00056                 Called from Base Class' onEvent method.
00057                 See GizmodDispatcher.onEvent documention for an explanation of this function
00058                 """
00059                 
00060                 # Only interact with Firefox if it's the first Powermate
00061                 if Gizmo.DeviceClassID == 0:
00062                         # Check for rotations
00063                         if Event.Type == GizmoEventType.EV_REL:
00064                                 # scroll the window slowly if the button isn't pressed
00065                                 # and fast if the button is down
00066                                 if not Gizmo.getKeyState(GizmoKey.BTN_0):
00067                                         # scroll slowly (create a mouse wheel event)
00068                                         Gizmod.Mice[0].createEventRaw(GizmoEventType.EV_REL, GizmoMouseAxis.WHEEL, -Event.Value)
00069                                 else:
00070                                         # scroll quickly (by pages using the page up / page down keys)
00071                                         if Event.Value > 0:
00072                                                 for repeat in range(abs(Event.Value)):
00073                                                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEDOWN)
00074                                         else:
00075                                                 for repeat in range(abs(Event.Value)):
00076                                                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEUP)
00077                                 return True
00078                         # check for button press
00079                         elif Event.Type == GizmoEventType.EV_KEY:
00080                                 if Event.Value == 0 and not Gizmo.Rotated:
00081                                         # issue a close tab if the button is pressed
00082                                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_W, [GizmoKey.KEY_LEFTCTRL])
00083                                         return True
00084                         else:
00085                                 return False
00086                 else:
00087                         return False
00088         
00089         ############################
00090         # Private Functions
00091         ##########################
00092 
00093         def __init__(self):
00094                 """ 
00095                 Default Constructor
00096                 """
00097                 
00098                 GizmoScriptActiveApplication.__init__(self, ENABLED, VERSION_NEEDED, INTERESTED_CLASSES, INTERESTED_WINDOWS)
00099 
00100 ############################
00101 # PowermateFirefox class end
00102 ##########################
00103 
00104 # register the user script
00105 PowermateFirefox()

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