Subversion Repositories mmkeyboard2k

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 janik 1
# MMKeyboard2k On Screen Display Plugin
2
# Copyright (C) 2007  Jan Janech
3
 
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
 
14
# You should have received a copy of the GNU General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
import os
18
import pyosd
19
 
20
color = '#CFCF00'
21
timeout = 3
22
position = pyosd.POS_BOT
23
shadow = True
24
font = "-adobe-helvetica-bold-r-*-*-*-240-100-*-*-*-*-*"
25
 
26
 
27
class Plugin:
28
    osd = None
29
    maxlines = 1
30
 
31
    options = ('text', 'type', 'linecount')
32
    stdin = 'text'
33
 
34
    @staticmethod
35
    def config(c = None, t = None, p = None, s = None, f = None):
36
        global color, timeout, position, shadow, font
37
 
38
        if c:
39
            color = c
40
        if t:
41
            timeout = t
42
        if p:
43
            position = p
44
        if s:
45
            shadow = s
46
        if f:
47
            font = f
48
 
49
    def __init__(self, text, type = 'text', linecount = 1):
50
        type = type.lower()
51
        linecount = int(linecount)
52
 
53
        assert type in ('text', 'percent')
54
 
55
        if type == 'percent' and linecount == 1:
56
            linecount = 2
57
 
58
        self.text = text
59
        self.type = type
60
        self.linecount = linecount
61
        if linecount > self.maxlines:
62
            self.__class__.maxlines = linecount
63
 
64
    def __repr__(self):
65
        return '<osd.Plugin %r %s %d>'%(self.text, self.type, self.linecount)
66
 
67
    def __call__(self):
68
        if self.osd is None:
3 janik 69
            self.__class__.osd = pyosd.osd(font=font, colour = color, timeout = timeout, pos = position, shadow = shadow, lines = self.maxlines, offset=3)
1 janik 70
 
71
        if callable(self.text):
72
            text = str(self.text())
73
        else:
74
            text = str(self.text)
75
 
10 janik 76
        if text is None:
77
            return
78
 
1 janik 79
        if self.type == 'text':
80
            for id, line in enumerate([""]*(self.maxlines-self.linecount)+([""]*self.linecount+text.splitlines())[-self.linecount:]):
81
                self.osd.display(line, line = id)
82
        else:
83
            for id in xrange(self.maxlines - 2):
84
                self.osd.display("", line = id)
85
            s, v = (text+'\n0').splitlines()[:2]
86
            v = int(v)
87
            self.osd.display("%s(%d%%)"%(s, v), line = self.maxlines - 2)
88
            self.osd.display(v, type = pyosd.TYPE_PERCENT, line = self.maxlines - 1)