1
# -*- coding: utf-8 -*-
2
# -----------------------------------------------------------------------------
3
# PyRoom - A clone of WriteRoom
4
# Copyright (c) 2007 Nicolas P. Rougier & NoWhereMan
5
# Copyright (c) 2008 The Pyroom Team - See AUTHORS file for more information
7
# This program is free software: you can redistribute it and/or modify it under
8
# the terms of the GNU General Public License as published by the Free Software
9
# Foundation, either version 3 of the License, or (at your option) any later
12
# This program is distributed in the hope that it will be useful, but WITHOUT
13
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17
# You should have received a copy of the GNU General Public License along with
18
# this program. If not, see <http://www.gnu.org/licenses/>.
19
# -----------------------------------------------------------------------------
24
provides a fading status bar that displays information to the user
32
class FadeLabel(gtk.Label):
33
""" GTK Label with timed fade out effect """
35
active_duration = 3000 # Fade start after this time
36
fade_duration = 1500.0 # Fade duration
38
def __init__(self, message='', active_color=None, inactive_color=None):
39
gtk.Label.__init__(self, message)
41
active_color = '#ffffff'
42
self.active_color = active_color
43
if not inactive_color:
44
inactive_color = '#000000'
46
self.inactive_color = inactive_color
49
def set_text(self, message, duration=None):
50
"""change text that is displayed
51
@param message: message to display
52
@param duration: duration in miliseconds"""
54
duration = self.active_duration
55
self.modify_fg(gtk.STATE_NORMAL,
56
gtk.gdk.color_parse(self.active_color))
57
gtk.Label.set_text(self, message)
59
gobject.source_remove(self.idle)
60
self.idle = gobject.timeout_add(duration, self.fade_start)
63
"""start fading timer"""
66
gobject.source_remove(self.idle)
67
self.idle = gobject.timeout_add(25, self.fade_out)
71
color = gtk.gdk.color_parse(self.inactive_color)
72
(red1, green1, blue1) = (color.red, color.green, color.blue)
73
color = gtk.gdk.color_parse(self.active_color)
74
(red2, green2, blue2) = (color.red, color.green, color.blue)
75
red = red1 + int(self.fade_level * abs(red1 - red2))
76
green = green1 + int(self.fade_level * abs(green1 - green2))
77
blue = blue1 + int(self.fade_level * abs(blue1 - blue2))
78
self.modify_fg(gtk.STATE_NORMAL, gtk.gdk.Color(red, green, blue))
79
self.fade_level -= 1.0 / (self.fade_duration / 25)
80
if self.fade_level > 0: