runtime/NevowServer.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Wed, 31 Mar 2021 09:08:15 +0200
branchsvghmi
changeset 3214 bb314cdfc656
parent 2701 f4dac054cfa3
child 3440 3770ded5db5c
permissions -rw-r--r--
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
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
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    25
1881
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1878
diff changeset
    26
from __future__ import absolute_import
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    27
from __future__ import print_function
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    28
import os
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
    29
import collections
2247
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
    30
import platform as platform_module
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
    31
from zope.interface import implements
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
    32
from nevow import appserver, inevow, tags, loaders, athena, url, rend
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    33
from nevow.page import renderer
2266
ed415982a9aa NevowServer : Added minimalist css style customization and a link to go to settings page and back
dporopat <denis.poropat@smarteh.si>
parents: 2219
diff changeset
    34
from nevow.static import File
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
    35
from formless import annotate
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
    36
from formless import webform
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
    37
from formless import configurable
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
    38
from twisted.internet import reactor
2210
81949104291d Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents: 2209
diff changeset
    39
1919
ccea0fa6ea91 Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents: 1881
diff changeset
    40
import util.paths as paths
2210
81949104291d Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents: 2209
diff changeset
    41
from runtime.loglevels import LogLevels, LogLevelsDict
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
    42
from runtime import MainWorker, GetPLCObjectSingleton
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    43
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
    44
PAGE_TITLE = 'Beremiz Runtime Web Interface'
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
    45
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    46
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
    47
<!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
    48
"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
    49
