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