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,2008,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 as published by 
 11  # the Free Software Foundation. 
 12  # This file is distributed without any warranty; without even the implied 
 13  # warranty of merchantability or fitness for a particular purpose. 
 14  # See "LICENSE.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18  import os 
 19  import gettext 
 20   
 21  import gst 
 22   
 23  from flumotion.component.base.baseadminnode import BaseAdminGtkNode 
 24  from flumotion.component.common.avproducer.admin_gtk import AVProducerAdminGtk 
 25  from flumotion.ui.glade import GladeWidget 
 26   
 27  __version__ = "$Rev$" 
 28  _ = gettext.gettext 
 29   
 30   
31 -def time_to_string(value):
32 sec = value / gst.SECOND 33 mins = sec / 60 34 sec = sec % 60 35 hours = mins / 60 36 mins = mins % 60 37 return "%02d:%02d:%02d" % (hours, mins, sec)
38 39
40 -class FileInfo(GladeWidget):
41 gladeFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 42 'flufileinfo.glade') 43 duration = 0 44
45 - def set_location(self, location):
46 self.locationlabel.set_text(location)
47
48 - def set_duration(self, duration):
49 self.duration = duration 50 self.timelabel.set_text(time_to_string(duration))
51
52 - def set_audio(self, audio):
53 self.audiolabel.set_markup(audio or "<i>No audio</i>")
54
55 - def set_video(self, video):
56 self.videolabel.set_markup(video or "<i>No video</i>")
57 58
59 -class LooperNode(BaseAdminGtkNode):
60 logCategory = 'looper' 61 62 uiStateHandlers = None 63 gladeFile = os.path.join('flumotion', 'component', 'producers', 64 'looper', 'looper.glade') 65
66 - def haveWidgetTree(self):
67 self.widget = self.wtree.get_widget('looper-widget') 68 self.fileinfowidget = self.wtree.get_widget('fileinfowidget') 69 self.numiterlabel = self.wtree.get_widget('iterationslabel') 70 self.curposlabel = self.wtree.get_widget('curposlabel') 71 self.positionbar = self.wtree.get_widget('positionbar') 72 self.restartbutton = self.wtree.get_widget('restartbutton') 73 self.restartbutton.set_sensitive(False)
74
75 - def setUIState(self, state):
76 BaseAdminGtkNode.setUIState(self, state) 77 if not self.uiStateHandlers: 78 self.uiStateHandlers = {'info-duration': 79 self.fileinfowidget.set_duration, 80 'info-location': 81 self.fileinfowidget.set_location, 82 'info-audio': 83 self.fileinfowidget.set_audio, 84 'info-video': 85 self.fileinfowidget.set_video, 86 'position': self.positionSet, 87 'num-iterations': self.numIterationsSet} 88 for k, handler in self.uiStateHandlers.items(): 89 handler(state.get(k))
90
91 - def positionSet(self, newposition):
92 self.log("got new position : %d" % newposition) 93 if self.fileinfowidget.duration: 94 percent = (float(newposition % self.fileinfowidget.duration) / 95 float(self.fileinfowidget.duration)) 96 self.positionbar.set_fraction(percent) 97 self.positionbar.set_text( 98 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
122 -class LooperAdminGtk(AVProducerAdminGtk):
123
124 - def setup(self):
125 looper = LooperNode(self.state, self.admin, title=_("Looper")) 126 self.nodes['Looper'] = looper 127 128 return AVProducerAdminGtk.setup(self)
129 130 GUIClass = LooperAdminGtk 131