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