scripts/modules.d/visualizers/VisualizerDefault.py

00001     #***
00002   #*********************************************************************
00003 #*************************************************************************
00004 #*** 
00005 #*** GizmoDaemon Config Script
00006 #***    Visualizer Default 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 import sys
00035 
00036 VERSION_NEEDED = 3.1
00037 INTERRUPT_LENGTH = 10
00038 
00039 ############################
00040 # Visualization Class definition
00041 ##########################
00042 
00043 class VisualizationType:
00044         """
00045         Types of visualizations
00046         """
00047         
00048         CPUUsage =              "CPUUsage"
00049         SoundVisualization =    "SoundVisualization"
00050         Volume =                "Volume"
00051 
00052 ############################
00053 # VisualizerDefault Class definition
00054 ##########################
00055 
00056 class VisualizerDefault:
00057         """
00058         Keyboard Visualization Handler
00059         """
00060         
00061         ############################
00062         # Public Functions
00063         ##########################
00064                                         
00065         def onEvent(self, Event, Gizmo = None):
00066                 """
00067                 See GizmodDispatcher.onEvent documention for an explanation of this function
00068                 """
00069                 
00070                 # take care of the interrupt count
00071                 if Event.Class == GizmoEventClass.CPUUsage:
00072                         if self.InterruptCount:
00073                                 self.InterruptCount -= 1
00074                         if self.SoundVisCount:
00075                                 self.SoundVisCount -= 1
00076                                 if not self.SoundVisCount:
00077                                         self.Visualization = self.LastVis
00078                 
00079                 # take care of the interrupt count
00080                 if Event.Class == GizmoEventClass.SoundVisualization:
00081                         if Event.Type == SoundVisualizationEventType.Connect:
00082                                 self.LastVis = self.Visualization
00083                         self.Visualization = VisualizationType.SoundVisualization
00084                         self.SoundVisCount = INTERRUPT_LENGTH
00085                 
00086                 # check for mixer events
00087                 if (self.Visualization == VisualizationType.Volume or self.VolumeInterruptsOthers) \
00088                    and Event.Class == GizmoEventClass.SoundCard \
00089                    and Event.Type == AlsaEventType.MixerElementChange:
00090                         # if we're an interruption, mark the occasion
00091                         self.InterruptCount = INTERRUPT_LENGTH
00092                         
00093                         # check for volume changed
00094                         if Event.VolumePlaybackChanged \
00095                            and Gizmod.DefaultMixerVolume \
00096                            and Event.Mixer.Name == Gizmod.DefaultMixerVolume.Name:
00097                                 self.applyVisualizationVolume()
00098                                 
00099                         # check for switch changed
00100                         if Event.SwitchPlaybackChanged \
00101                            and Gizmod.DefaultMixerSwitch \
00102                            and Event.Mixer.Name == Gizmod.DefaultMixerSwitch.Name:
00103                                 self.applyVisualizationVolume()
00104                                 
00105                 # check for CPUUsage events
00106                 elif self.Visualization == VisualizationType.CPUUsage \
00107                    and Event.Class == GizmoEventClass.CPUUsage\
00108                    and not (Gizmod.DefaultMixerSwitch and (not Gizmod.DefaultMixerSwitch.SwitchPlayback)):
00109                         if not self.InterruptCount:
00110                                 self.applyVisualizationCPUUsage(Event)
00111 
00112                 # check for Sound Visualization events
00113                 elif self.Visualization == VisualizationType.SoundVisualization \
00114                    and Event.Class == GizmoEventClass.SoundVisualization \
00115                    and not (Gizmod.DefaultMixerSwitch and (not Gizmod.DefaultMixerSwitch.SwitchPlayback)):
00116                         if not self.InterruptCount:
00117                                 self.applyVisualizationSound(Event)
00118 
00119                 return False
00120                                         
00121         ############################
00122         # Private Functions
00123         ##########################
00124         
00125         def __init__(self):
00126                 """ 
00127                 Default Constructor
00128                 """
00129 
00130                 # initialize member variables
00131                 self.Visualization = VisualizationType.CPUUsage # Current LED visualizer
00132                 self.LastVis = self.Visualization               # Last known visualizer
00133                 self.VolumeInterruptsOthers = True              # Set to True if volume changes should interrupt other visualizations
00134                 self.InterruptCount = 0                         # Length of time to remain interrupted
00135                 self.SoundVisCount = 0                          # Amarok is buggy and doesn't notify on exit, so this is the workaround
00136         
00137                 # apply the initial visualization
00138                 self.applyVisualizationVolume()
00139 
00140 ############################
00141 # KeyboardVisualization class end
00142 ##########################

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