'''
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    50
1453
f31353cac197 Fixed Nevow website startup
Edouard Tisserant
parents: 1439
diff changeset
    51
WorkingDir = None
2210
81949104291d Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents: 2209
diff changeset
    52
_PySrv = None
1453
f31353cac197 Fixed Nevow website startup
Edouard Tisserant
parents: 1439
diff changeset
    53
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1682
diff changeset
    54
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    55
class PLCHMI(athena.LiveElement):
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
    initialised = False
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    58
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    59
    def HMIinitialised(self, result):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    60
        self.initialised = True
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    61
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    62
    def HMIinitialisation(self):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    63
        self.HMIinitialised(None)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    64
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
    65
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    66
class DefaultPLCStartedHMI(PLCHMI):
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1870
diff changeset
    67
    docFactory = loaders.stan(
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1870
diff changeset
    68
        tags.div(render=tags.directive('liveElement'))[
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1870
diff changeset
    69
            tags.h1["PLC IS NOW STARTED"],
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1870
diff changeset
    70
        ])
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    71
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1682
diff changeset
    72
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    73
class PLCStoppedHMI(PLCHMI):
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1870
diff changeset
    74
    docFactory = loaders.stan(
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1870
diff changeset
    75
        tags.div(render=tags.directive('liveElement'))[
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1870
diff changeset
    76
            tags.h1["PLC IS STOPPED"],
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1870
diff changeset
    77
        ])
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    78
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1682
diff changeset
    79
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    80
class MainPage(athena.LiveElement):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    81
    jsClass = u"WebInterface.PLC"
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1870
diff changeset
    82
    docFactory = loaders.stan(
2266
ed415982a9aa NevowServer : Added minimalist css style customization and a link to go to settings page and back
dporopat <denis.poropat@smarteh.si>
parents: 2219
diff changeset
    83
        tags.invisible[
ed415982a9aa NevowServer : Added minimalist css style customization and a link to go to settings page and back
dporopat <denis.poropat@smarteh.si>
parents: 2219
diff changeset
    84
            tags.div(render=tags.directive('liveElement'))[
ed415982a9aa NevowServer : Added minimalist css style customization and a link to go to settings page and back
dporopat <denis.poropat@smarteh.si>
parents: 2219
diff changeset
    85
                tags.div(id='content')[
ed415982a9aa NevowServer : Added minimalist css style customization and a link to go to settings page and back
dporopat <denis.poropat@smarteh.si>
parents: 2219
diff changeset
    86
                    tags.div(render=tags.directive('PLCElement'))]
ed415982a9aa NevowServer : Added minimalist css style customization and a link to go to settings page and back
dporopat <denis.poropat@smarteh.si>
parents: 2219
diff changeset
    87
            ],
ed415982a9aa NevowServer : Added minimalist css style customization and a link to go to settings page and back
dporopat <denis.poropat@smarteh.si>
parents: 2219
diff changeset
    88
            tags.a(href='settings')['Settings']])
1438
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 __init__(self, *a, **kw):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    91
        athena.LiveElement.__init__(self, *a, **kw)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    92
        self.pcl_state = False
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    93
        self.HMI = None
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    94
        self.resetPLCStartedHMI()
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    95
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    96
    def setPLCState(self, state):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    97
        self.pcl_state = state
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    98
        if self.HMI is not None:
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    99
            self.callRemote('updateHMI')
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   100
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   101
    def setPLCStartedHMI(self, hmi):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   102
        self.PLCStartedHMIClass = hmi
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   103
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   104
    def resetPLCStartedHMI(self):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   105
        self.PLCStartedHMIClass = DefaultPLCStartedHMI
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   106
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   107
    def getHMI(self):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   108
        return self.HMI
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   109
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   110
    def HMIexec(self, function, *args, **kwargs):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   111
        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
   112
            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
   113
    athena.expose(HMIexec)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   114
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   115
    def resetHMI(self):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   116
        self.HMI = None
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   117
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   118
    def PLCElement(self, ctx, data):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   119
        return self.getPLCElement()
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   120
    renderer(PLCElement)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   121
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   122
    def getPLCElement(self):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   123
        self.detachFragmentChildren()
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   124
        if self.pcl_state:
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   125
            f = self.PLCStartedHMIClass()
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   126
        else:
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   127
            f = PLCStoppedHMI()
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   128
        f.setFragmentParent(self)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   129
        self.HMI = f
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   130
        return f
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   131
    athena.expose(getPLCElement)
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 detachFragmentChildren(self):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   134
        for child in self.liveFragmentChildren[:]:
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   135
            child.detach()
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   136
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   137
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   138
class ConfigurableBindings(configurable.Configurable):
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   139
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   140
    def __init__(self):
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   141
        configurable.Configurable.__init__(self, None)
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   142
        self.bindingsNames = []
2262
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   143
        self.infostringcount = 0
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   144
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   145
    def getBindingNames(self, ctx):
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   146
        return self.bindingsNames
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   147
2262
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   148
    def addInfoString(self, label, value, name=None):
2267
Edouard Tisserant
parents: 2262 2266
diff changeset
   149
        if isinstance(value, str):
2262
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   150
            def default(*k):
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   151
                return value
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   152
        else:
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   153
            def default(*k):
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   154
                return value()
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   155
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   156
        if name is None:
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   157
            name = "_infostring_" + str(self.infostringcount)
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   158
            self.infostringcount = self.infostringcount + 1
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   159
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   160
        def _bind(ctx):
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   161
            return annotate.Property(
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   162
                name,
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   163
                annotate.String(
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   164
                    label=label,
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   165
                    default=default,
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   166
                    immutable=True))
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   167
        setattr(self, 'bind_' + name, _bind)
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   168
        self.bindingsNames.append(name)
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   169
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   170
    def addSettings(self, name, desc, fields, btnlabel, callback):
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   171
        def _bind(ctx):
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   172
            return annotate.MethodBinding(
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   173
                'action_' + name,
2247
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   174
                annotate.Method(
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   175
                    arguments=[
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   176
                        annotate.Argument(*field)
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   177
                        for field in fields],
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   178
                    label=desc),
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   179
                action=btnlabel)
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   180
        setattr(self, 'bind_' + name, _bind)
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   181
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   182
        setattr(self, 'action_' + name, callback)
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   183
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   184
        self.bindingsNames.append(name)
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2649
diff changeset
   185
            
2260
74205edac761 Some blank lines to make bitbucket's PEP8 2.2.0 happy
Edouard Tisserant
parents: 2247
diff changeset
   186
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   187
ConfigurableSettings = ConfigurableBindings()
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   188
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   189
def newExtensionSetting(display, token):
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   190
    global extensions_settings_od
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   191
    settings = ConfigurableBindings()
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   192
    extensions_settings_od[token] = (settings, display)
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   193
    return settings
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   194
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   195
def removeExtensionSetting(token):
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   196
    global extensions_settings_od
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   197
    extensions_settings_od.pop(token)
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   198
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   199
class ISettings(annotate.TypedInterface):
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   200
    platform = annotate.String(label=_("Platform"),
2247
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   201
                               default=platform_module.system() +
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   202
                               " " + platform_module.release(),
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   203
                               immutable=True)
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   204
2217
a603d1ba287b Added some immutable field (platform) in default runtime web setting page, for the example.
Edouard Tisserant
parents: 2214
diff changeset
   205
    # TODO version ?
a603d1ba287b Added some immutable field (platform) in default runtime web setting page, for the example.
Edouard Tisserant
parents: 2214
diff changeset
   206
2247
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   207
    # pylint: disable=no-self-argument
2210
81949104291d Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents: 2209
diff changeset
   208
    def sendLogMessage(
2247
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   209
            ctx=annotate.Context(),
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   210
            level=annotate.Choice(LogLevels,
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   211
                                  required=True,
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   212
                                  label=_("Log message level")),
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   213
            message=annotate.String(label=_("Message text"))):
2247
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   214
        pass
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   215
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   216
    sendLogMessage = annotate.autocallable(sendLogMessage,
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   217
                                           label=_(
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   218
                                               "Send a message to the log"),
2210
81949104291d Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents: 2209
diff changeset
   219
                                           action=_("Send"))
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   220
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   221
    # pylint: disable=no-self-argument
2701
f4dac054cfa3 WebInterface: better wording for wiping PLC content: "Repair"
Edouard Tisserant
parents: 2700
diff changeset
   222
    def restartOrRepairPLC(
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   223
            ctx=annotate.Context(),
2701
f4dac054cfa3 WebInterface: better wording for wiping PLC content: "Repair"
Edouard Tisserant
parents: 2700
diff changeset
   224
            action=annotate.Choice(["Restart", "Repair"],
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   225
                                  required=True,
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   226
                                  label=_("Action"))):
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   227
        pass
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   228
2701
f4dac054cfa3 WebInterface: better wording for wiping PLC content: "Repair"
Edouard Tisserant
parents: 2700
diff changeset
   229
    restartOrRepairPLC = annotate.autocallable(restartOrRepairPLC,
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   230
                                           label=_(
2701
f4dac054cfa3 WebInterface: better wording for wiping PLC content: "Repair"
Edouard Tisserant
parents: 2700
diff changeset
   231
                                               "Restart or Repair"),
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   232
                                           action=_("Do"))
2260
74205edac761 Some blank lines to make bitbucket's PEP8 2.2.0 happy
Edouard Tisserant
parents: 2247
diff changeset
   233
2219
73042b2d8d65 Added a way for extension to register dedicated URL under settings page URL (i.e. /settings/something)
Edouard Tisserant
parents: 2217
diff changeset
   234
customSettingsURLs = {
73042b2d8d65 Added a way for extension to register dedicated URL under settings page URL (i.e. /settings/something)
Edouard Tisserant
parents: 2217
diff changeset
   235
}
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   236
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   237
extensions_settings_od = collections.OrderedDict()
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   238
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   239
class SettingsPage(rend.Page):
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   240
    # We deserve a slash
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   241
    addSlash = True
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   242
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   243
    # This makes webform_css url answer some default CSS
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   244
    child_webform_css = webform.defaultCSS
2266
ed415982a9aa NevowServer : Added minimalist css style customization and a link to go to settings page and back
dporopat <denis.poropat@smarteh.si>
parents: 2219
diff changeset
   245
    child_webinterface_css = File(paths.AbsNeighbourFile(__file__, 'webinterface.css'), 'text/css')
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   246
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   247
    implements(ISettings)
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   248
   
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   249
    def __getattr__(self, name):
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   250
        global extensions_settings_od
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   251
        if name.startswith('configurable_'):
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   252
            token = name[13:]
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   253
            def configurable_something(ctx):
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   254
                settings, _display = extensions_settings_od[token]
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   255
                return settings
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   256
            return configurable_something
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   257
        raise AttributeError
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   258
    
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   259
    def extensions_settings(self, context, data):
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   260
        """ Project extensions settings
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   261
        Extensions added to Configuration Tree in IDE have their setting rendered here
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   262
        """
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   263
        global extensions_settings_od
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   264
        res = []
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   265
        for token in extensions_settings_od:
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   266
            _settings, display = extensions_settings_od[token]
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   267
            res += [tags.h2[display], webform.renderForms(token)] 
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   268
        return res
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   269
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   270
    docFactory = loaders.stan([tags.html[
2267
Edouard Tisserant
parents: 2262 2266
diff changeset
   271
        tags.head[
Edouard Tisserant
parents: 2262 2266
diff changeset
   272
            tags.title[_("Beremiz Runtime Settings")],
Edouard Tisserant
parents: 2262 2266
diff changeset
   273
            tags.link(rel='stylesheet',
Edouard Tisserant
parents: 2262 2266
diff changeset
   274
                      type='text/css',
Edouard Tisserant
parents: 2262 2266
diff changeset
   275
                      href=url.here.child("webform_css")),
Edouard Tisserant
parents: 2262 2266
diff changeset
   276
            tags.link(rel='stylesheet',
Edouard Tisserant
parents: 2262 2266
diff changeset
   277
                      type='text/css',
Edouard Tisserant
parents: 2262 2266
diff changeset
   278
                      href=url.here.child("webinterface_css"))
Edouard Tisserant
parents: 2262 2266
diff changeset
   279
        ],
Edouard Tisserant
parents: 2262 2266
diff changeset
   280
        tags.body[
Edouard Tisserant
parents: 2262 2266
diff changeset
   281
            tags.a(href='/')['Back'],
Edouard Tisserant
parents: 2262 2266
diff changeset
   282
            tags.h1["Runtime settings:"],
Edouard Tisserant
parents: 2262 2266
diff changeset
   283
            webform.renderForms('staticSettings'),
Edouard Tisserant
parents: 2262 2266
diff changeset
   284
            tags.h1["Extensions settings:"],
Edouard Tisserant
parents: 2262 2266
diff changeset
   285
            webform.renderForms('dynamicSettings'),
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   286
            extensions_settings
2267
Edouard Tisserant
parents: 2262 2266
diff changeset
   287
        ]]])
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   288
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   289
    def configurable_staticSettings(self, ctx):
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   290
        return configurable.TypedInterfaceConfigurable(self)
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   291
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   292
    def configurable_dynamicSettings(self, ctx):
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   293
        """ Runtime Extensions settings
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   294
        Extensions loaded through Beremiz_service -e or optional runtime features render setting forms here
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   295
        """
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   296
        return ConfigurableSettings
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   297
2210
81949104291d Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents: 2209
diff changeset
   298
    def sendLogMessage(self, level, message, **kwargs):
81949104291d Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents: 2209
diff changeset
   299
        level = LogLevelsDict[level]
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   300
        GetPLCObjectSingleton().LogMessage(
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   301
            level, "Web form log message: " + message)
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   302
2701
f4dac054cfa3 WebInterface: better wording for wiping PLC content: "Repair"
Edouard Tisserant
parents: 2700
diff changeset
   303
    def restartOrRepairPLC(self, action, **kwargs):
f4dac054cfa3 WebInterface: better wording for wiping PLC content: "Repair"
Edouard Tisserant
parents: 2700
diff changeset
   304
        if(action == "Repair"):
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   305
            GetPLCObjectSingleton().RepairPLC()
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   306
        else:
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   307
            MainWorker.quit()
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   308
            
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   309
        
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   310
2219
73042b2d8d65 Added a way for extension to register dedicated URL under settings page URL (i.e. /settings/something)
Edouard Tisserant
parents: 2217
diff changeset
   311
    def locateChild(self, ctx, segments):
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   312
        if segments[0] in customSettingsURLs:
2219
73042b2d8d65 Added a way for extension to register dedicated URL under settings page URL (i.e. /settings/something)
Edouard Tisserant
parents: 2217
diff changeset
   313
            return customSettingsURLs[segments[0]](ctx, segments)
73042b2d8d65 Added a way for extension to register dedicated URL under settings page URL (i.e. /settings/something)
Edouard Tisserant
parents: 2217
diff changeset
   314
        return super(SettingsPage, self).locateChild(ctx, segments)
73042b2d8d65 Added a way for extension to register dedicated URL under settings page URL (i.e. /settings/something)
Edouard Tisserant
parents: 2217
diff changeset
   315
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1682
diff changeset
   316
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   317
class WebInterface(athena.LivePage):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   318
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   319
    docFactory = loaders.stan([tags.raw(xhtml_header),
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   320
                               tags.html(xmlns="http://www.w3.org/1999/xhtml")[
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   321
                                   tags.head(render=tags.directive('liveglue'))[
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   322
                                       tags.title[PAGE_TITLE],
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   323
                                       tags.link(rel='stylesheet',
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   324
                                                 type='text/css',
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   325
                                                 href=url.here.child("webform_css"))
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   326
                                   ],
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   327
                                   tags.body[
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   328
                                       tags.div[
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   329
                                           tags.div(
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   330
                                               render=tags.directive(
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   331
                                                   "MainPage")),
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   332
                                       ]]]])
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   333
    MainPage = MainPage()
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   334
    PLCHMI = PLCHMI
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   335
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   336
    def child_settings(self, context):
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   337
        return SettingsPage()
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   338
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   339
    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
   340
        super(WebInterface, self).__init__(*a, **kw)
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   341
        self.jsModules.mapping[u'WebInterface'] = paths.AbsNeighbourFile(
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   342
            __file__, 'webinterface.js')
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   343
        self.plcState = plcState
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   344
        self.MainPage.setPLCState(plcState)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   345
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   346
    def getHMI(self):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   347
        return self.MainPage.getHMI()
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   348
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   349
    def LoadHMI(self, hmi, jsmodules):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   350
        for name, path in jsmodules.iteritems():
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   351
            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
   352
        self.MainPage.setPLCStartedHMI(hmi)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   353
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   354
    def UnLoadHMI(self):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   355
        self.MainPage.resetPLCStartedHMI()
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   356
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   357
    def PLCStarted(self):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   358
        self.plcState = True
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   359
        self.MainPage.setPLCState(True)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   360
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   361
    def PLCStopped(self):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   362
        self.plcState = False
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   363
        self.MainPage.setPLCState(False)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   364
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   365
    def renderHTTP(self, ctx):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   366
        """
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   367
        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
   368
        """
1870
4d070115b552 fix pylint error '(too-many-function-args) Too many positional arguments for function call'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   369
        req = ctx.locate(inevow.IRequest)
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   370
        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
   371
        return super(WebInterface, self).renderHTTP(ctx)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   372
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   373
    def render_MainPage(self, ctx, data):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   374
        f = self.MainPage
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   375
        f.setFragmentParent(self)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   376
        return ctx.tag[f]
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   377
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   378
    def child_(self, ctx):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   379
        self.MainPage.detachFragmentChildren()
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   380
        return WebInterface(plcState=self.plcState)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   381
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   382
    def beforeRender(self, ctx):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   383
        d = self.notifyOnDisconnect()
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   384
        d.addErrback(self.disconnected)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   385
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   386
    def disconnected(self, reason):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   387
        self.MainPage.resetHMI()
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1776
diff changeset
   388
        # print reason
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1776
diff changeset
   389
        # print "We will be called back when the client disconnects"
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   390
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1682
diff changeset
   391
2311
bef2b4b87370 Beremiz_service now binds both pyro and nevow ports to interface given with '-i' argument.
Edouard Tisserant
parents: 2267
diff changeset
   392
def RegisterWebsite(iface, port):
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   393
    website = WebInterface()
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   394
    site = appserver.NevowSite(website)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   395
2311
bef2b4b87370 Beremiz_service now binds both pyro and nevow ports to interface given with '-i' argument.
Edouard Tisserant
parents: 2267
diff changeset
   396
    reactor.listenTCP(port, site, interface=iface)
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   397
    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
   398
    return website
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   399
2210
81949104291d Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents: 2209
diff changeset
   400
1831
56b48961cc68 fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1826
diff changeset
   401
class statuslistener(object):
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   402
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   403
    def __init__(self, site):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   404
        self.oldstate = None
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   405
        self.site = site
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   406
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   407
    def listen(self, state):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   408
        if state != self.oldstate:
1453
f31353cac197 Fixed Nevow website startup
Edouard Tisserant
parents: 1439
diff changeset
   409
            action = {'Started': self.site.PLCStarted,
f31353cac197 Fixed Nevow website startup
Edouard Tisserant
parents: 1439
diff changeset
   410
                      '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
   411
            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
   412
                action()
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   413
            self.oldstate = state
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   414
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1682
diff changeset
   415
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   416
def website_statuslistener_factory(site):
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   417
    return statuslistener(site).listen
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   418
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   419
2210
81949104291d Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents: 2209
diff changeset
   420
def SetServer(pysrv):
81949104291d Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents: 2209
diff changeset
   421
    global _PySrv
81949104291d Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents: 2209
diff changeset
   422
    _PySrv = pysrv