public
Description: A desktop widget that display informations about CPU speed, temperature and so on through OSD
Homepage:
Clone URL: git://github.com/kratorius/osdwidget.git
osdwidget / base.py
100644 53 lines (42 sloc) 1.29 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pyosd
 
from settings import FONT_FACE
 
class BaseWidget(object):
    """
The base class for the OSD widgets. Every widget should extend
this class to do its dirty stuff.
"""
 
    def __init__(self):
        osd = pyosd.osd()
        self.msg = ""
 
        # set common stuff
        osd.set_font(FONT_FACE)
        osd.set_outline_offset(1)
        osd.set_timeout(0)
        osd.set_vertical_offset(2)
        osd.set_align(pyosd.ALIGN_RIGHT)
        osd.set_pos(pyosd.POS_TOP)
        osd.set_colour("yellow")
 
        self.osd = osd
 
    def update(self, text, color):
        self.msg = (text, color)
 
    def get_msg(self):
        """
Returns the tuple in the format (message, color) where message
is the text that should be shown on OSD and color the text's
color.
 
In most cases, when extending this class you may want to override
only this method.
"""
        return self.msg
 
    def display(self):
        """
Display the text through OSD
"""
        msg = self.get_msg()
        self.osd.set_colour(msg[1])
        self.osd.display(msg[0])
 
    def set_horizontal_offset(self, offset):
        """
Set the OSD horizontal offset
"""
        self.osd.set_horizontal_offset(offset)