Package flumotion :: Package component :: Package effects :: Package volume :: Module admin_gtk
[hide private]

Source Code for Module flumotion.component.effects.volume.admin_gtk

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  import gtk 
 23  import os 
 24  import math 
 25   
 26  from flumotion.common import errors, log 
 27   
 28  # import custom glade handler 
 29  from flumotion.ui import glade 
 30   
 31  from flumotion.component.base import admin_gtk 
 32   
33 -def clamp(x, min, max):
34 if x < min: 35 return min 36 elif x > max: 37 return max 38 return x
39
40 -class VolumeAdminGtkNode(admin_gtk.EffectAdminGtkNode):
41 logCategory = 'volume' 42 glade_file = os.path.join('flumotion', 'component', 'effects', 43 'volume', 'volume.glade') 44 45 uiStateHandlers = None 46
47 - def haveWidgetTree(self):
48 self.widget = self.wtree.get_widget('volume-widget') 49 self.scale_volume = self.wtree.get_widget('level-widget') 50 self._volume_set_label = self.wtree.get_widget('volume-set-label') 51 self._volume_set_label.set_text('0') 52 self.shown = False 53 54 # now do the callbacks for the volume setting 55 self._hscale = self.wtree.get_widget('volume-set-hscale') 56 self._scale_changed_id = self._hscale.connect('value_changed', 57 self.cb_volume_set) 58 59 # callback for checkbutton 60 check = self.wtree.get_widget('volume-set-check') 61 check.connect('toggled', self._check_toggled_cb)
62
63 - def setUIState(self, state):
64 admin_gtk.EffectAdminGtkNode.setUIState(self, state) 65 if not self.uiStateHandlers: 66 self.uiStateHandlers = {'volume-volume': self.volumeSet, 67 'volume-peak': self.peakSet, 68 'volume-decay': self.decaySet} 69 for k, handler in self.uiStateHandlers.items(): 70 handler(state.get(k))
71
72 - def peakSet(self, peak):
73 peak = sum(peak)/len(peak) 74 self.scale_volume.set_property('peak', clamp(peak, -90.0, 0.0))
75
76 - def decaySet(self, decay):
77 decay = sum(decay)/len(decay) 78 self.scale_volume.set_property('decay', clamp(decay, -90.0, 0.0))
79 80 # when volume has been set by another admin client
81 - def volumeSet(self, volume):
82 self._hscale.handler_block(self._scale_changed_id) 83 self._hscale.set_value(volume) 84 dB = "- inf" 85 if volume: 86 dB = "%2.2f" % (20.0 * math.log10(volume)) 87 self._volume_set_label.set_text(dB) 88 self._hscale.handler_unblock(self._scale_changed_id)
89
90 - def stateSet(self, state, key, value):
91 handler = self.uiStateHandlers.get(key, None) 92 if handler: 93 handler(value)
94 95 # run when the scale is moved by user
96 - def cb_volume_set(self, widget):
97 # do something 98 volume = self._hscale.get_value() 99 #self.volumeSet(volume) 100 d = self.effectCallRemote("setVolume", volume) 101 d.addErrback(self.setVolumeErrback)
102
103 - def setVolumeErrback(self, failure):
104 self.warning("Failure %s setting volume: %s" % ( 105 failure.type, failure.getErrorMessage())) 106 return None
107
108 - def _update_volume_label(self):
109 # update the volume label's dB value 110 pass
111 112 # when the "increase volume" checkbutton is toggled
113 - def _check_toggled_cb(self, widget):
114 checked = widget.get_property('active') 115 self.debug('checkbutton toggled; now %r' % checked) 116 value = self._hscale.get_value() 117 if checked: 118 self._hscale.set_range(0.0, 4.0) 119 else: 120 if value > 1.0: value = 1.0 121 self._hscale.set_range(0.0, 1.0) 122 self.volumeSet(value)
123