Package flumotion :: Package admin :: Package gtk :: Module statusbar
[hide private]

Source Code for Module flumotion.admin.gtk.statusbar

  1  # -*- Mode: Python; test-case-name: flumotion.test.test_parts -*- 
  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 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  """statusbar widget used by in admin window""" 
 23   
 24  __version__ = "$Rev: 6961 $" 
 25   
 26   
27 -class AdminStatusbar(object):
28 """ 29 I implement the status bar used in the admin UI. 30 """
31 - def __init__(self, widget):
32 """ 33 @param widget: a gtk.Statusbar to wrap. 34 """ 35 self._widget = widget 36 37 self._cids = {} # hash of context -> context id 38 self._mids = {} # hash of context -> message id lists 39 self._contexts = ['main', 'notebook'] 40 41 for context in self._contexts: 42 self._cids[context] = widget.get_context_id(context) 43 self._mids[context] = []
44
45 - def clear(self, context=None):
46 """ 47 Clear the status bar for the given context, or for all contexts 48 if none specified. 49 """ 50 if context: 51 self._clearContext(context) 52 return 53 54 for context in self._contexts: 55 self._clearContext(context)
56
57 - def push(self, context, message):
58 """ 59 Push the given message for the given context. 60 61 @returns: message id 62 """ 63 mid = self._widget.push(self._cids[context], message) 64 self._mids[context].append(mid) 65 return mid
66
67 - def pop(self, context):
68 """ 69 Pop the last message for the given context. 70 71 @returns: message id popped, or None 72 """ 73 if len(self._mids[context]): 74 mid = self._mids[context].pop() 75 self._widget.remove(self._cids[context], mid) 76 return mid 77 78 return None
79
80 - def set(self, context, message):
81 """ 82 Replace the current top message for this context with this new one. 83 84 @returns: the message id of the message pushed 85 """ 86 self.pop(context) 87 return self.push(context, message)
88
89 - def remove(self, context, mid):
90 """ 91 Remove the message with the given id from the given context. 92 93 @returns: whether or not the given mid was valid. 94 """ 95 if not mid in self._mids[context]: 96 return False 97 98 self._mids[context].remove(mid) 99 self._widget.remove(self._cids[context], mid) 100 return True
101
102 - def _clearContext(self, context):
103 if not context in self._cids.keys(): 104 return 105 106 for mid in self._mids[context][:]: 107 self.remove(context, mid)
108