34 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
34 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
35 ''' |
35 ''' |
36 |
36 |
37 WorkingDir = None |
37 WorkingDir = None |
38 |
38 |
|
39 |
39 class PLCHMI(athena.LiveElement): |
40 class PLCHMI(athena.LiveElement): |
40 |
41 |
41 initialised = False |
42 initialised = False |
42 |
43 |
43 def HMIinitialised(self, result): |
44 def HMIinitialised(self, result): |
44 self.initialised = True |
45 self.initialised = True |
45 |
46 |
46 def HMIinitialisation(self): |
47 def HMIinitialisation(self): |
47 self.HMIinitialised(None) |
48 self.HMIinitialised(None) |
|
49 |
48 |
50 |
49 class DefaultPLCStartedHMI(PLCHMI): |
51 class DefaultPLCStartedHMI(PLCHMI): |
50 docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
52 docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
51 tags.h1["PLC IS NOW STARTED"], |
53 tags.h1["PLC IS NOW STARTED"], |
52 ]) |
54 ]) |
53 |
55 |
|
56 |
54 class PLCStoppedHMI(PLCHMI): |
57 class PLCStoppedHMI(PLCHMI): |
55 docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
58 docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
56 tags.h1["PLC IS STOPPED"], |
59 tags.h1["PLC IS STOPPED"], |
57 ]) |
60 ]) |
58 |
61 |
|
62 |
59 class MainPage(athena.LiveElement): |
63 class MainPage(athena.LiveElement): |
60 jsClass = u"WebInterface.PLC" |
64 jsClass = u"WebInterface.PLC" |
61 docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
65 docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
62 tags.div(id='content')[ |
66 tags.div(id='content')[ |
63 tags.div(render = tags.directive('PLCElement')), |
67 tags.div(render=tags.directive('PLCElement')), |
64 ]]) |
68 ]]) |
65 |
69 |
66 def __init__(self, *a, **kw): |
70 def __init__(self, *a, **kw): |
67 athena.LiveElement.__init__(self, *a, **kw) |
71 athena.LiveElement.__init__(self, *a, **kw) |
68 self.pcl_state = False |
72 self.pcl_state = False |
83 def getHMI(self): |
87 def getHMI(self): |
84 return self.HMI |
88 return self.HMI |
85 |
89 |
86 def HMIexec(self, function, *args, **kwargs): |
90 def HMIexec(self, function, *args, **kwargs): |
87 if self.HMI is not None: |
91 if self.HMI is not None: |
88 getattr(self.HMI, function, lambda:None)(*args, **kwargs) |
92 getattr(self.HMI, function, lambda: None)(*args, **kwargs) |
89 athena.expose(HMIexec) |
93 athena.expose(HMIexec) |
90 |
94 |
91 def resetHMI(self): |
95 def resetHMI(self): |
92 self.HMI = None |
96 self.HMI = None |
93 |
97 |
108 |
112 |
109 def detachFragmentChildren(self): |
113 def detachFragmentChildren(self): |
110 for child in self.liveFragmentChildren[:]: |
114 for child in self.liveFragmentChildren[:]: |
111 child.detach() |
115 child.detach() |
112 |
116 |
|
117 |
113 class WebInterface(athena.LivePage): |
118 class WebInterface(athena.LivePage): |
114 |
119 |
115 docFactory = loaders.stan([tags.raw(xhtml_header), |
120 docFactory = loaders.stan([tags.raw(xhtml_header), |
116 tags.html(xmlns="http://www.w3.org/1999/xhtml")[ |
121 tags.html(xmlns="http://www.w3.org/1999/xhtml")[ |
117 tags.head(render=tags.directive('liveglue')), |
122 tags.head(render=tags.directive('liveglue')), |
118 tags.body[ |
123 tags.body[ |
119 tags.div[ |
124 tags.div[ |
120 tags.div( render = tags.directive( "MainPage" )) |
125 tags.div(render=tags.directive("MainPage")) |
121 ]]]]) |
126 ]]]]) |
122 MainPage = MainPage() |
127 MainPage = MainPage() |
123 PLCHMI = PLCHMI |
128 PLCHMI = PLCHMI |
124 |
129 |
125 def __init__(self, plcState=False, *a, **kw): |
130 def __init__(self, plcState=False, *a, **kw): |
126 super(WebInterface, self).__init__(*a, **kw) |
131 super(WebInterface, self).__init__(*a, **kw) |
168 d = self.notifyOnDisconnect() |
173 d = self.notifyOnDisconnect() |
169 d.addErrback(self.disconnected) |
174 d.addErrback(self.disconnected) |
170 |
175 |
171 def disconnected(self, reason): |
176 def disconnected(self, reason): |
172 self.MainPage.resetHMI() |
177 self.MainPage.resetHMI() |
173 #print reason |
178 # print reason |
174 #print "We will be called back when the client disconnects" |
179 # print "We will be called back when the client disconnects" |
|
180 |
175 |
181 |
176 def RegisterWebsite(port): |
182 def RegisterWebsite(port): |
177 website = WebInterface() |
183 website = WebInterface() |
178 site = appserver.NevowSite(website) |
184 site = appserver.NevowSite(website) |
179 |
185 |
180 listening = False |
186 listening = False |
181 reactor.listenTCP(port, site) |
187 reactor.listenTCP(port, site) |
182 print _("HTTP interface port :"), port |
188 print _("HTTP interface port :"), port |
183 return website |
189 return website |
184 |
190 |
|
191 |
185 class statuslistener: |
192 class statuslistener: |
186 def __init__(self, site): |
193 def __init__(self, site): |
187 self.oldstate = None |
194 self.oldstate = None |
188 self.site = site |
195 self.site = site |
189 |
196 |
190 def listen(self, state): |
197 def listen(self, state): |
191 if state != self.oldstate: |
198 if state != self.oldstate: |
192 action = {'Started': self.site.PLCStarted, |
199 action = {'Started': self.site.PLCStarted, |
193 'Stopped': self.site.PLCStopped}.get(state, None) |
200 'Stopped': self.site.PLCStopped}.get(state, None) |
194 if action is not None: action () |
201 if action is not None: |
|
202 action() |
195 self.oldstate = state |
203 self.oldstate = state |
|
204 |
196 |
205 |
197 def website_statuslistener_factory(site): |
206 def website_statuslistener_factory(site): |
198 return statuslistener(site).listen |
207 return statuslistener(site).listen |