svghmi/svghmi.py
changeset 3817 3deeda82636a
parent 3750 f62625418bff
child 3863 b076f52bd1c8
equal deleted inserted replaced
3816:032bf4f225d0 3817:3deeda82636a
   425         self.ProgressStart("inkscape", "collecting SVG geometry (Inkscape)")
   425         self.ProgressStart("inkscape", "collecting SVG geometry (Inkscape)")
   426         # invoke inskscape -S, csv-parse output, produce elements
   426         # invoke inskscape -S, csv-parse output, produce elements
   427         InkscapeGeomColumns = ["Id", "x", "y", "w", "h"]
   427         InkscapeGeomColumns = ["Id", "x", "y", "w", "h"]
   428 
   428 
   429         inkpath = get_inkscape_path()
   429         inkpath = get_inkscape_path()
   430 
       
   431         if inkpath is None:
   430         if inkpath is None:
   432             self.FatalError("SVGHMI: inkscape is not installed.")
   431             self.FatalError("SVGHMI: inkscape is not installed.")
   433 
   432 
   434         svgpath = self._getSVGpath()
   433         svgpath = self._getSVGpath()
   435         status, result, _err_result = ProcessLogger(self.GetCTRoot().logger,
   434         status, result, _err_result = ProcessLogger(self.GetCTRoot().logger,
   436                                                      '"' + inkpath + '" -S "' + svgpath + '"',
   435                                                      [inkpath, '-S', svgpath],
   437                                                      no_stdout=True,
   436                                                      no_stdout=True,
   438                                                      no_stderr=True).spin()
   437                                                      no_stderr=True).spin()
   439         if status != 0:
   438         if status != 0:
   440             self.FatalError("SVGHMI: inkscape couldn't extract geometry from given SVG.")
   439             self.FatalError("SVGHMI: inkscape couldn't extract geometry from given SVG.")
   441 
   440 
   609 
   608 
   610                 # print(str(result))
   609                 # print(str(result))
   611                 # print(transform.xslt.error_log)
   610                 # print(transform.xslt.error_log)
   612                 # print(etree.tostring(result.xslt_profile,pretty_print=True))
   611                 # print(etree.tostring(result.xslt_profile,pretty_print=True))
   613 
   612 
   614                 with open(hash_path, 'wb') as digest_file:
   613                 with open(hash_path, 'w') as digest_file:
   615                     digest_file.write(digest)
   614                     digest_file.write(digest)
   616             else:
   615             else:
   617                 self.GetCTRoot().logger.write("    No changes - XSLT transformation skipped\n")
   616                 self.GetCTRoot().logger.write("    No changes - XSLT transformation skipped\n")
   618 
   617 
   619         else:
   618         else:
   675     else:
   674     else:
   676         svghmi_root = Resource()
   675         svghmi_root = Resource()
   677         factory = HMIWebSocketServerFactory()
   676         factory = HMIWebSocketServerFactory()
   678         factory.setProtocolOptions(maxConnections={maxConnections})
   677         factory.setProtocolOptions(maxConnections={maxConnections})
   679 
   678 
   680         svghmi_root.putChild("ws", WebSocketResource(factory))
   679         svghmi_root.putChild(b"ws", WebSocketResource(factory))
   681 
   680 
   682         svghmi_listener = reactor.listenTCP({port}, Site(svghmi_root), interface='{interface}')
   681         svghmi_listener = reactor.listenTCP({port}, Site(svghmi_root), interface='{interface}')
   683         path_list = []
   682         path_list = []
   684         svghmi_servers["{interface}:{port}"] = (svghmi_root, svghmi_listener, path_list)
   683         svghmi_servers["{interface}:{port}"] = (svghmi_root, svghmi_listener, path_list)
   685 
   684 
   686     svghmi_root.putChild(
   685     svghmi_root.putChild(
   687         '{path}',
   686         b'{path}',
   688         NoCacheFile('{xhtml}',
   687         NoCacheFile('{xhtml}',
   689             defaultType='application/xhtml+xml'))
   688             defaultType='application/xhtml+xml'))
   690 
   689 
   691     path_list.append("{path}")
   690     path_list.append("{path}")
   692 
   691