-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindicatorlabel.py
More file actions
39 lines (31 loc) · 1.3 KB
/
Copy pathindicatorlabel.py
File metadata and controls
39 lines (31 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!usr/bin/env python3:
#encoding: UTF8
from gi.repository import Gtk
class IndicatorLabel(Gtk.Label):
"""A label that has a rounded, colored background.
It is mainly useful for showing new entries or indicate errors.
There are 3 colors available, plus a color derived from the
theme's main color. In case of Adwaita blue.
"""
SUCCESS, WARNING, ERROR, THEME, DEFAULT = range(1, 6)
def __init__(self, *args):
Gtk.Label.__init__(self, *args)
self.set_use_markup(True)
# Do not expand space.
self.set_valign(Gtk.Align.CENTER)
self.set_halign(Gtk.Align.CENTER)
self.set_vexpand(False)
self.set_hexpand(False)
# Use the theme's color by default.
self.set_color(IndicatorLabel.THEME)
def set_color(self, state):
classes = {
IndicatorLabel.ERROR: 'AppIndicatorLabelError',
IndicatorLabel.SUCCESS: 'AppIndicatorLabelSuccess',
IndicatorLabel.WARNING: 'AppIndicatorLabelWarning',
IndicatorLabel.THEME: 'AppIndicatorLabelTheme',
IndicatorLabel.DEFAULT: 'AppIndicatorLabelDefault'
}
# Will act as normal label for invalid states.
# Useful for highlighting problematic input.
self.set_name(classes.get(state, 'AppIndicatorLabelEmpty'))