Package flumotion :: Package component :: Package misc :: Package httpfile :: Module admin_gtk
[hide private]

Source Code for Module flumotion.component.misc.httpfile.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 gtk 
 24   
 25  from gettext import gettext as _ 
 26   
 27  from flumotion.component.base.admin_gtk import BaseAdminGtk, BaseAdminGtkNode 
 28   
29 -class StatisticsAdminGtkNode(BaseAdminGtkNode):
30 glade_file = os.path.join('flumotion', 'component', 'misc', 31 'httpfile', 'httpfile.glade') 32
33 - def __init__(self, *args, **kwargs):
34 BaseAdminGtkNode.__init__(self, *args, **kwargs) 35 self.shown = False 36 self._stats = None
37
38 - def setStats(self, stats):
39 # Set _stats regardless of if condition 40 # Used to be a race where _stats was 41 # not set if widget tree was gotten before 42 # ui state 43 self._stats = stats 44 if not hasattr(self, 'statistics'): 45 # widget tree not created yet 46 return 47 48 self.updateLabels(stats) 49 50 if not self.shown: 51 # widget tree created but not yet shown 52 self.shown = True 53 self.statistics.show_all()
54
55 - def registerLabel(self, name):
56 #widgetname = name.replace('-', '_') 57 #FIXME: make object member directly 58 widget = self.wtree.get_widget('label-' + name) 59 if widget: 60 self.labels[name] = widget 61 else: 62 print "FIXME: no widget %s" % name
63
64 - def hideLabels(self):
65 for name in self.labels.keys(): 66 self.labels[name].hide()
67
68 - def updateLabels(self, state):
69 if not hasattr(self, 'labels'): 70 return 71 72 for name in self.labels.keys(): 73 text = state.get(name) 74 if text == None: 75 text = '' 76 else: 77 self.labels[name].set_text(str(text))
78
79 - def haveWidgetTree(self):
80 self.labels = {} 81 self.statistics = self.wtree.get_widget('statistics-widget') 82 self.widget = self.statistics 83 for type in ('bytes-transferred', 'connected-clients'): 84 self.registerLabel(type) 85 86 if self._stats: 87 self.shown = True 88 self.updateLabels(self._stats) 89 self.statistics.show_all() 90 91 return self.statistics
92
93 -class HTTPFileAdminGtk(BaseAdminGtk):
94 - def setup(self):
95 statistics = StatisticsAdminGtkNode(self.state, self.admin) 96 self.nodes['Statistics'] = statistics 97 # FIXME: maybe make a protocol instead of overriding 98 return BaseAdminGtk.setup(self)
99
100 - def uiStateChanged(self, state):
101 self.nodes['Statistics'].setStats(state)
102 103 GUIClass = HTTPFileAdminGtk 104