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 GizmoScriptActiveApplication import *
00035 from GizmoScriptAltTabber import *
00036 import subprocess
00037
00038 ENABLED = True
00039 VERSION_NEEDED = 3.2
00040 INTERESTED_CLASSES = [GizmoEventClass.LIRC]
00041 INTERESTED_WINDOWS = ["mythfrontend"]
00042 USES_LIRC_REMOTES = ["mceusb", "mceusb2"]
00043 POWER_APPLICATION = "mythfrontend"
00044
00045
00046
00047
00048
00049 class LIRCMceUSB2MythTV(GizmoScriptActiveApplication):
00050 """
00051 MythTV LIRC Event Mapping for the MceUSB2 remote
00052 """
00053
00054
00055
00056
00057
00058 def onDeviceEvent(self, Event, Gizmo = None):
00059 """
00060 Called from Base Class' onEvent method.
00061 See GizmodDispatcher.onEvent documention for an explanation of this function
00062 """
00063
00064
00065 if Event.Remote not in USES_LIRC_REMOTES:
00066 return False
00067
00068
00069 if Event.Button == "Power":
00070
00071 subprocess.Popen(["killall", "mythfrontend"])
00072 return True
00073 elif Event.Button == "TV":
00074 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_A)
00075 return True
00076 elif Event.Button == "Music":
00077 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_B)
00078 return True
00079 elif Event.Button == "Pictures":
00080 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_SLASH)
00081 return True
00082 elif Event.Button == "Videos":
00083 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_SLASH, [GizmoKey.KEY_RIGHTSHIFT])
00084 return True
00085 elif Event.Button == "Stop":
00086 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_S)
00087 return True
00088 elif Event.Button == "Record":
00089 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_R)
00090 return True
00091 elif Event.Button == "Pause":
00092 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_P)
00093 return True
00094 elif Event.Button == "Rewind":
00095 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_COMMA, [GizmoKey.KEY_RIGHTSHIFT])
00096 return True
00097 elif Event.Button == "Play":
00098 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_P)
00099 return True
00100 elif Event.Button == "Forward":
00101 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_DOT, [GizmoKey.KEY_RIGHTSHIFT])
00102 return True
00103 elif Event.Button == "Replay":
00104 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEUP)
00105 return True
00106 elif Event.Button == "Back":
00107 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_ESC)
00108 return True
00109 elif Event.Button == "Up":
00110 return False
00111 elif Event.Button == "Skip":
00112 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEDOWN)
00113 return True
00114 elif Event.Button == "More":
00115 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_M)
00116 return True
00117 elif Event.Button == "Left":
00118 return False
00119 elif Event.Button == "OK":
00120 return False
00121 elif Event.Button == "Right":
00122 return False
00123 elif Event.Button == "Down":
00124 return False
00125 elif Event.Button == "VolUp":
00126 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHTBRACE)
00127 return True
00128 elif Event.Button == "VolDown":
00129 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_LEFTBRACE)
00130 return True
00131 elif Event.Button == "Home":
00132 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_END)
00133 return True
00134 elif Event.Button == "ChanUp":
00135 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_UP)
00136 return True
00137 elif Event.Button == "ChanDown":
00138 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_DOWN)
00139 return True
00140 elif Event.Button == "RecTV":
00141 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_HOME)
00142 return True
00143 elif Event.Button == "Mute":
00144 return False
00145 elif Event.Button == "DVD":
00146 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_H)
00147 return True
00148 elif Event.Button == "Guide":
00149 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_S)
00150 return True
00151 elif Event.Button == "LiveTV":
00152 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_N)
00153 return True
00154 elif Event.Button == "One":
00155 return False
00156 elif Event.Button == "Two":
00157 return False
00158 elif Event.Button == "Three":
00159 return False
00160 elif Event.Button == "Four":
00161 return False
00162 elif Event.Button == "Five":
00163 return False
00164 elif Event.Button == "Six":
00165 return False
00166 elif Event.Button == "Seven":
00167 return False
00168 elif Event.Button == "Eight":
00169 return False
00170 elif Event.Button == "Nine":
00171 return False
00172 elif Event.Button == "Star":
00173 return False
00174 elif Event.Button == "Zero":
00175 return False
00176 elif Event.Button == "Hash":
00177 return False
00178 elif Event.Button == "Clear":
00179 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_C)
00180 return True
00181 elif Event.Button == "Enter":
00182 Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_I)
00183 return True
00184 else:
00185
00186 return False
00187
00188 def onEvent(self, Event, Gizmo = None):
00189 """
00190 Overloading Base Class' onEvent method!
00191 Make sure to call it!
00192 """
00193
00194
00195
00196
00197
00198 if Event.Class in self.InterestedClasses \
00199 and Event.Remote in USES_LIRC_REMOTES \
00200 and Event.Button == "Power" \
00201 and Gizmod.isProcessRunning(POWER_APPLICATION) < 0:
00202 subprocess.Popen([POWER_APPLICATION])
00203 Gizmod.updateProcessTree()
00204 return False
00205
00206
00207 return GizmoScriptActiveApplication.onEvent(self, Event, Gizmo)
00208
00209
00210
00211
00212
00213 def __init__(self):
00214 """
00215 Default Constructor
00216 """
00217
00218 GizmoScriptActiveApplication.__init__(self, ENABLED, VERSION_NEEDED, INTERESTED_CLASSES, INTERESTED_WINDOWS)
00219
00220
00221
00222
00223
00224
00225 LIRCMceUSB2MythTV()