scripts/modules.d/510-LIRC-Hauppauge-MythTV.py

00001     #***
00002   #*********************************************************************
00003 #*************************************************************************
00004 #*** 
00005 #*** GizmoDaemon Config Script
00006 #***    LIRCHauppauge MythTV 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 import subprocess
00036 
00037 ENABLED = True
00038 VERSION_NEEDED = 3.2
00039 INTERESTED_CLASSES = [GizmoEventClass.LIRC]
00040 INTERESTED_WINDOWS = ["mythfrontend"]
00041 USES_LIRC_REMOTES = ["Hauppauge_350"]
00042 POWER_APPLICATION = "mythfrontend"
00043 
00044 ############################
00045 # LIRCHauppaugeMythTV Class definition
00046 ##########################
00047 
00048 class LIRCHauppaugeMythTV(GizmoScriptActiveApplication):
00049         """
00050         MythTV LIRC Event Mapping for the Hauppauge remote
00051         """
00052         
00053         ############################
00054         # Public Functions
00055         ##########################
00056                         
00057         def onDeviceEvent(self, Event, Gizmo = None):
00058                 """
00059                 Called from Base Class' onEvent method.
00060                 See GizmodDispatcher.onEvent documention for an explanation of this function
00061                 """
00062 
00063                 # if the event isn't from the remote we're interested in don't handle it
00064                 if Event.Remote not in USES_LIRC_REMOTES:
00065                         return False
00066 
00067                 # process the key
00068                 if   Event.Button == "Go":
00069                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_A)
00070                         return True
00071                 elif Event.Button == "Power":
00072                         # if mythfrontend is open, kill it
00073                         subprocess.Popen(["killall", "mythfrontend"])
00074                         return True
00075                 elif Event.Button == "TV":
00076                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_B)
00077                         return True
00078                 elif Event.Button == "Videos":
00079                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_SLASH)
00080                         return True
00081                 elif Event.Button == "Music":                   
00082                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_SLASH, [GizmoKey.KEY_RIGHTSHIFT])
00083                         return True
00084                 elif Event.Button == "Pictures":
00085                         return False
00086                 elif Event.Button == "Guide":
00087                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_S)
00088                         return True
00089                 elif Event.Button == "Up":
00090                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_UP)
00091                         return True
00092                 elif Event.Button == "Radio":
00093                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_N)
00094                         return True
00095                 elif Event.Button == "Left":
00096                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_LEFT)
00097                         return True
00098                 elif Event.Button == "OK":
00099                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_ENTER)
00100                         return True
00101                 elif Event.Button == "Right":
00102                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHT)
00103                         return True
00104                 elif Event.Button == "Back/Exit":
00105                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_ESC)
00106                         return True
00107                 elif Event.Button == "Down":
00108                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_DOWN)
00109                         return True
00110                 elif Event.Button == "Menu/i":
00111                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_M)
00112                         return True
00113                 elif Event.Button == "Vol+":
00114                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHTBRACE)
00115                         return True
00116                 elif Event.Button == "Vol-":
00117                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_LEFTBRACE)
00118                         return True
00119                 elif Event.Button == "Prev.Ch":
00120                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_H)
00121                         return True
00122                 elif Event.Button == "Mute":
00123                         return False
00124                 elif Event.Button == "Ch+":
00125                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_UP)
00126                         return True
00127                 elif Event.Button == "Ch-":
00128                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_DOWN)
00129                         return True
00130                 elif Event.Button == "Record":
00131                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_R)
00132                         return True
00133                 elif Event.Button == "Stop":
00134                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_S)
00135                         return True
00136                 elif Event.Button == "Rewind":
00137                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_COMMA, [GizmoKey.KEY_RIGHTSHIFT])
00138                         return True
00139                 elif Event.Button == "Play":
00140                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_P)
00141                         return True
00142                 elif Event.Button == "Forward":
00143                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_DOT, [GizmoKey.KEY_RIGHTSHIFT])
00144                         return True
00145                 elif Event.Button == "Replay/SkipBackward":
00146                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEUP)
00147                         return True
00148                 elif Event.Button == "Pause":
00149                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_P)
00150                         return True
00151                 elif Event.Button == "SkipForward":
00152                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEDOWN)
00153                         return True
00154                 elif Event.Button == "1":
00155                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_1)
00156                         return True
00157                 elif Event.Button == "2":
00158                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_2)
00159                         return True
00160                 elif Event.Button == "3":
00161                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_3)
00162                         return True
00163                 elif Event.Button == "4":
00164                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_4)
00165                         return True
00166                 elif Event.Button == "5":
00167                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_5)
00168                         return True
00169                 elif Event.Button == "6":
00170                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_6)
00171                         return True
00172                 elif Event.Button == "7":
00173                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_7)
00174                         return True
00175                 elif Event.Button == "8":
00176                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_8)
00177                         return True
00178                 elif Event.Button == "9":
00179                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_9)
00180                         return True
00181                 elif Event.Button == "Asterix":
00182                         return False
00183                 elif Event.Button == "0":
00184                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_0)
00185                         return True
00186                 elif Event.Button == "#":
00187                         return False
00188                 elif Event.Button == "Red":
00189                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_END)
00190                         return True
00191                 elif Event.Button == "Green":
00192                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_HOME)
00193                         return True
00194                 elif Event.Button == "Yellow":
00195                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_C)
00196                         return True
00197                 elif Event.Button == "Blue":
00198                         Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_I)
00199                         return True
00200                 else:
00201                         # unmatched event, keep processing
00202                         return False                            
00203                 
00204         def onEvent(self, Event, Gizmo = None):
00205                 """
00206                 Overloading Base Class' onEvent method!
00207                 Make sure to call it!
00208                 """
00209                 
00210                 # check for power button
00211                 # if pressed and mythfrontend isn't running, then launch it
00212                 # also return False so that other scripts may make use of the power
00213                 # button as well
00214                 if Event.Class in self.InterestedClasses \
00215                    and Event.Remote in USES_LIRC_REMOTES \
00216                    and Event.Button == "Power" \
00217                    and Gizmod.isProcessRunning(POWER_APPLICATION) < 0:
00218                         subprocess.Popen([POWER_APPLICATION])
00219                         Gizmod.updateProcessTree() # force an instantaneous process tree update
00220                         return False
00221 
00222                 # call base classe' onEvent method
00223                 return GizmoScriptActiveApplication.onEvent(self, Event, Gizmo)         
00224         
00225         ############################
00226         # Private Functions
00227         ##########################
00228 
00229         def __init__(self):
00230                 """ 
00231                 Default Constructor
00232                 """
00233                 
00234                 GizmoScriptActiveApplication.__init__(self, ENABLED, VERSION_NEEDED, INTERESTED_CLASSES, INTERESTED_WINDOWS)
00235 
00236 ############################
00237 # LIRCHauppaugeMythTV class end
00238 ##########################
00239 
00240 # register the user script
00241 LIRCHauppaugeMythTV()

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