author | Paul Beltyukov |
Thu, 18 Aug 2016 14:35:03 +0500 | |
changeset 1517 | 30692ab8b5c7 |
parent 1511 | 91538d0c242c |
child 1595 | b3cc68dd037d |
permissions | -rw-r--r-- |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
1 |
#!/usr/bin/env python |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
3 |
|
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
6 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
8 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
10 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
15 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
19 |
# GNU General Public License for more details. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
20 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
24 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
25 |
import os |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
26 |
from nevow import rend, appserver, inevow, tags, loaders, athena |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
27 |
from nevow.page import renderer |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
28 |
from twisted.python import util |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
29 |
from twisted.internet import reactor |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
30 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
31 |
xhtml_header = '''<?xml version="1.0" encoding="utf-8"?> |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
32 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
33 |
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
34 |
''' |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
35 |
|
1453 | 36 |
WorkingDir = None |
37 |
||
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
38 |
class PLCHMI(athena.LiveElement): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
39 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
40 |
initialised = False |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
41 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
42 |
def HMIinitialised(self, result): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
43 |
self.initialised = True |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
44 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
45 |
def HMIinitialisation(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
46 |
self.HMIinitialised(None) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
47 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
48 |
class DefaultPLCStartedHMI(PLCHMI): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
49 |
docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
50 |
tags.h1["PLC IS NOW STARTED"], |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
51 |
]) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
52 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
53 |
class PLCStoppedHMI(PLCHMI): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
54 |
docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
55 |
tags.h1["PLC IS STOPPED"], |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
56 |
]) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
57 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
58 |
class MainPage(athena.LiveElement): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
59 |
jsClass = u"WebInterface.PLC" |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
60 |
docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
61 |
tags.div(id='content')[ |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
62 |
tags.div(render = tags.directive('PLCElement')), |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
63 |
]]) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
64 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
65 |
def __init__(self, *a, **kw): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
66 |
athena.LiveElement.__init__(self, *a, **kw) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
67 |
self.pcl_state = False |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
68 |
self.HMI = None |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
69 |
self.resetPLCStartedHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
70 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
71 |
def setPLCState(self, state): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
72 |
self.pcl_state = state |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
73 |
if self.HMI is not None: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
74 |
self.callRemote('updateHMI') |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
75 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
76 |
def setPLCStartedHMI(self, hmi): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
77 |
self.PLCStartedHMIClass = hmi |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
78 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
79 |
def resetPLCStartedHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
80 |
self.PLCStartedHMIClass = DefaultPLCStartedHMI |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
81 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
82 |
def getHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
83 |
return self.HMI |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
84 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
85 |
def HMIexec(self, function, *args, **kwargs): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
86 |
if self.HMI is not None: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
87 |
getattr(self.HMI, function, lambda:None)(*args, **kwargs) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
88 |
athena.expose(HMIexec) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
89 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
90 |
def resetHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
91 |
self.HMI = None |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
92 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
93 |
def PLCElement(self, ctx, data): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
94 |
return self.getPLCElement() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
95 |
renderer(PLCElement) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
96 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
97 |
def getPLCElement(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
98 |
self.detachFragmentChildren() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
99 |
if self.pcl_state: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
100 |
f = self.PLCStartedHMIClass() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
101 |
else: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
102 |
f = PLCStoppedHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
103 |
f.setFragmentParent(self) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
104 |
self.HMI = f |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
105 |
return f |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
106 |
athena.expose(getPLCElement) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
107 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
108 |
def detachFragmentChildren(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
109 |
for child in self.liveFragmentChildren[:]: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
110 |
child.detach() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
111 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
112 |
class WebInterface(athena.LivePage): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
113 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
114 |
docFactory = loaders.stan([tags.raw(xhtml_header), |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
115 |
tags.html(xmlns="http://www.w3.org/1999/xhtml")[ |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
116 |
tags.head(render=tags.directive('liveglue')), |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
117 |
tags.body[ |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
118 |
tags.div[ |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
119 |
tags.div( render = tags.directive( "MainPage" )) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
120 |
]]]]) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
121 |
MainPage = MainPage() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
122 |
PLCHMI = PLCHMI |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
123 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
124 |
def __init__(self, plcState=False, *a, **kw): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
125 |
super(WebInterface, self).__init__(*a, **kw) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
126 |
self.jsModules.mapping[u'WebInterface'] = util.sibpath(__file__, 'webinterface.js') |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
127 |
self.plcState = plcState |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
128 |
self.MainPage.setPLCState(plcState) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
129 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
130 |
def getHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
131 |
return self.MainPage.getHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
132 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
133 |
def LoadHMI(self, hmi, jsmodules): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
134 |
for name, path in jsmodules.iteritems(): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
135 |
self.jsModules.mapping[name] = os.path.join(WorkingDir, path) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
136 |
self.MainPage.setPLCStartedHMI(hmi) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
137 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
138 |
def UnLoadHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
139 |
self.MainPage.resetPLCStartedHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
140 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
141 |
def PLCStarted(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
142 |
self.plcState = True |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
143 |
self.MainPage.setPLCState(True) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
144 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
145 |
def PLCStopped(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
146 |
self.plcState = False |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
147 |
self.MainPage.setPLCState(False) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
148 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
149 |
def renderHTTP(self, ctx): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
150 |
""" |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
151 |
Force content type to fit with SVG |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
152 |
""" |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
153 |
req = inevow.IRequest(ctx) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
154 |
req.setHeader('Content-type', 'application/xhtml+xml') |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
155 |
return super(WebInterface, self).renderHTTP(ctx) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
156 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
157 |
def render_MainPage(self, ctx, data): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
158 |
f = self.MainPage |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
159 |
f.setFragmentParent(self) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
160 |
return ctx.tag[f] |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
161 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
162 |
def child_(self, ctx): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
163 |
self.MainPage.detachFragmentChildren() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
164 |
return WebInterface(plcState=self.plcState) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
165 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
166 |
def beforeRender(self, ctx): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
167 |
d = self.notifyOnDisconnect() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
168 |
d.addErrback(self.disconnected) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
169 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
170 |
def disconnected(self, reason): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
171 |
self.MainPage.resetHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
172 |
#print reason |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
173 |
#print "We will be called back when the client disconnects" |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
174 |
|
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
175 |
def RegisterWebsite(port): |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
176 |
website = WebInterface() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
177 |
site = appserver.NevowSite(website) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
178 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
179 |
listening = False |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
180 |
reactor.listenTCP(port, site) |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
181 |
print "Http interface port :",port |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
182 |
return website |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
183 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
184 |
class statuslistener: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
185 |
def __init__(self, site): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
186 |
self.oldstate = None |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
187 |
self.site = site |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
188 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
189 |
def listen(self, state): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
190 |
if state != self.oldstate: |
1453 | 191 |
action = {'Started': self.site.PLCStarted, |
192 |
'Stopped': self.site.PLCStopped}.get(state, None) |
|
193 |
if action is not None: action () |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
194 |
self.oldstate = state |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
195 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
196 |
def website_statuslistener_factory(site): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
197 |
return statuslistener(site).listen |