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