beremiz

f6a4c9059ca8
Parents 4ec9bb061271
Children 44890ce0ac93
Python runtime: drop Nevow/Athena based web interface landing page
--- a/Beremiz_service.py Tue Feb 18 16:22:54 2025 +0100
+++ b/Beremiz_service.py Thu Feb 20 12:00:17 2025 +0100
@@ -570,7 +570,6 @@
try:
website = NS.RegisterWebsite(interface, webport)
pyruntimevars["website"] = website
- statuschange.append(NS.website_statuslistener_factory(website))
except Exception:
LogMessageAndException(_("Nevow Web service failed. "))
--- a/runtime/NevowServer.py Tue Feb 18 16:22:54 2025 +0100
+++ b/runtime/NevowServer.py Thu Feb 20 12:00:17 2025 +0100
@@ -51,89 +51,6 @@
WorkingDir = None
-class PLCHMI(athena.LiveElement):
-
- initialised = False
-
- def HMIinitialised(self, result):
- self.initialised = True
-
- def HMIinitialisation(self):
- self.HMIinitialised(None)
-
-
-class DefaultPLCStartedHMI(PLCHMI):
- docFactory = loaders.stan(
- tags.div(render=tags.directive('liveElement'))[
- tags.h1["PLC IS NOW STARTED"],
- ])
-
-
-class PLCStoppedHMI(PLCHMI):
- docFactory = loaders.stan(
- tags.div(render=tags.directive('liveElement'))[
- tags.h1["PLC IS STOPPED"],
- ])
-
-
-class MainPage(athena.LiveElement):
- jsClass = u"WebInterface.PLC"
- docFactory = loaders.stan(
- tags.invisible[
- tags.div(render=tags.directive('liveElement'))[
- tags.div(id='content')[
- tags.div(render=tags.directive('PLCElement'))]
- ],
- tags.a(href='settings')['Settings']])
-
- def __init__(self, *a, **kw):
- athena.LiveElement.__init__(self, *a, **kw)
- self.pcl_state = False
- self.HMI = None
- self.resetPLCStartedHMI()
-
- def setPLCState(self, state):
- self.pcl_state = state
- if self.HMI is not None:
- self.callRemote('updateHMI')
-
- def setPLCStartedHMI(self, hmi):
- self.PLCStartedHMIClass = hmi
-
- def resetPLCStartedHMI(self):
- self.PLCStartedHMIClass = DefaultPLCStartedHMI
-
- def getHMI(self):
- return self.HMI
-
- def HMIexec(self, function, *args, **kwargs):
- if self.HMI is not None:
- getattr(self.HMI, function, lambda: None)(*args, **kwargs)
- athena.expose(HMIexec)
-
- def resetHMI(self):
- self.HMI = None
-
- def PLCElement(self, ctx, data):
- return self.getPLCElement()
- renderer(PLCElement)
-
- def getPLCElement(self):
- self.detachFragmentChildren()
- if self.pcl_state:
- f = self.PLCStartedHMIClass()
- else:
- f = PLCStoppedHMI()
- f.setFragmentParent(self)
- self.HMI = f
- return f
- athena.expose(getPLCElement)
-
- def detachFragmentChildren(self):
- for child in self.liveFragmentChildren[:]:
- child.detach()
-
-
class ConfigurableBindings(configurable.Configurable):
def __init__(self):
@@ -380,83 +297,23 @@
return res
return super(ExtensionSettingsPage, self).locateChild(ctx, segments)
-class WebInterface(athena.LivePage):
- docFactory = loaders.stan([tags.raw(xhtml_header),
- tags.html(xmlns="http://www.w3.org/1999/xhtml")[
- tags.head(render=tags.directive('liveglue'))[
- tags.title[PAGE_TITLE],
- tags.link(rel='stylesheet',
- type='text/css',
- href=url.here.child("webform_css"))
- ],
- tags.body[
- tags.div[
- tags.div(
- render=tags.directive(
- "MainPage")),
- ]]]])
- MainPage = MainPage()
- PLCHMI = PLCHMI
+class LandingPage(rend.Page):
+ addSlash = True
+ docFactory = loaders.stan(
+ tags.html[
+ tags.head[tags.title[PAGE_TITLE]],
+ tags.body[
+ tags.a(href="settings")["Access Settings"]
+ ]
+ ]
+ )
def child_settings(self, context):
return SettingsPage()
- def __init__(self, plcState=False, *a, **kw):
- super(WebInterface, self).__init__(*a, **kw)
- self.jsModules.mapping[u'WebInterface'] = paths.AbsNeighbourFile(
- __file__, 'webinterface.js')
- self.plcState = plcState
- self.MainPage.setPLCState(plcState)
-
- def getHMI(self):
- return self.MainPage.getHMI()
-
- def LoadHMI(self, hmi, jsmodules):
- for name, path in jsmodules.iteritems():
- self.jsModules.mapping[name] = os.path.join(WorkingDir, path)
- self.MainPage.setPLCStartedHMI(hmi)
-
- def UnLoadHMI(self):
- self.MainPage.resetPLCStartedHMI()
-
- def PLCStarted(self):
- self.plcState = True
- self.MainPage.setPLCState(True)
-
- def PLCStopped(self):
- self.plcState = False
- self.MainPage.setPLCState(False)
-
- def renderHTTP(self, ctx):
- """
- Force content type to fit with SVG
- """
- req = ctx.locate(inevow.IRequest)
- req.setHeader('Content-type', 'application/xhtml+xml')
- return super(WebInterface, self).renderHTTP(ctx)
-
- def render_MainPage(self, ctx, data):
- f = self.MainPage
- f.setFragmentParent(self)
- return ctx.tag[f]
-
- def child_(self, ctx):
- self.MainPage.detachFragmentChildren()
- return WebInterface(plcState=self.plcState)
-
- def beforeRender(self, ctx):
- d = self.notifyOnDisconnect()
- d.addErrback(self.disconnected)
-
- def disconnected(self, reason):
- self.MainPage.resetHMI()
- # print reason
- # print "We will be called back when the client disconnects"
-
-
def RegisterWebsite(iface, port):
- website = WebInterface()
+ website = LandingPage()
site = appserver.NevowSite(website)
reactor.listenTCP(port, site, interface=iface)
@@ -464,22 +321,3 @@
return website
-class statuslistener(object):
-
- def __init__(self, site):
- self.oldstate = None
- self.site = site
-
- def listen(self, state):
- if state != self.oldstate:
- action = {'Started': self.site.PLCStarted,
- 'Stopped': self.site.PLCStopped}.get(state, None)
- if action is not None:
- action()
- self.oldstate = state
-
-
-def website_statuslistener_factory(site):
- return statuslistener(site).listen
-
-