summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/msg_osd.py
blob: 669a7962a41ff9eff8a21df555052e0599070420 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/python2
# other modules

import sys, string
import aosd
import ConfigParser
import getopt


# =================================


class msg():
    def scroll(self,osd, width, height, display_time,position):
        pos = position
        step = 1

        osd.set_position(pos, width, height)
        (x, y, _, _) = osd.get_geometry()
        osd.set_position_offset(width, height)
        osd.show()

        x -= 1
        y += height - 1;
        for i in range(1, height + 1, step):
            osd.loop_for(5)
            y -= step
            osd.set_geometry(x, y, width, i)

        osd.set_position(pos, width, height)
        osd.set_position_offset(-1, -1)
        (x, y, _, _) = osd.get_geometry()
    #time to display
        osd.loop_for(display_time)

        for i in range(height, 0, -step):
            y += step
            osd.set_geometry(x, y, width, i);
            osd.loop_for(1);

        osd.hide();

    def setup(self,font_color,font_type):
        osd = aosd.AosdText()
        osd.set_transparency(aosd.TRANSPARENCY_COMPOSITE)
        if osd.get_transparency() != aosd.TRANSPARENCY_COMPOSITE:
            osd.set_transparency(aosd.TRANSPARENCY_NONE)

        osd.geom_x_offset = 10
        osd.geom_y_offset = 0

        osd.back_color = "white"
        osd.back_opacity = 50

        osd.shadow_color = "black"
        osd.shadow_opacity = 127
        osd.shadow_x_offset = 2
        osd.shadow_y_offset = 2

        osd.fore_color = font_color
        osd.fore_opacity = 255

        osd.set_font(font_type)
        osd.wrap = aosd.PANGO_WRAP_WORD_CHAR
        osd.alignment = aosd.PANGO_ALIGN_LEFT
        osd.set_layout_width(osd.get_screen_wrap_width())
        return osd

    def set_string(self, osd, text):
        osd.set_text(text)
        return osd.get_text_size()

    def setup_config(self):
        module_config = ConfigParser.RawConfigParser()
        try:
            module_config.read('/usr/MythVantage/etc/msg.cfg')
        except:
            pass
        return module_config



    def display (self,flags):
        """
        parse the msg for display.
        """
        try:
            text,config_section=flags.split("|")
            if config_section == '':
                config_section="default"
        except:
            text=flags
            config_section="default"

        module_config = self.setup_config()

        display_time=5000
        position=6
        font_color="green"
        font_type="Times New Roman Italic 36"
        try:
            display_time =  int(module_config.get(config_section,"display_time"))
        except:
            pass
        try:
            position =  int(module_config.get(config_section,"position"))
        except:
            pass
        try:
            font_color = module_config.get(config_section,"font_color")
        except:
            pass
        try:
            font_type =  module_config.get(config_section,"font_type")
        except:
            pass

        #this bit of code converts a \n to EOL/BREAK
        textline=text.split('\\n')
        try:
            textline.remove(' ')
        except:
            pass
        text=chr(10).join(textline)

        #cmd = sub_process.Popen("/usr/bin/wall %s" % text,stdout=sub_process.PIPE,shell=True)
        #data = cmd.communicate()[0]
        osd = self.setup(font_color, font_type)
        width, height = self.set_string(osd, text)
        self.scroll(osd, width, height, display_time, position)

        return ("Message delivered")




def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hm:", ["help", "msg="])
    except getopt.GetoptError, err:
        # print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    in_msg = None

    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in ("-m", "--msg"):
            in_msg = a
        else:
            assert False, "unhandled option"
    txt_msg=in_msg
    out_msg=msg()

    out_msg.display(txt_msg)

if __name__ == "__main__":
    main()