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
|
from gettext import gettext as _
import gtk
import pango
from utilities import Utilities
class BroadcastProcess():
"""Broadcast process component
"""
# utilities
_utilities = None
# process details
_programName = "x11vnc"
_args = ["-viewonly", "-shared", "-bg", "-forever", "-solid", "-wireframe"]
def __init__(self):
"""Constructor
"""
self._utilities = Utilities()
def getStatus(self):
"""get current status of the vnc process
"""
st = self._utilities.checkProgramStatus(self._programName)
return st[0]
def changeStatus(self):
"""change current status of the vnc proces
"""
if self.getStatus():
self._utilities.endProgram(self._programName)
else:
self._utilities.startProgram(self._programName,self._args)
def getProcessInfo(self):
return self._utilities.getNetworkProcessInfo(self._programName)
class BroadcastUI():
"""Broadcast UI component for Classroom Kit Activity
"""
# Constants
_greenColor = '#00E500'
_redColor = '#FF0000'
# I18N
_START = _('Start')
_STOP = _('Stop')
# UI elements
_box = None
_button = None
_label = None
_toolbar = None
_boxAlign = None
# activity, process
_activity = None
_process = None
def __init__(self, activity, process):
"""Constructor
"""
self._activity = activity
self._process = process
def loadUI(self):
"""Create and show UI
"""
# Box
self._box = gtk.VBox()
# Label
self._label = gtk.Label()
# Button
self._button = gtk.Button()
self._button.set_size_request(200, 50)
self._button.connect("clicked", self.buttonClicked)
# Add button to box
self._box.pack_start(self._button)
# Add label to box
self._box.pack_start(self._label, padding=20)
# Box Align (xalign, yalign, xscale, yscale)
self._boxAlign = gtk.Alignment(0.5, 0.5, 0, 0)
self._boxAlign.add(self._box)
# Set canvas with box alignment
self._activity.set_canvas(self._boxAlign)
def setButtonBG(self, color):
"""Change button bg color
"""
self._button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
def setButtonLabel(self, txt):
"""Change button label
"""
self._button.set_label(txt)
def buttonClicked(self, widget, data=None):
"""Button clicked event handler
"""
self._process.changeStatus()
self.showStatus()
def setLabelTXT(self, txt):
"""Change label text
"""
self._label.set_label(txt)
def showStatus(self):
"""Show VNC status
"""
state = self._process.getStatus()
if not state:
self.setButtonBG(self._greenColor)
self.setButtonLabel(self._START)
self.setLabelTXT("")
else:
self.setButtonBG(self._redColor)
self.setButtonLabel(self._STOP)
self.setLabelTXT(self._process.getProcessInfo())
class Broadcast():
"""Broadcast component for Classroom Kit Activity
"""
_activity = None
_process = None
_ui = None
def __init__(self,activity):
"""Constructor
"""
self._activity = activity
self._process = BroadcastProcess()
self._ui = BroadcastUI(self._activity, self._process)
def loadUI(self):
"""Load UI
"""
self._ui.loadUI()
def showStatus(self):
"""Show broadcast status
"""
self._ui.showStatus()
|