author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Thu, 17 Aug 2017 10:04:24 +0300 | |
changeset 1759 | 56e7f4a11046 |
parent 1756 | 08e4394ff4fb |
child 1767 | c74815729afd |
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 |
|
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
4 |
# This file is part of Beremiz runtime. |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
5 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
6 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1667
diff
changeset
|
7 |
# Copyright (C) 2017: Andrey Skvortsov |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
8 |
# |
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
9 |
# See COPYING.Runtime file for copyrights details. |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
10 |
# |
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
11 |
# This library is free software; you can redistribute it and/or |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
12 |
# modify it under the terms of the GNU Lesser General Public |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
13 |
# License as published by the Free Software Foundation; either |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
14 |
# version 2.1 of the License, or (at your option) any later version. |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
15 |
|
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
16 |
# This library is distributed in the hope that it will be useful, |
1511
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 |
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
19 |
# Lesser General Public License for more details. |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
20 |
|
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
21 |
# You should have received a copy of the GNU Lesser General Public |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
22 |
# License along with this library; if not, write to the Free Software |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1511
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 |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1667
diff
changeset
|
26 |
import util.paths as paths |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
27 |
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
|
28 |
from nevow.page import renderer |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
29 |
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
|
30 |
from twisted.internet import reactor |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
31 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
32 |
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
|
33 |
<!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
|
34 |
"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
|
35 |
''' |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
36 |
|
1453 | 37 |
WorkingDir = None |
38 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
39 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
40 |
class PLCHMI(athena.LiveElement): |
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 |
initialised = False |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
43 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
44 |
def HMIinitialised(self, result): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
45 |
self.initialised = True |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
46 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
47 |
def HMIinitialisation(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
48 |
self.HMIinitialised(None) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
49 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
50 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
51 |
class DefaultPLCStartedHMI(PLCHMI): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
52 |
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
|
53 |
tags.h1["PLC IS NOW STARTED"], |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
54 |
]) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
55 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
56 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
57 |
class PLCStoppedHMI(PLCHMI): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
58 |
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
|
59 |
tags.h1["PLC IS STOPPED"], |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
60 |
]) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
61 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
62 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
63 |
class MainPage(athena.LiveElement): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
64 |
jsClass = u"WebInterface.PLC" |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
65 |
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
|
66 |
tags.div(id='content')[ |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
67 |
tags.div(render=tags.directive('PLCElement')), |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
68 |
]]) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
69 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
70 |
def __init__(self, *a, **kw): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
71 |
athena.LiveElement.__init__(self, *a, **kw) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
72 |
self.pcl_state = False |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
73 |
self.HMI = None |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
74 |
self.resetPLCStartedHMI() |
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 setPLCState(self, state): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
77 |
self.pcl_state = state |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
78 |
if self.HMI is not None: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
79 |
self.callRemote('updateHMI') |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
80 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
81 |
def setPLCStartedHMI(self, hmi): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
82 |
self.PLCStartedHMIClass = hmi |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
83 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
84 |
def resetPLCStartedHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
85 |
self.PLCStartedHMIClass = DefaultPLCStartedHMI |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
86 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
87 |
def getHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
88 |
return self.HMI |
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 HMIexec(self, function, *args, **kwargs): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
91 |
if self.HMI is not None: |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
92 |
getattr(self.HMI, function, lambda: None)(*args, **kwargs) |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
93 |
athena.expose(HMIexec) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
94 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
95 |
def resetHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
96 |
self.HMI = None |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
97 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
98 |
def PLCElement(self, ctx, data): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
99 |
return self.getPLCElement() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
100 |
renderer(PLCElement) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
101 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
102 |
def getPLCElement(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
103 |
self.detachFragmentChildren() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
104 |
if self.pcl_state: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
105 |
f = self.PLCStartedHMIClass() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
106 |
else: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
107 |
f = PLCStoppedHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
108 |
f.setFragmentParent(self) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
109 |
self.HMI = f |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
110 |
return f |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
111 |
athena.expose(getPLCElement) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
112 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
113 |
def detachFragmentChildren(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
114 |
for child in self.liveFragmentChildren[:]: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
115 |
child.detach() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
116 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
117 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
118 |
class WebInterface(athena.LivePage): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
119 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
120 |
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
|
121 |
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
|
122 |
tags.head(render=tags.directive('liveglue')), |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
123 |
tags.body[ |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
124 |
tags.div[ |
1746
45d6f5fba016
clean-up: fix PEP8 E202 whitespace before ')'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
125 |
tags.div(render=tags.directive("MainPage")) |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
126 |
]]]]) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
127 |
MainPage = MainPage() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
128 |
PLCHMI = PLCHMI |
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 __init__(self, plcState=False, *a, **kw): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
131 |
super(WebInterface, self).__init__(*a, **kw) |
1682 | 132 |
self.jsModules.mapping[u'WebInterface'] = paths.AbsNeighbourFile(__file__, 'webinterface.js') |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
133 |
self.plcState = plcState |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
134 |
self.MainPage.setPLCState(plcState) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
135 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
136 |
def getHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
137 |
return self.MainPage.getHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
138 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
139 |
def LoadHMI(self, hmi, jsmodules): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
140 |
for name, path in jsmodules.iteritems(): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
141 |
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
|
142 |
self.MainPage.setPLCStartedHMI(hmi) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
143 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
144 |
def UnLoadHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
145 |
self.MainPage.resetPLCStartedHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
146 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
147 |
def PLCStarted(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
148 |
self.plcState = True |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
149 |
self.MainPage.setPLCState(True) |
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 |
def PLCStopped(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
152 |
self.plcState = False |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
153 |
self.MainPage.setPLCState(False) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
154 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
155 |
def renderHTTP(self, 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 |
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
|
158 |
""" |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
159 |
req = inevow.IRequest(ctx) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
160 |
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
|
161 |
return super(WebInterface, self).renderHTTP(ctx) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
162 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
163 |
def render_MainPage(self, ctx, data): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
164 |
f = self.MainPage |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
165 |
f.setFragmentParent(self) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
166 |
return ctx.tag[f] |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
167 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
168 |
def child_(self, ctx): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
169 |
self.MainPage.detachFragmentChildren() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
170 |
return WebInterface(plcState=self.plcState) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
171 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
172 |
def beforeRender(self, ctx): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
173 |
d = self.notifyOnDisconnect() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
174 |
d.addErrback(self.disconnected) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
175 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
176 |
def disconnected(self, reason): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
177 |
self.MainPage.resetHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
178 |
#print reason |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
179 |
#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
|
180 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
181 |
|
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
|
182 |
def RegisterWebsite(port): |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
183 |
website = WebInterface() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
184 |
site = appserver.NevowSite(website) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
185 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
186 |
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
|
187 |
reactor.listenTCP(port, site) |
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
188 |
print _("HTTP interface port :"), port |
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
|
189 |
return website |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
190 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
191 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
192 |
class statuslistener: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
193 |
def __init__(self, site): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
194 |
self.oldstate = None |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
195 |
self.site = site |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
196 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
197 |
def listen(self, state): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
198 |
if state != self.oldstate: |
1453 | 199 |
action = {'Started': self.site.PLCStarted, |
200 |
'Stopped': self.site.PLCStopped}.get(state, None) |
|
1756
08e4394ff4fb
clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1746
diff
changeset
|
201 |
if action is not None: |
08e4394ff4fb
clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1746
diff
changeset
|
202 |
action() |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
203 |
self.oldstate = state |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
204 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
205 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
206 |
def website_statuslistener_factory(site): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
207 |
return statuslistener(site).listen |