00001
00002
00003
00004
00005
00006
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
00031
00032
00033 from GizmoDaemon import *
00034 from GizmoScriptDefault import *
00035 from GizmoDeviceStrings import *
00036 import time
00037
00038 ENABLED = True
00039 VERSION_NEEDED = 3.3
00040 INTERESTED_CLASSES = [GizmoEventClass.Powermate]
00041
00042
00043
00044
00045
00046 class PowermateButtonTimeout(GizmoScriptDefault):
00047 """
00048 ButtonTimeout Powermate Event Mapping
00049 """
00050
00051
00052
00053
00054
00055 def onDeviceEvent(self, Event, Gizmo = None):
00056 """
00057 Called from Base Class' onEvent method.
00058 See GizmodDispatcher.onEvent documention for an explanation of this function
00059 """
00060
00061
00062 if Event.Type == GizmoEventType.EV_KEY:
00063 if Event.Value == 1:
00064
00065 self.ButtonTimeoutTimers[Gizmo.FileName] = GizmodTimer(POWERMATE_BUTTON_TIMEOUT, self.timerCallback, Gizmo)
00066 self.ButtonTimeoutTimers[Gizmo.FileName].start()
00067 self.ButtonTimeoutEatNexts[Gizmo.FileName] = False
00068 else:
00069 if not self.ButtonTimeoutEatNexts[Gizmo.FileName]:
00070
00071 self.ButtonTimeoutTimers[Gizmo.FileName].cancel()
00072 else:
00073
00074 self.ButtonTimeoutEatNexts[Gizmo.FileName] = False
00075
00076
00077
00078 for UserScript in Gizmod.Dispatcher.userScripts:
00079 if UserScript.__class__.__name__.find("Powermate") == -1:
00080 continue
00081 if "onDeviceEventEaten" in dir(UserScript):
00082 if UserScript.onDeviceEventEaten(Event, Gizmo):
00083 break
00084 return True
00085 elif Event.Type == GizmoEventType.EV_REL:
00086 try:
00087 self.ButtonTimeoutTimers[Gizmo.FileName].cancel()
00088 except KeyError:
00089
00090 pass
00091 return False
00092
00093 def onDeviceEventButtonTimeout(self, Gizmo):
00094 """
00095 Called when a Powermate's button times out
00096
00097 This is generated from 200-Powermate-ButtonTimeout.py
00098 """
00099
00100
00101 return False
00102
00103 def onDeviceEventEaten(self, Event, Gizmo):
00104 """
00105 Called when a Powermate's button is released after timing out
00106
00107 This is generated from 200-Powermate-ButtonTimeout.py
00108 """
00109
00110
00111 return False
00112
00113 def timerCallback(self, UserData):
00114 """
00115 Timer function callback
00116 """
00117
00118
00119 self.ButtonTimeoutEatNexts[UserData.FileName] = True
00120
00121
00122
00123 for UserScript in Gizmod.Dispatcher.userScripts:
00124 if UserScript.__class__.__name__.find("Powermate") == -1:
00125 continue
00126 if "onDeviceEventButtonTimeout" in dir(UserScript):
00127 if UserScript.onDeviceEventButtonTimeout(UserData):
00128 break
00129
00130
00131
00132
00133
00134 def __init__(self):
00135 """
00136 Default Constructor
00137 """
00138
00139 GizmoScriptDefault.__init__(self, ENABLED, VERSION_NEEDED, INTERESTED_CLASSES)
00140 self.ButtonTimeoutTimers = {}
00141 self.ButtonTimeoutEatNexts = {}
00142
00143
00144
00145
00146
00147
00148 PowermateButtonTimeout()