runtime/NevowServer.py
changeset 1736 7e61baa047f0
parent 1682 496029f768d9
child 1740 b789b695b5c6
equal deleted inserted replaced
1735:c02818d7e29f 1736:7e61baa047f0
    34 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    34 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    35 '''
    35 '''
    36 
    36 
    37 WorkingDir = None
    37 WorkingDir = None
    38 
    38 
       
    39 
    39 class PLCHMI(athena.LiveElement):
    40 class PLCHMI(athena.LiveElement):
    40 
    41 
    41     initialised = False
    42     initialised = False
    42 
    43 
    43     def HMIinitialised(self, result):
    44     def HMIinitialised(self, result):
    44         self.initialised = True
    45         self.initialised = True
    45 
    46 
    46     def HMIinitialisation(self):
    47     def HMIinitialisation(self):
    47         self.HMIinitialised(None)
    48         self.HMIinitialised(None)
       
    49 
    48 
    50 
    49 class DefaultPLCStartedHMI(PLCHMI):
    51 class DefaultPLCStartedHMI(PLCHMI):
    50     docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[
    52     docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[
    51                                             tags.h1["PLC IS NOW STARTED"],
    53                                             tags.h1["PLC IS NOW STARTED"],
    52                                             ])
    54                                             ])
    53 
    55 
       
    56 
    54 class PLCStoppedHMI(PLCHMI):
    57 class PLCStoppedHMI(PLCHMI):
    55     docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[
    58     docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[
    56                                             tags.h1["PLC IS STOPPED"],
    59                                             tags.h1["PLC IS STOPPED"],
    57                                             ])
    60                                             ])
       
    61 
    58 
    62 
    59 class MainPage(athena.LiveElement):
    63 class MainPage(athena.LiveElement):
    60     jsClass = u"WebInterface.PLC"
    64     jsClass = u"WebInterface.PLC"
    61     docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[
    65     docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[
    62                                                     tags.div(id='content')[
    66                                                     tags.div(id='content')[
   108 
   112 
   109     def detachFragmentChildren(self):
   113     def detachFragmentChildren(self):
   110         for child in self.liveFragmentChildren[:]:
   114         for child in self.liveFragmentChildren[:]:
   111             child.detach()
   115             child.detach()
   112 
   116 
       
   117 
   113 class WebInterface(athena.LivePage):
   118 class WebInterface(athena.LivePage):
   114 
   119 
   115     docFactory = loaders.stan([tags.raw(xhtml_header),
   120     docFactory = loaders.stan([tags.raw(xhtml_header),
   116                                 tags.html(xmlns="http://www.w3.org/1999/xhtml")[
   121                                 tags.html(xmlns="http://www.w3.org/1999/xhtml")[
   117                                     tags.head(render=tags.directive('liveglue')),
   122                                     tags.head(render=tags.directive('liveglue')),
   171     def disconnected(self, reason):
   176     def disconnected(self, reason):
   172         self.MainPage.resetHMI()
   177         self.MainPage.resetHMI()
   173         #print reason
   178         #print reason
   174         #print "We will be called back when the client disconnects"
   179         #print "We will be called back when the client disconnects"
   175 
   180 
       
   181 
   176 def RegisterWebsite(port):
   182 def RegisterWebsite(port):
   177     website = WebInterface()
   183     website = WebInterface()
   178     site = appserver.NevowSite(website)
   184     site = appserver.NevowSite(website)
   179 
   185 
   180     listening = False
   186     listening = False
   181     reactor.listenTCP(port, site)
   187     reactor.listenTCP(port, site)
   182     print _("HTTP interface port :"), port
   188     print _("HTTP interface port :"), port
   183     return website
   189     return website
       
   190 
   184 
   191 
   185 class statuslistener:
   192 class statuslistener:
   186     def __init__(self, site):
   193     def __init__(self, site):
   187         self.oldstate = None
   194         self.oldstate = None
   188         self.site = site
   195         self.site = site
   192             action = {'Started': self.site.PLCStarted,
   199             action = {'Started': self.site.PLCStarted,
   193                       'Stopped': self.site.PLCStopped}.get(state, None)
   200                       'Stopped': self.site.PLCStopped}.get(state, None)
   194             if action is not None: action ()
   201             if action is not None: action ()
   195             self.oldstate = state
   202             self.oldstate = state
   196 
   203 
       
   204 
   197 def website_statuslistener_factory(site):
   205 def website_statuslistener_factory(site):
   198     return statuslistener(site).listen
   206     return statuslistener(site).listen