Julio Biason
15 years ago
2 changed files with 100 additions and 18 deletions
@ -0,0 +1,92 @@ |
|||||||
|
#!/usr/bin/env python |
||||||
|
# -*- coding: utf-8 -*- |
||||||
|
|
||||||
|
# Mitter, a micro-blogging client with multiple interfaces. |
||||||
|
# Copyright (C) 2007-2010 Mitter Contributors |
||||||
|
# |
||||||
|
# This program is free software: you can redistribute it and/or modify |
||||||
|
# it under the terms of the GNU General Public License as published by |
||||||
|
# the Free Software Foundation, either version 3 of the License, or |
||||||
|
# (at your option) any later version. |
||||||
|
# |
||||||
|
# This program is distributed in the hope that it will be useful, |
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
# GNU General Public License for more details. |
||||||
|
# |
||||||
|
# You should have received a copy of the GNU General Public License |
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||||
|
|
||||||
|
import gobject |
||||||
|
import gtk |
||||||
|
|
||||||
|
import logging |
||||||
|
|
||||||
|
# ---------------------------------------------------------------------- |
||||||
|
# Constants |
||||||
|
# ---------------------------------------------------------------------- |
||||||
|
|
||||||
|
_log = logging.getLogger('ui.pygtk') |
||||||
|
|
||||||
|
# ---------------------------------------------------------------------- |
||||||
|
# Smart statusbar message queueing object |
||||||
|
# ---------------------------------------------------------------------- |
||||||
|
class SmartStatusbar(gtk.Statusbar): |
||||||
|
"""A custom status bar with smart placement of messages.""" |
||||||
|
|
||||||
|
def __init__(self): |
||||||
|
super(SmartStatusbar, self).__init__() |
||||||
|
|
||||||
|
self.static = None |
||||||
|
self.pairs = {} |
||||||
|
|
||||||
|
self._context = self.get_context_id('Mitter') |
||||||
|
return |
||||||
|
|
||||||
|
def static(self, message): |
||||||
|
"""Place a new static message in the statusbar. Only one static |
||||||
|
message can be in the message stack at a time; if there is any static |
||||||
|
messages in the stack, it will be removed before the new one is |
||||||
|
added.""" |
||||||
|
if self.static: |
||||||
|
# remove any previous static messages |
||||||
|
self.remove_message(self._context, self.static) |
||||||
|
|
||||||
|
self.static = self.push(self._context, message) |
||||||
|
return |
||||||
|
|
||||||
|
def volatile(self, message, seconds=10, pair=None): |
||||||
|
"""Place a new volatile message in the statusbar. Volatile messages |
||||||
|
are removed from the statusbar in two possiblities: |
||||||
|
* The first way is after the number of seconds has passed. |
||||||
|
* The second way by pairing; The first time a message appears with a |
||||||
|
pair name, it is not queued for removal after some time like normal |
||||||
|
messages; the message will stay in the message stack till its pair |
||||||
|
appear, when it will be finally removed; the second message, in this |
||||||
|
case, will be removed after the number of seconds, like any |
||||||
|
non-paired message.""" |
||||||
|
message_id = self.push(self._context, message)) |
||||||
|
|
||||||
|
# pair checking |
||||||
|
if pair: |
||||||
|
if pair in self.pairs: |
||||||
|
# this is the second message. We remove the first one and |
||||||
|
# this one will be removed like any other message. |
||||||
|
first = self.pairs[pair] |
||||||
|
self.remove_message(self._context, first) |
||||||
|
del self.pairs[pair] |
||||||
|
else: |
||||||
|
# this is the first message of the pair. It will not be |
||||||
|
# removed but the timeout. |
||||||
|
self.pairs[pairs] = message_id |
||||||
|
return |
||||||
|
|
||||||
|
self.timeout = gobject.timeout_add( |
||||||
|
seconds * 1000, # removal after 20 seconds |
||||||
|
self.remove_volatile, message_id) |
||||||
|
return |
||||||
|
|
||||||
|
def kill_volatiles(self, message_id): |
||||||
|
"""Kill all messages that are marked as volatiles.""" |
||||||
|
self.remove_message(self._context, message_id) |
||||||
|
return |
Loading…
Reference in new issue