Subversion Repositories mmkeyboard2k

Rev

Rev 3 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 10
1
# MMKeyboard2k On Screen Display Plugin
1
# MMKeyboard2k On Screen Display Plugin
2
# Copyright (C) 2007  Jan Janech
2
# Copyright (C) 2007  Jan Janech
3

3

4
# This program is free software: you can redistribute it and/or modify
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
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
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
7
# (at your option) any later version.
8

8

9
# This program is distributed in the hope that it will be useful,
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
12
# GNU General Public License for more details.
13

13

14
# You should have received a copy of the GNU General Public License
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/>.
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

16

17
import os
17
import os
18
import pyosd
18
import pyosd
19

19

20
color = '#CFCF00'
20
color = '#CFCF00'
21
timeout = 3
21
timeout = 3
22
position = pyosd.POS_BOT
22
position = pyosd.POS_BOT
23
shadow = True
23
shadow = True
24
font = "-adobe-helvetica-bold-r-*-*-*-240-100-*-*-*-*-*"
24
font = "-adobe-helvetica-bold-r-*-*-*-240-100-*-*-*-*-*"
25

25

26

26

27
class Plugin:
27
class Plugin:
28
    osd = None
28
    osd = None
29
    maxlines = 1
29
    maxlines = 1
30
    
30
    
31
    options = ('text', 'type', 'linecount')
31
    options = ('text', 'type', 'linecount')
32
    stdin = 'text'
32
    stdin = 'text'
33
    
33
    
34
    @staticmethod
34
    @staticmethod
35
    def config(c = None, t = None, p = None, s = None, f = None):
35
    def config(c = None, t = None, p = None, s = None, f = None):
36
        global color, timeout, position, shadow, font
36
        global color, timeout, position, shadow, font
37
        
37
        
38
        if c:
38
        if c:
39
            color = c
39
            color = c
40
        if t:
40
        if t:
41
            timeout = t
41
            timeout = t
42
        if p:
42
        if p:
43
            position = p
43
            position = p
44
        if s:
44
        if s:
45
            shadow = s
45
            shadow = s
46
        if f:
46
        if f:
47
            font = f
47
            font = f
48
    
48
    
49
    def __init__(self, text, type = 'text', linecount = 1):
49
    def __init__(self, text, type = 'text', linecount = 1):
50
        type = type.lower()
50
        type = type.lower()
51
        linecount = int(linecount)
51
        linecount = int(linecount)
52
        
52
        
53
        assert type in ('text', 'percent')
53
        assert type in ('text', 'percent')
54
        
54
        
55
        if type == 'percent' and linecount == 1:
55
        if type == 'percent' and linecount == 1:
56
            linecount = 2
56
            linecount = 2
57
        
57
        
58
        self.text = text
58
        self.text = text
59
        self.type = type
59
        self.type = type
60
        self.linecount = linecount
60
        self.linecount = linecount
61
        if linecount > self.maxlines:
61
        if linecount > self.maxlines:
62
            self.__class__.maxlines = linecount
62
            self.__class__.maxlines = linecount
63
    
63
    
64
    def __repr__(self):
64
    def __repr__(self):
65
        return '<osd.Plugin %r %s %d>'%(self.text, self.type, self.linecount)
65
        return '<osd.Plugin %r %s %d>'%(self.text, self.type, self.linecount)
66
    
66
    
67
    def __call__(self):
67
    def __call__(self):
68
        if self.osd is None:
68
        if self.osd is None:
69
            self.__class__.osd = pyosd.osd(font=font, colour = color, timeout = timeout, pos = position, shadow = shadow, lines = self.maxlines, offset=3)
69
            self.__class__.osd = pyosd.osd(font=font, colour = color, timeout = timeout, pos = position, shadow = shadow, lines = self.maxlines, offset=3)
70
        
70
        
71
        if callable(self.text):
71
        if callable(self.text):
72
            text = str(self.text())
72
            text = str(self.text())
73
        else:
73
        else:
74
            text = str(self.text)
74
            text = str(self.text)
-
 
75
        
-
 
76
        if text is None:
-
 
77
            return
75
        
78
        
76
        if self.type == 'text':
79
        if self.type == 'text':
77
            for id, line in enumerate([""]*(self.maxlines-self.linecount)+([""]*self.linecount+text.splitlines())[-self.linecount:]):
80
            for id, line in enumerate([""]*(self.maxlines-self.linecount)+([""]*self.linecount+text.splitlines())[-self.linecount:]):
78
                self.osd.display(line, line = id)
81
                self.osd.display(line, line = id)
79
        else:
82
        else:
80
            for id in xrange(self.maxlines - 2):
83
            for id in xrange(self.maxlines - 2):
81
                self.osd.display("", line = id)
84
                self.osd.display("", line = id)
82
            s, v = (text+'\n0').splitlines()[:2]
85
            s, v = (text+'\n0').splitlines()[:2]
83
            v = int(v)
86
            v = int(v)
84
            self.osd.display("%s(%d%%)"%(s, v), line = self.maxlines - 2)
87
            self.osd.display("%s(%d%%)"%(s, v), line = self.maxlines - 2)
85
            self.osd.display(v, type = pyosd.TYPE_PERCENT, line = self.maxlines - 1)
88
            self.osd.display(v, type = pyosd.TYPE_PERCENT, line = self.maxlines - 1)