scripts/modules.d/250-Powermate-Amarok.py

00001     #***
00002   #*********************************************************************
00003 #*************************************************************************
00004 #*** 
00005 #*** GizmoDaemon Config Script
00006 #***    Powermate Amarok 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 GizmoScriptRunningApplication import *
00035 import subprocess
00036 
00037 ENABLED = True
00038 VERSION_NEEDED = 3.2
00039 INTERESTED_CLASSES = [GizmoEventClass.Powermate]
00040 INTERESTED_APPLICATION = "amarokapp"
00041 
00042 ############################
00043 # PowermateAmarok Class definition
00044 ##########################
00045 
00046 class PowermateAmarok(GizmoScriptRunningApplication):
00047         """
00048         Amarok Powermate Event Mapping
00049         """
00050         
00051         ############################
00052         # Public Functions
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                 # Only interact with Amarok if it's the first Powermate
00062                 if Gizmo.DeviceClassID == 0:
00063                         # Check for rotations
00064                         if Event.Type == GizmoEventType.EV_REL:
00065                                 if Gizmo.getKeyState(GizmoKey.BTN_0):
00066                                         # scroll quickly (by pages using the page up / page down keys)
00067                                         if Event.Value > 0:
00068                                                 for repeat in range(abs(Event.Value)):
00069                                                         subprocess.Popen(["amarok", "--previous"])
00070                                         else:
00071                                                 for repeat in range(abs(Event.Value)):
00072                                                         subprocess.Popen(["amarok", "--next"])
00073                                         return True
00074                         elif Event.Type == GizmoEventType.EV_KEY:
00075                                 if Event.Value == 0 and not Gizmo.Rotated:
00076                                         subprocess.Popen(["amarok", "--play-pause"])
00077                                         return True
00078                 return False
00079                 
00080         ############################
00081         # Private Functions
00082         ##########################
00083 
00084         def __init__(self):
00085                 """ 
00086                 Default Constructor
00087                 """
00088                 
00089                 GizmoScriptRunningApplication.__init__(self, ENABLED, VERSION_NEEDED, INTERESTED_CLASSES, INTERESTED_APPLICATION)
00090 
00091 ############################
00092 # PowermateAmarok class end
00093 ##########################
00094 
00095 # register the user script
00096 PowermateAmarok()

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