Package flumotion :: Package component :: Package producers :: Package looper :: Module admin_gtk
[hide private]

Source Code for Module flumotion.component.producers.looper.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  from gettext import gettext as _ 
 23   
 24  import os 
 25  import gst 
 26  from twisted.internet import defer 
 27   
 28  from flumotion.common import errors 
 29   
 30  from flumotion.component.base.admin_gtk import BaseAdminGtk, BaseAdminGtkNode 
 31   
 32  from flumotion.ui.glade import GladeWidget 
 33   
34 -def time_to_string(value):
35 sec = value / gst.SECOND 36 mins = sec / 60 37 sec = sec % 60 38 hours = mins / 60 39 mins = mins % 60 40 return "%02d:%02d:%02d" % (hours, mins, sec)
41 42
43 -class FileInfo(GladeWidget):
44 glade_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 45 'flufileinfo.glade') 46 duration = 0 47
48 - def set_location(self, location):
49 self.locationlabel.set_text(location)
50
51 - def set_duration(self, duration):
52 self.duration = duration 53 self.timelabel.set_text(time_to_string(duration))
54
55 - def set_audio(self, audio):
56 self.audiolabel.set_text(audio or "<i>No audio</i>")
57
58 - def set_video(self, video):
59 self.videolabel.set_text(video or "<i>No video</i>")
60
61 -class LooperNode(BaseAdminGtkNode):
62 logCategory = 'looper' 63 64 uiStateHandlers = None 65 glade_file = os.path.join('flumotion', 'component', 'producers', 66 'looper', 'looper.glade') 67
68 - def haveWidgetTree(self):
69 self.widget = self.wtree.get_widget('looper-widget') 70 self.fileinfowidget = self.wtree.get_widget('fileinfowidget') 71 self.numiterlabel = self.wtree.get_widget('iterationslabel') 72 self.curposlabel = self.wtree.get_widget('curposlabel') 73 self.positionbar = self.wtree.get_widget('positionbar') 74 self.restartbutton = self.wtree.get_widget('restartbutton') 75 self.restartbutton.set_sensitive(False)
76
77 - def setUIState(self, state):
78 BaseAdminGtkNode.setUIState(self, state) 79 if not self.uiStateHandlers: 80 self.uiStateHandlers = {'info-duration': 81 self.fileinfowidget.set_duration, 82 'info-location': 83 self.fileinfowidget.set_location, 84 'info-audio': 85 self.fileinfowidget.set_audio, 86 'info-video': 87 self.fileinfowidget.set_video, 88 'position': self.positionSet, 89 'num-iterations': self.numIterationsSet} 90 for k, handler in self.uiStateHandlers.items(): 91 handler(state.get(k))
92
93 - def positionSet(self, newposition):
94 self.log("got new position : %d" % newposition) 95 if self.fileinfowidget.duration: 96 percent = float(newposition % self.fileinfowidget.duration) / float(self.fileinfowidget.duration) 97 self.positionbar.set_fraction(percent) 98 self.positionbar.set_text(time_to_string(newposition % self.fileinfowidget.duration))
99
100 - def numIterationsSet(self, numIterations):
101 self.numiterlabel.set_text(str(numIterations))
102
103 - def _restart_callback(self, result):
104 pass
105
106 - def _restart_failed(self, failure):
107 self.warning("Failure %s getting pattern: %s" % ( 108 failure.type, failure.getErrorMessage())) 109 return None
110
111 - def _reset_button_clicked(self, button):
112 d = self.callRemote("gimme5", "ooooh yeah") 113 d.addCallback(self._restart_callback) 114 d.addErrback(self._restart_failed)
115
116 - def stateSet(self, state, key, value):
117 handler = self.uiStateHandlers.get(key, None) 118 if handler: 119 handler(value)
120
121 -class LooperAdminGtk(BaseAdminGtk):
122 - def setup(self):
123 looper = LooperNode(self.state, self.admin, title=_("Looper")) 124 self.nodes['Looper'] = looper 125 126 return BaseAdminGtk.setup(self)
127 128 GUIClass = LooperAdminGtk 129