author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Tue, 01 Aug 2023 21:04:00 +0200 | |
changeset 3840 | c2b6354f036f |
parent 3817 | 3deeda82636a |
child 3863 | b076f52bd1c8 |
permissions | -rw-r--r-- |
2745 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
# This file is part of Beremiz |
|
3197
0f41c1e2c121
SVGHMI: split svghmi.py into hmi_tree.py + svghmi.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3193
diff
changeset
|
5 |
# Copyright (C) 2021: Edouard TISSERANT |
2745 | 6 |
# |
7 |
# See COPYING file for copyrights details. |
|
8 |
||
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3688
diff
changeset
|
9 |
|
2745 | 10 |
import os |
3573
1ee56fb544fc
IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3572
diff
changeset
|
11 |
import sys |
2745 | 12 |
import shutil |
2789 | 13 |
import hashlib |
2823
d631f8671c75
SVGHMI : add on Start, Stop and Watchdog command fields to configuration
Edouard Tisserant
parents:
2822
diff
changeset
|
14 |
import shlex |
3156
76c0c0a524c9
SVGHMI: display progress in IDE console while building
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3140
diff
changeset
|
15 |
import time |
2745 | 16 |
|
17 |
import wx |
|
2816 | 18 |
|
19 |
from lxml import etree |
|
20 |
from lxml.etree import XSLTApplyError |
|
2745 | 21 |
|
22 |
import util.paths as paths |
|
23 |
from POULibrary import POULibrary |
|
2756
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
24 |
from docutil import open_svg, get_inkscape_path |
2745 | 25 |
|
2756
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
26 |
from util.ProcessLogger import ProcessLogger |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
27 |
from runtime.typemapping import DebugTypesSize |
2767
302347f48193
svghmi.c : deduplicated variable access code borrowed from plc_debug.c. Added targets/var_access.c.
Edouard Tisserant
parents:
2765
diff
changeset
|
28 |
import targets |
2816 | 29 |
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor |
30 |
from XSLTransform import XSLTransform |
|
3201
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
31 |
from svghmi.i18n import EtreeToMessages, SaveCatalog, ReadTranslations,\ |
3214
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
32 |
MatchTranslations, TranslationToEtree, open_pofile,\ |
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
33 |
GetPoFiles |
3197
0f41c1e2c121
SVGHMI: split svghmi.py into hmi_tree.py + svghmi.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3193
diff
changeset
|
34 |
from svghmi.hmi_tree import HMI_TYPES, HMITreeNode, SPECIAL_NODES |
3201
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
35 |
from svghmi.ui import SVGHMI_UI |
3210
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
36 |
from svghmi.fonts import GetFontTypeAndFamilyName, GetCSSFontFaceFromFontFile |
2745 | 37 |
|
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
38 |
|
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
39 |
ScriptDirectory = paths.AbsDir(__file__) |
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
40 |
|
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
41 |
|
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
42 |
# module scope for HMITree root |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
43 |
# so that CTN can use HMITree deduced in Library |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
44 |
# note: this only works because library's Generate_C is |
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
45 |
# systematicaly invoked before CTN's CTNGenerate_C |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
46 |
|
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
47 |
hmi_tree_root = None |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
48 |
|
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
49 |
on_hmitree_update = None |
2816 | 50 |
|
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
51 |
maxConnectionsTotal = 0 |
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
52 |
|
2745 | 53 |
class SVGHMILibrary(POULibrary): |
54 |
def GetLibraryPath(self): |
|
2750 | 55 |
return paths.AbsNeighbourFile(__file__, "pous.xml") |
2745 | 56 |
|
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
57 |
def Generate_C(self, buildpath, varlist, IECCFLAGS): |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
58 |
global hmi_tree_root, on_hmitree_update, maxConnectionsTotal |
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
59 |
|
3341
dce1d5413310
SVGHMI: force MaxConnections sum back to zero, preventing it to grow indefinitely on each build.
Edouard Tisserant
parents:
3290
diff
changeset
|
60 |
maxConnectionsTotal = 0 |
dce1d5413310
SVGHMI: force MaxConnections sum back to zero, preventing it to grow indefinitely on each build.
Edouard Tisserant
parents:
3290
diff
changeset
|
61 |
|
3287
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
62 |
already_found_watchdog = False |
3290
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
63 |
found_SVGHMI_instance = False |
3287
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
64 |
for CTNChild in self.GetCTR().IterChildren(): |
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
65 |
if isinstance(CTNChild, SVGHMI): |
3290
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
66 |
found_SVGHMI_instance = True |
3287
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
67 |
# collect maximum connection total for all svghmi nodes |
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
68 |
maxConnectionsTotal += CTNChild.GetParamsAttributes("SVGHMI.MaxConnections")["value"] |
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
69 |
|
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
70 |
# spot watchdog abuse |
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
71 |
if CTNChild.GetParamsAttributes("SVGHMI.EnableWatchdog")["value"]: |
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
72 |
if already_found_watchdog: |
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
73 |
self.FatalError("SVGHMI: Only one watchdog enabled HMI allowed") |
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
74 |
already_found_watchdog = True |
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
75 |
|
3290
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
76 |
if not found_SVGHMI_instance: |
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
77 |
self.FatalError("SVGHMI : Library is selected but not used. Please either deselect it in project config or add a SVGHMI node to project.") |
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
78 |
|
3287
70a76083c59c
SVGHMI: detect watchdog abuse (more than one HMI instance with watchdog) at build time
Edouard Tisserant
parents:
3286
diff
changeset
|
79 |
|
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
80 |
""" |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
81 |
PLC Instance Tree: |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
82 |
prog0 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
83 |
+->v1 HMI_INT |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
84 |
+->v2 HMI_INT |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
85 |
+->fb0 (type mhoo) |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
86 |
| +->va HMI_NODE |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
87 |
| +->v3 HMI_INT |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
88 |
| +->v4 HMI_INT |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
89 |
| |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
90 |
+->fb1 (type mhoo) |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
91 |
| +->va HMI_NODE |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
92 |
| +->v3 HMI_INT |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
93 |
| +->v4 HMI_INT |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
94 |
| |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
95 |
+->fb2 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
96 |
+->v5 HMI_IN |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
97 |
|
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
98 |
HMI tree: |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
99 |
hmi0 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
100 |
+->v1 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
101 |
+->v2 |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
102 |
+->fb0 class:va |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
103 |
| +-> v3 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
104 |
| +-> v4 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
105 |
| |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
106 |
+->fb1 class:va |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
107 |
| +-> v3 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
108 |
| +-> v4 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
109 |
| |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
110 |
+->v5 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
111 |
|
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
112 |
""" |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
113 |
|
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
114 |
# Filter known HMI types |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
115 |
hmi_types_instances = [v for v in varlist if v["derived"] in HMI_TYPES] |
2758
5f79b194fa63
SVGHMI: filter out temporary variables created while generating ST code out of FBD.
Edouard Tisserant
parents:
2757
diff
changeset
|
116 |
|
2890
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
117 |
hmi_tree_root = None |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
118 |
|
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
119 |
# take first HMI_NODE (placed as special node), make it root |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
120 |
for i,v in enumerate(hmi_types_instances): |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
121 |
path = v["IEC_path"].split(".") |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
122 |
derived = v["derived"] |
2965
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
123 |
if derived == "HMI_NODE": |
2890
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
124 |
hmi_tree_root = HMITreeNode(path, "", derived, v["type"], v["vartype"], v["C_path"]) |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
125 |
hmi_types_instances.pop(i) |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
126 |
break |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
127 |
|
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
128 |
# deduce HMI tree from PLC HMI_* instances |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
129 |
for v in hmi_types_instances: |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
130 |
path = v["IEC_path"].split(".") |
2758
5f79b194fa63
SVGHMI: filter out temporary variables created while generating ST code out of FBD.
Edouard Tisserant
parents:
2757
diff
changeset
|
131 |
# ignores variables starting with _TMP_ |
5f79b194fa63
SVGHMI: filter out temporary variables created while generating ST code out of FBD.
Edouard Tisserant
parents:
2757
diff
changeset
|
132 |
if path[-1].startswith("_TMP_"): |
5f79b194fa63
SVGHMI: filter out temporary variables created while generating ST code out of FBD.
Edouard Tisserant
parents:
2757
diff
changeset
|
133 |
continue |
3381
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
134 |
vartype = v["vartype"] |
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
135 |
# ignores external variables |
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
136 |
if vartype == "EXT": |
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
137 |
continue |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
138 |
derived = v["derived"] |
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
139 |
kwargs={} |
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
140 |
if derived == "HMI_NODE": |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
141 |
# TODO : make problem if HMI_NODE used in CONFIG or RESOURCE |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
142 |
name = path[-2] |
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
143 |
kwargs['hmiclass'] = path[-1] |
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
144 |
else: |
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
145 |
name = path[-1] |
3381
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
146 |
new_node = HMITreeNode(path, name, derived, v["type"], vartype, v["C_path"], **kwargs) |
2965
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
147 |
placement_result = hmi_tree_root.place_node(new_node) |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
148 |
if placement_result is not None: |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
149 |
cause, problematic_node = placement_result |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
150 |
if cause == "Non_Unique": |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
151 |
message = _("HMI tree nodes paths are not unique.\nConflicting variable: {} {}").format( |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
152 |
".".join(problematic_node.path), |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
153 |
".".join(new_node.path)) |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
154 |
|
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
155 |
last_FB = None |
3381
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
156 |
for _v in varlist: |
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
157 |
if _v["vartype"] == "FB": |
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
158 |
last_FB = _v |
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
159 |
if _v["C_path"] == problematic_node: |
2965
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
160 |
break |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
161 |
if last_FB is not None: |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
162 |
failing_parent = last_FB["type"] |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
163 |
message += "\n" |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
164 |
message += _("Solution: Add HMI_NODE at beginning of {}").format(failing_parent) |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
165 |
|
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
166 |
elif cause in ["Late_HMI_NODE", "Duplicate_HMI_NODE"]: |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
167 |
cause, problematic_node = placement_result |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
168 |
message = _("There must be only one occurrence of HMI_NODE before any HMI_* variable in POU.\nConflicting variable: {} {}").format( |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
169 |
".".join(problematic_node.path), |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
170 |
".".join(new_node.path)) |
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
171 |
|
8f928cee01e5
SVGHMI: Makes error when HMI tree is not well formed. Prevents multiple and non-first HMI_NODE, and ensure that all paths in HMI tree are unique.
Edouard Tisserant
parents:
2945
diff
changeset
|
172 |
self.FatalError("SVGHMI : " + message) |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
173 |
|
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
174 |
if on_hmitree_update is not None: |
3201
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
175 |
on_hmitree_update(hmi_tree_root) |
2816 | 176 |
|
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
177 |
variable_decl_array = [] |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
178 |
extern_variables_declarations = [] |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
179 |
buf_index = 0 |
2775
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2772
diff
changeset
|
180 |
item_count = 0 |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
181 |
found_heartbeat = False |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
182 |
|
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
183 |
hearbeat_IEC_path = ['CONFIG', 'HEARTBEAT'] |
2828 | 184 |
|
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
185 |
for node in hmi_tree_root.traverse(): |
2828 | 186 |
if not found_heartbeat and node.path == hearbeat_IEC_path: |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
187 |
hmi_tree_hearbeat_index = item_count |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
188 |
found_heartbeat = True |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
189 |
extern_variables_declarations += [ |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
190 |
"#define heartbeat_index "+str(hmi_tree_hearbeat_index) |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
191 |
] |
2866
59a855c17aa6
SVGHMI: Stop ignoring HMI_NODE in HMI tree, and count it as a BOOL. Soon we use those nodes as reference for relative page jump, and as an "enable" bit for features associated to an HMI tree fragment.
Edouard Tisserant
parents:
2834
diff
changeset
|
192 |
if hasattr(node, "iectype"): |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
193 |
sz = DebugTypesSize.get(node.iectype, 0) |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
194 |
variable_decl_array += [ |
3399
95e0b926a8c3
SVGHMI: optimization of C part : stop traversing the whole HMI tree, use dual linked list for subscriptions and single linked list for changes from HMI. Intermediate commit, still crashing in some cases.
Edouard Tisserant
parents:
3381
diff
changeset
|
195 |
"HMITREE_ITEM_INITIALIZER(" + node.cpath + ", " + node.iectype + { |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
196 |
"EXT": "_P_ENUM", |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
197 |
"IN": "_P_ENUM", |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
198 |
"MEM": "_O_ENUM", |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
199 |
"OUT": "_O_ENUM", |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
200 |
"VAR": "_ENUM" |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
201 |
}[node.vartype] + ", " + |
3399
95e0b926a8c3
SVGHMI: optimization of C part : stop traversing the whole HMI tree, use dual linked list for subscriptions and single linked list for changes from HMI. Intermediate commit, still crashing in some cases.
Edouard Tisserant
parents:
3381
diff
changeset
|
202 |
str(buf_index) + ")"] |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
203 |
buf_index += sz |
2775
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2772
diff
changeset
|
204 |
item_count += 1 |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
205 |
if len(node.path) == 1: |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
206 |
extern_variables_declarations += [ |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
207 |
"extern __IEC_" + node.iectype + "_" + |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
208 |
"t" if node.vartype is "VAR" else "p" |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
209 |
+ node.cpath + ";"] |
2828 | 210 |
|
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
211 |
assert(found_heartbeat) |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
212 |
|
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
213 |
# TODO : filter only requiered external declarations |
2828 | 214 |
for v in varlist: |
215 |
if v["C_path"].find('.') < 0: |
|
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
216 |
extern_variables_declarations += [ |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
217 |
"extern %(type)s %(C_path)s;" % v] |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
218 |
|
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
219 |
# TODO check if programs need to be declared separately |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
220 |
# "programs_declarations": "\n".join(["extern %(type)s %(C_path)s;" % |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
221 |
# p for p in self._ProgramList]), |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
222 |
|
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
223 |
# C code to observe/access HMI tree variables |
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
224 |
svghmi_c_filepath = paths.AbsNeighbourFile(__file__, "svghmi.c") |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
225 |
svghmi_c_file = open(svghmi_c_filepath, 'r') |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
226 |
svghmi_c_code = svghmi_c_file.read() |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
227 |
svghmi_c_file.close() |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
228 |
svghmi_c_code = svghmi_c_code % { |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
229 |
"variable_decl_array": ",\n".join(variable_decl_array), |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
230 |
"extern_variables_declarations": "\n".join(extern_variables_declarations), |
2767
302347f48193
svghmi.c : deduplicated variable access code borrowed from plc_debug.c. Added targets/var_access.c.
Edouard Tisserant
parents:
2765
diff
changeset
|
231 |
"buffer_size": buf_index, |
2775
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2772
diff
changeset
|
232 |
"item_count": item_count, |
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
233 |
"var_access_code": targets.GetCode("var_access.c"), |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
234 |
"PLC_ticktime": self.GetCTR().GetTicktime(), |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
235 |
"hmi_hash_ints": ",".join(map(str,hmi_tree_root.hash())), |
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
236 |
"max_connections": maxConnectionsTotal |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
237 |
} |
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
238 |
|
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
239 |
gen_svghmi_c_path = os.path.join(buildpath, "svghmi.c") |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
240 |
gen_svghmi_c = open(gen_svghmi_c_path, 'w') |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
241 |
gen_svghmi_c.write(svghmi_c_code) |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
242 |
gen_svghmi_c.close() |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
243 |
|
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
244 |
# Python based WebSocket HMITree Server |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
245 |
svghmiserverfile = open(paths.AbsNeighbourFile(__file__, "svghmi_server.py"), 'r') |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
246 |
svghmiservercode = svghmiserverfile.read() |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
247 |
svghmiserverfile.close() |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
248 |
|
2993
b76f303ffce6
Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents:
2984
diff
changeset
|
249 |
runtimefile_path = os.path.join(buildpath, "runtime_00_svghmi.py") |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
250 |
runtimefile = open(runtimefile_path, 'w') |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
251 |
runtimefile.write(svghmiservercode) |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
252 |
runtimefile.close() |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
253 |
|
3176
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
254 |
# Backup HMI Tree in XML form so that it can be loaded without building |
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
255 |
hmitree_backup_path = os.path.join(buildpath, "hmitree.xml") |
3180
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
256 |
hmitree_backup_file = open(hmitree_backup_path, 'wb') |
3176
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
257 |
hmitree_backup_file.write(etree.tostring(hmi_tree_root.etree())) |
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
258 |
hmitree_backup_file.close() |
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
259 |
|
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
260 |
return ((["svghmi"], [(gen_svghmi_c_path, IECCFLAGS)], True), "", |
2993
b76f303ffce6
Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents:
2984
diff
changeset
|
261 |
("runtime_00_svghmi.py", open(runtimefile_path, "rb"))) |
b76f303ffce6
Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents:
2984
diff
changeset
|
262 |
# ^ |
b76f303ffce6
Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents:
2984
diff
changeset
|
263 |
# note the double zero after "runtime_", |
b76f303ffce6
Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents:
2984
diff
changeset
|
264 |
# to ensure placement before other CTN generated code in execution order |
2745 | 265 |
|
3267
5f20f391ae31
SVGHMI: Prepare accepting multiple clients on multiple HMI: Use POULibrary new capability to add variables to PLC Configuration. Now heartbeat and HMI tree root are added by the library part of SVGHMI, and not by each instance.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3218
diff
changeset
|
266 |
def GlobalInstances(self): |
5f20f391ae31
SVGHMI: Prepare accepting multiple clients on multiple HMI: Use POULibrary new capability to add variables to PLC Configuration. Now heartbeat and HMI tree root are added by the library part of SVGHMI, and not by each instance.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3218
diff
changeset
|
267 |
""" Adds HMI tree root and hearbeat to PLC Configuration's globals """ |
5f20f391ae31
SVGHMI: Prepare accepting multiple clients on multiple HMI: Use POULibrary new capability to add variables to PLC Configuration. Now heartbeat and HMI tree root are added by the library part of SVGHMI, and not by each instance.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3218
diff
changeset
|
268 |
return [(name, iec_type, "") for name, iec_type in SPECIAL_NODES] |
5f20f391ae31
SVGHMI: Prepare accepting multiple clients on multiple HMI: Use POULibrary new capability to add variables to PLC Configuration. Now heartbeat and HMI tree root are added by the library part of SVGHMI, and not by each instance.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3218
diff
changeset
|
269 |
|
5f20f391ae31
SVGHMI: Prepare accepting multiple clients on multiple HMI: Use POULibrary new capability to add variables to PLC Configuration. Now heartbeat and HMI tree root are added by the library part of SVGHMI, and not by each instance.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3218
diff
changeset
|
270 |
|
2816 | 271 |
|
3201
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
272 |
def Register_SVGHMI_UI_for_HMI_tree_updates(ref): |
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
273 |
global on_hmitree_update |
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
274 |
def HMITreeUpdate(_hmi_tree_root): |
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
275 |
obj = ref() |
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
276 |
if obj is not None: |
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
277 |
obj.HMITreeUpdate(_hmi_tree_root) |
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
278 |
|
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
279 |
on_hmitree_update = HMITreeUpdate |
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
280 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
281 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
282 |
class SVGHMIEditor(ConfTreeNodeEditor): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
283 |
CONFNODEEDITOR_TABS = [ |
3201
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
284 |
(_("HMI Tree"), "CreateSVGHMI_UI")] |
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
285 |
|
3499
72ee59ff959c
SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3498
diff
changeset
|
286 |
def __init__(self, parent, controler, window): |
72ee59ff959c
SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3498
diff
changeset
|
287 |
ConfTreeNodeEditor.__init__(self, parent, controler, window) |
72ee59ff959c
SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3498
diff
changeset
|
288 |
self.Controler = controler |
72ee59ff959c
SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3498
diff
changeset
|
289 |
|
3201
6dadc1690284
SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3197
diff
changeset
|
290 |
def CreateSVGHMI_UI(self, parent): |
3176
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
291 |
global hmi_tree_root |
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
292 |
|
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
293 |
if hmi_tree_root is None: |
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
294 |
buildpath = self.Controler.GetCTRoot()._getBuildPath() |
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
295 |
hmitree_backup_path = os.path.join(buildpath, "hmitree.xml") |
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
296 |
if os.path.exists(hmitree_backup_path): |
3180
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
297 |
hmitree_backup_file = open(hmitree_backup_path, 'rb') |
3176
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
298 |
hmi_tree_root = HMITreeNode.from_etree(etree.parse(hmitree_backup_file).getroot()) |
81136a097012
SVGHMI: Systematically save HMI Tree in build directory as hmitree.xml when building, so that HMI Tree can be displayed when re-opening project, without having to build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3170
diff
changeset
|
299 |
|
3499
72ee59ff959c
SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3498
diff
changeset
|
300 |
ret = SVGHMI_UI(parent, self.Controler, Register_SVGHMI_UI_for_HMI_tree_updates) |
3208
b5330d76e225
SVGHMI: Fix update of HMI tree in UI when loading from XML at start. Removed some dead code left after split of svghmi.py into svghmi.py+ui.py.
Edouard Tisserant
parents:
3201
diff
changeset
|
301 |
|
b5330d76e225
SVGHMI: Fix update of HMI tree in UI when loading from XML at start. Removed some dead code left after split of svghmi.py into svghmi.py+ui.py.
Edouard Tisserant
parents:
3201
diff
changeset
|
302 |
on_hmitree_update(hmi_tree_root) |
b5330d76e225
SVGHMI: Fix update of HMI tree in UI when loading from XML at start. Removed some dead code left after split of svghmi.py into svghmi.py+ui.py.
Edouard Tisserant
parents:
3201
diff
changeset
|
303 |
|
b5330d76e225
SVGHMI: Fix update of HMI tree in UI when loading from XML at start. Removed some dead code left after split of svghmi.py into svghmi.py+ui.py.
Edouard Tisserant
parents:
3201
diff
changeset
|
304 |
return ret |
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
305 |
|
3573
1ee56fb544fc
IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3572
diff
changeset
|
306 |
if sys.platform.startswith('win'): |
3498
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
307 |
default_cmds={ |
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
308 |
"launch":"cmd.exe /c 'start msedge {url}'", |
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
309 |
"watchdog":"cmd.exe /k 'echo watchdog for {url} !'"} |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3688
diff
changeset
|
310 |
elif "SNAP" in os.environ: |
3573
1ee56fb544fc
IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3572
diff
changeset
|
311 |
default_cmds={ |
1ee56fb544fc
IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3572
diff
changeset
|
312 |
"launch":"xdg-open {url}", |
1ee56fb544fc
IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3572
diff
changeset
|
313 |
"watchdog":"echo Watchdog for {name} !"} |
3348
cfac764413dd
IDE/windows: Avoid exception on quit caused by runtime being killed without disconnecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3341
diff
changeset
|
314 |
else: |
3498
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
315 |
default_cmds={ |
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
316 |
"launch":"chromium {url}", |
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
317 |
"watchdog":"echo Watchdog for {name} !"} |
3348
cfac764413dd
IDE/windows: Avoid exception on quit caused by runtime being killed without disconnecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3341
diff
changeset
|
318 |
|
2745 | 319 |
class SVGHMI(object): |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
320 |
XSD = """<?xml version="1.0" encoding="utf-8" ?> |
2745 | 321 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
322 |
<xsd:element name="SVGHMI"> |
|
323 |
<xsd:complexType> |
|
3498
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
324 |
<xsd:attribute name="OnStart" type="xsd:string" use="optional" default="%(launch)s"/> |
3348
cfac764413dd
IDE/windows: Avoid exception on quit caused by runtime being killed without disconnecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3341
diff
changeset
|
325 |
<xsd:attribute name="OnStop" type="xsd:string" use="optional" default=""/> |
3498
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
326 |
<xsd:attribute name="OnWatchdog" type="xsd:string" use="optional" default="%(watchdog)s"/> |
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
327 |
<xsd:attribute name="EnableWatchdog" type="xsd:boolean" use="optional" default="false"/> |
3277
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
328 |
<xsd:attribute name="WatchdogInitial" use="optional" default="30"> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
329 |
<xsd:simpleType> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
330 |
<xsd:restriction base="xsd:integer"> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
331 |
<xsd:minInclusive value="2"/> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
332 |
<xsd:maxInclusive value="600"/> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
333 |
</xsd:restriction> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
334 |
</xsd:simpleType> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
335 |
</xsd:attribute> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
336 |
<xsd:attribute name="WatchdogInterval" use="optional" default="5"> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
337 |
<xsd:simpleType> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
338 |
<xsd:restriction base="xsd:integer"> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
339 |
<xsd:minInclusive value="2"/> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
340 |
<xsd:maxInclusive value="60"/> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
341 |
</xsd:restriction> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
342 |
</xsd:simpleType> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
343 |
</xsd:attribute> |
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
344 |
<xsd:attribute name="Port" type="xsd:integer" use="optional" default="8008"/> |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
345 |
<xsd:attribute name="Interface" type="xsd:string" use="optional" default="localhost"/> |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
346 |
<xsd:attribute name="Path" type="xsd:string" use="optional" default="{name}"/> |
3277
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
347 |
<xsd:attribute name="MaxConnections" use="optional" default="16"> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
348 |
<xsd:simpleType> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
349 |
<xsd:restriction base="xsd:integer"> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
350 |
<xsd:minInclusive value="1"/> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
351 |
<xsd:maxInclusive value="1024"/> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
352 |
</xsd:restriction> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
353 |
</xsd:simpleType> |
8e81e4ce9bc6
SVGHMI: set some boundaries for watchdog timings and max connection count.
Edouard Tisserant
parents:
3274
diff
changeset
|
354 |
</xsd:attribute> |
2745 | 355 |
</xsd:complexType> |
356 |
</xsd:element> |
|
357 |
</xsd:schema> |
|
3498
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
358 |
"""%default_cmds |
2816 | 359 |
|
360 |
EditorType = SVGHMIEditor |
|
2745 | 361 |
|
362 |
ConfNodeMethods = [ |
|
363 |
{ |
|
364 |
"bitmap": "ImportSVG", |
|
365 |
"name": _("Import SVG"), |
|
366 |
"tooltip": _("Import SVG"), |
|
367 |
"method": "_ImportSVG" |
|
368 |
}, |
|
369 |
{ |
|
3210
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
370 |
"bitmap": "EditSVG", |
2745 | 371 |
"name": _("Inkscape"), |
372 |
"tooltip": _("Edit HMI"), |
|
373 |
"method": "_StartInkscape" |
|
374 |
}, |
|
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
375 |
{ |
3210
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
376 |
"bitmap": "OpenPOT", |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
377 |
"name": _("New lang"), |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
378 |
"tooltip": _("Open non translated message catalog (POT) to start new language"), |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
379 |
"method": "_OpenPOT" |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
380 |
}, |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
381 |
{ |
3210
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
382 |
"bitmap": "EditPO", |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
383 |
"name": _("Edit lang"), |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
384 |
"tooltip": _("Edit existing message catalog (PO) for specific language"), |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
385 |
"method": "_EditPO" |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
386 |
}, |
3210
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
387 |
{ |
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
388 |
"bitmap": "AddFont", |
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
389 |
"name": _("Add Font"), |
3211
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
390 |
"tooltip": _("Add TTF, OTF or WOFF font to be embedded in HMI"), |
3210
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
391 |
"method": "_AddFont" |
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
392 |
}, |
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
393 |
{ |
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
394 |
"bitmap": "DelFont", |
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
395 |
"name": _("Delete Font"), |
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
396 |
"tooltip": _("Remove font previously added to HMI"), |
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
397 |
"method": "_DelFont" |
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
398 |
}, |
2745 | 399 |
] |
400 |
||
401 |
def _getSVGpath(self, project_path=None): |
|
402 |
if project_path is None: |
|
403 |
project_path = self.CTNPath() |
|
2781 | 404 |
return os.path.join(project_path, "svghmi.svg") |
2745 | 405 |
|
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
406 |
def _getPOTpath(self, project_path=None): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
407 |
if project_path is None: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
408 |
project_path = self.CTNPath() |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
409 |
return os.path.join(project_path, "messages.pot") |
2745 | 410 |
|
411 |
def OnCTNSave(self, from_project_path=None): |
|
412 |
if from_project_path is not None: |
|
413 |
shutil.copyfile(self._getSVGpath(from_project_path), |
|
414 |
self._getSVGpath()) |
|
3498
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
415 |
|
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
416 |
potpath = self._getPOTpath(from_project_path) |
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
417 |
if os.path.isfile(potpath): |
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
418 |
shutil.copyfile(potpath, self._getPOTpath()) |
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
419 |
# copy .PO files |
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
420 |
for _name, pofile in GetPoFiles(from_project_path): |
cf4e6a7d40f8
Various fixes to make svghmi_traffic_light example bahave on windows.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3399
diff
changeset
|
421 |
shutil.copy(pofile, self.CTNPath()) |
2750 | 422 |
return True |
2745 | 423 |
|
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
424 |
def GetSVGGeometry(self): |
3170
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
425 |
self.ProgressStart("inkscape", "collecting SVG geometry (Inkscape)") |
2756
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
426 |
# invoke inskscape -S, csv-parse output, produce elements |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
427 |
InkscapeGeomColumns = ["Id", "x", "y", "w", "h"] |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
428 |
|
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
429 |
inkpath = get_inkscape_path() |
3052
ffce85221ea5
SVGHMI: Better error message when inkscape is not installed.
Edouard Tisserant
parents:
3051
diff
changeset
|
430 |
if inkpath is None: |
ffce85221ea5
SVGHMI: Better error message when inkscape is not installed.
Edouard Tisserant
parents:
3051
diff
changeset
|
431 |
self.FatalError("SVGHMI: inkscape is not installed.") |
ffce85221ea5
SVGHMI: Better error message when inkscape is not installed.
Edouard Tisserant
parents:
3051
diff
changeset
|
432 |
|
2756
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
433 |
svgpath = self._getSVGpath() |
3032
2f6dfb99d094
SVGHMI: Behave when project path include spaces, and make more understandable error in case of problem extracting geometry with inkscape.
Edouard Tisserant
parents:
2993
diff
changeset
|
434 |
status, result, _err_result = ProcessLogger(self.GetCTRoot().logger, |
3817
3deeda82636a
Fix Py3 problems with basic SVGHMI build and run.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3750
diff
changeset
|
435 |
[inkpath, '-S', svgpath], |
2756
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
436 |
no_stdout=True, |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
437 |
no_stderr=True).spin() |
3032
2f6dfb99d094
SVGHMI: Behave when project path include spaces, and make more understandable error in case of problem extracting geometry with inkscape.
Edouard Tisserant
parents:
2993
diff
changeset
|
438 |
if status != 0: |
3052
ffce85221ea5
SVGHMI: Better error message when inkscape is not installed.
Edouard Tisserant
parents:
3051
diff
changeset
|
439 |
self.FatalError("SVGHMI: inkscape couldn't extract geometry from given SVG.") |
3032
2f6dfb99d094
SVGHMI: Behave when project path include spaces, and make more understandable error in case of problem extracting geometry with inkscape.
Edouard Tisserant
parents:
2993
diff
changeset
|
440 |
|
2756
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
441 |
res = [] |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
442 |
for line in result.split(): |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
443 |
strippedline = line.strip() |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
444 |
attrs = dict( |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3688
diff
changeset
|
445 |
list(zip(InkscapeGeomColumns, line.strip().split(',')))) |
2756
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
446 |
|
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
447 |
res.append(etree.Element("bbox", **attrs)) |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
448 |
|
3170
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
449 |
self.ProgressEnd("inkscape") |
2756
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
450 |
return res |
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
451 |
|
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
452 |
def GetHMITree(self): |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
453 |
global hmi_tree_root |
3170
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
454 |
self.ProgressStart("hmitree", "getting HMI tree") |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
455 |
res = [hmi_tree_root.etree(add_hash=True)] |
3170
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
456 |
self.ProgressEnd("hmitree") |
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
457 |
return res |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
458 |
|
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
459 |
def GetTranslations(self, _context, msgs): |
3170
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
460 |
self.ProgressStart("i18n", "getting Translations") |
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
461 |
messages = EtreeToMessages(msgs) |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
462 |
|
3140
cae53fe54cf2
SVGHMI: i18n: prevent creating messages.pot if no translation
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3137
diff
changeset
|
463 |
if len(messages) == 0: |
3170
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
464 |
self.ProgressEnd("i18n") |
3140
cae53fe54cf2
SVGHMI: i18n: prevent creating messages.pot if no translation
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3137
diff
changeset
|
465 |
return |
cae53fe54cf2
SVGHMI: i18n: prevent creating messages.pot if no translation
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3137
diff
changeset
|
466 |
|
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
467 |
SaveCatalog(self._getPOTpath(), messages) |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
468 |
|
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
469 |
translations = ReadTranslations(self.CTNPath()) |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
470 |
|
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
471 |
langs,translated_messages = MatchTranslations(translations, messages, |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
472 |
errcallback=self.GetCTRoot().logger.write_warning) |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
473 |
|
3165
2db69e2c5673
SVGHMI: Optimized overlapping geometry (widget ot page belonging) computation. Added human readable messages for progress. Includes updated XSLT.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3160
diff
changeset
|
474 |
ret = TranslationToEtree(langs,translated_messages) |
2db69e2c5673
SVGHMI: Optimized overlapping geometry (widget ot page belonging) computation. Added human readable messages for progress. Includes updated XSLT.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3160
diff
changeset
|
475 |
|
3170
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
476 |
self.ProgressEnd("i18n") |
3165
2db69e2c5673
SVGHMI: Optimized overlapping geometry (widget ot page belonging) computation. Added human readable messages for progress. Includes updated XSLT.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3160
diff
changeset
|
477 |
|
2db69e2c5673
SVGHMI: Optimized overlapping geometry (widget ot page belonging) computation. Added human readable messages for progress. Includes updated XSLT.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3160
diff
changeset
|
478 |
return ret |
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
479 |
|
3214
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
480 |
def GetFontsFiles(self): |
3211
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
481 |
project_path = self.CTNPath() |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
482 |
fontdir = os.path.join(project_path, "fonts") |
3214
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
483 |
if os.path.isdir(fontdir): |
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
484 |
return [os.path.join(fontdir,f) for f in sorted(os.listdir(fontdir))] |
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
485 |
return [] |
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
486 |
|
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
487 |
def GetFonts(self, _context): |
3211
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
488 |
css_parts = [] |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
489 |
|
3214
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
490 |
for fontfile in self.GetFontsFiles(): |
3211
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
491 |
if os.path.isfile(fontfile): |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
492 |
css_parts.append(GetCSSFontFaceFromFontFile(fontfile)) |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
493 |
|
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
494 |
return "".join(css_parts) |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
495 |
|
3170
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
496 |
times_msgs = {} |
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
497 |
indent = 1 |
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
498 |
def ProgressStart(self, k, m): |
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
499 |
self.times_msgs[k] = (time.time(), m) |
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
500 |
self.GetCTRoot().logger.write(" "*self.indent + "Start %s...\n"%m) |
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
501 |
self.indent = self.indent + 1 |
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
502 |
|
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
503 |
def ProgressEnd(self, k): |
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
504 |
t = time.time() |
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
505 |
oldt, m = self.times_msgs[k] |
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
506 |
self.indent = self.indent - 1 |
aaa203270ab0
SVGHMI: Make build log less redundant, and refactor progress information code a bit, to make it also a bit less redundant.
Edouard Tisserant
parents:
3167
diff
changeset
|
507 |
self.GetCTRoot().logger.write(" "*self.indent + "... finished in %.3fs\n"%(t - oldt)) |
3156
76c0c0a524c9
SVGHMI: display progress in IDE console while building
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3140
diff
changeset
|
508 |
|
3286
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
509 |
def get_SVGHMI_options(self): |
3290
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
510 |
name = self.BaseParams.getName() |
3286
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
511 |
port = self.GetParamsAttributes("SVGHMI.Port")["value"] |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
512 |
interface = self.GetParamsAttributes("SVGHMI.Interface")["value"] |
3290
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
513 |
path = self.GetParamsAttributes("SVGHMI.Path")["value"].format(name=name) |
3286
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
514 |
if path and path[0]=='/': |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
515 |
path = path[1:] |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
516 |
enable_watchdog = self.GetParamsAttributes("SVGHMI.EnableWatchdog")["value"] |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
517 |
url="http://"+interface+("" if port==80 else (":"+str(port)) |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
518 |
) + (("/"+path) if path else "" |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
519 |
) + ("#watchdog" if enable_watchdog else "") |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
520 |
|
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
521 |
return dict( |
3290
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
522 |
name=name, |
3286
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
523 |
port=port, |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
524 |
interface=interface, |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
525 |
path=path, |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
526 |
enable_watchdog=enable_watchdog, |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
527 |
url=url) |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
528 |
|
2745 | 529 |
def CTNGenerate_C(self, buildpath, locations): |
3290
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
530 |
global hmi_tree_root |
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
531 |
|
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
532 |
if hmi_tree_root is None: |
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
533 |
self.FatalError("SVGHMI : Library is not selected. Please select it in project config.") |
2745 | 534 |
|
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
535 |
location_str = "_".join(map(str, self.GetCurrentLocation())) |
3286
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
536 |
svghmi_options = self.get_SVGHMI_options() |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
537 |
|
2745 | 538 |
svgfile = self._getSVGpath() |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
539 |
|
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
540 |
res = ([], "", False) |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
541 |
|
2812
68ac5bf43525
SVGHMI: various fixes to make SVGHMI behave on more versions of twisted and GCC.
Edouard Tisserant
parents:
2789
diff
changeset
|
542 |
target_fname = "svghmi_"+location_str+".xhtml" |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
543 |
|
3180
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
544 |
build_path = self._getBuildPath() |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
545 |
target_path = os.path.join(build_path, target_fname) |
3375
aa25c89a8845
SVGHMI: prevent systematic rebuild when there are multiple instances of SVGHMI CTN.
Edouard Tisserant
parents:
3372
diff
changeset
|
546 |
hash_path = os.path.join(build_path, "svghmi_"+location_str+".md5") |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
547 |
|
3156
76c0c0a524c9
SVGHMI: display progress in IDE console while building
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3140
diff
changeset
|
548 |
self.GetCTRoot().logger.write("SVGHMI:\n") |
76c0c0a524c9
SVGHMI: display progress in IDE console while building
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3140
diff
changeset
|
549 |
|
2745 | 550 |
if os.path.exists(svgfile): |
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
551 |
|
3180
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
552 |
hasher = hashlib.md5() |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
553 |
hmi_tree_root._hash(hasher) |
3218
76f1cd1291f4
SVGHMI: Fixed last i18n changes meant to allow checking changes in PO files. Was making build exception when no PO files available.
Edouard Tisserant
parents:
3214
diff
changeset
|
554 |
pofiles = GetPoFiles(self.CTNPath()) |
3214
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
555 |
filestocheck = [svgfile] + \ |
3218
76f1cd1291f4
SVGHMI: Fixed last i18n changes meant to allow checking changes in PO files. Was making build exception when no PO files available.
Edouard Tisserant
parents:
3214
diff
changeset
|
556 |
(list(zip(*pofiles)[1]) if pofiles else []) + \ |
3214
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
557 |
self.GetFontsFiles() |
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
558 |
|
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
559 |
for filetocheck in filestocheck: |
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
560 |
with open(filetocheck, 'rb') as afile: |
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
561 |
while True: |
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
562 |
buf = afile.read(65536) |
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
563 |
if len(buf) > 0: |
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
564 |
hasher.update(buf) |
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
565 |
else: |
bb314cdfc656
SVGHMI: force svghmi build if any change in fonts or translation (.PO) files
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3211
diff
changeset
|
566 |
break |
3180
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
567 |
digest = hasher.hexdigest() |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
568 |
|
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
569 |
if os.path.exists(hash_path): |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
570 |
with open(hash_path, 'rb') as digest_file: |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
571 |
last_digest = digest_file.read() |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
572 |
else: |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
573 |
last_digest = None |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
574 |
|
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
575 |
if digest != last_digest: |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
576 |
|
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
577 |
transform = XSLTransform(os.path.join(ScriptDirectory, "gen_index_xhtml.xslt"), |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
578 |
[("GetSVGGeometry", lambda *_ignored:self.GetSVGGeometry()), |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
579 |
("GetHMITree", lambda *_ignored:self.GetHMITree()), |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
580 |
("GetTranslations", self.GetTranslations), |
3211
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
581 |
("GetFonts", self.GetFonts), |
3180
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
582 |
("ProgressStart", lambda _ign,k,m:self.ProgressStart(str(k),str(m))), |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
583 |
("ProgressEnd", lambda _ign,k:self.ProgressEnd(str(k)))]) |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
584 |
|
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
585 |
self.ProgressStart("svg", "source SVG parsing") |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
586 |
|
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
587 |
# load svg as a DOM with Etree |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
588 |
svgdom = etree.parse(svgfile) |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
589 |
|
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
590 |
self.ProgressEnd("svg") |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
591 |
|
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
592 |
# call xslt transform on Inkscape's SVG to generate XHTML |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
593 |
try: |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
594 |
self.ProgressStart("xslt", "XSLT transform") |
3381
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
595 |
result = transform.transform( |
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
596 |
svgdom, instance_name=location_str) # , profile_run=True) |
3180
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
597 |
self.ProgressEnd("xslt") |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
598 |
except XSLTApplyError as e: |
3290
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
599 |
self.FatalError("SVGHMI " + svghmi_options["name"] + ": " + e.message) |
3180
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
600 |
finally: |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
601 |
for entry in transform.get_error_log(): |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
602 |
message = "SVGHMI: "+ entry.message + "\n" |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
603 |
self.GetCTRoot().logger.write_warning(message) |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
604 |
|
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
605 |
target_file = open(target_path, 'wb') |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
606 |
result.write(target_file, encoding="utf-8") |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
607 |
target_file.close() |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
608 |
|
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
609 |
# print(str(result)) |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
610 |
# print(transform.xslt.error_log) |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
611 |
# print(etree.tostring(result.xslt_profile,pretty_print=True)) |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
612 |
|
3817
3deeda82636a
Fix Py3 problems with basic SVGHMI build and run.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3750
diff
changeset
|
613 |
with open(hash_path, 'w') as digest_file: |
3180
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
614 |
digest_file.write(digest) |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
615 |
else: |
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
616 |
self.GetCTRoot().logger.write(" No changes - XSLT transformation skipped\n") |
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
617 |
|
2745 | 618 |
else: |
3180
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
619 |
target_file = open(target_path, 'wb') |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
620 |
target_file.write("""<!DOCTYPE html> |
3274
16066300b254
SVGHMI: default library path, default page when starting a SVGHMI project, error page when no SVG present
Edouard Tisserant
parents:
3270
diff
changeset
|
621 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
16066300b254
SVGHMI: default library path, default page when starting a SVGHMI project, error page when no SVG present
Edouard Tisserant
parents:
3270
diff
changeset
|
622 |
<head> |
16066300b254
SVGHMI: default library path, default page when starting a SVGHMI project, error page when no SVG present
Edouard Tisserant
parents:
3270
diff
changeset
|
623 |
<title>SVGHMI</title> |
16066300b254
SVGHMI: default library path, default page when starting a SVGHMI project, error page when no SVG present
Edouard Tisserant
parents:
3270
diff
changeset
|
624 |
</head> |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
625 |
<body> |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
626 |
<h1> No SVG file provided </h1> |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
627 |
</body> |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
628 |
</html> |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
629 |
""") |
3180
c059026d8626
SVGHMI: do not do XSLT transform if both SVGHMI and HMI Tree didn't change since last build
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3177
diff
changeset
|
630 |
target_file.close() |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
631 |
|
3372
e5cb7447320c
SVGHMI: prevents watchdog being triggered when SVGHMI is empty.
Edouard Tisserant
parents:
3348
diff
changeset
|
632 |
# In case no SVG is given, watchdog is useless |
e5cb7447320c
SVGHMI: prevents watchdog being triggered when SVGHMI is empty.
Edouard Tisserant
parents:
3348
diff
changeset
|
633 |
svghmi_options["enable_watchdog"] = False |
e5cb7447320c
SVGHMI: prevents watchdog being triggered when SVGHMI is empty.
Edouard Tisserant
parents:
3348
diff
changeset
|
634 |
|
2772 | 635 |
res += ((target_fname, open(target_path, "rb")),) |
2828 | 636 |
|
2823
d631f8671c75
SVGHMI : add on Start, Stop and Watchdog command fields to configuration
Edouard Tisserant
parents:
2822
diff
changeset
|
637 |
svghmi_cmds = {} |
d631f8671c75
SVGHMI : add on Start, Stop and Watchdog command fields to configuration
Edouard Tisserant
parents:
2822
diff
changeset
|
638 |
for thing in ["Start", "Stop", "Watchdog"]: |
d631f8671c75
SVGHMI : add on Start, Stop and Watchdog command fields to configuration
Edouard Tisserant
parents:
2822
diff
changeset
|
639 |
given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"] |
2824
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
640 |
svghmi_cmds[thing] = ( |
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
641 |
"Popen(" + |
3286
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
642 |
repr(shlex.split(given_command.format(**svghmi_options))) + |
3647
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
643 |
")") if given_command else "None # no command given" |
2772 | 644 |
|
2993
b76f303ffce6
Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents:
2984
diff
changeset
|
645 |
runtimefile_path = os.path.join(buildpath, "runtime_%s_svghmi_.py" % location_str) |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
646 |
runtimefile = open(runtimefile_path, 'w') |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
647 |
runtimefile.write(""" |
3647
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
648 |
#!/usr/bin/env python |
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
649 |
# -*- coding: utf-8 -*- |
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
650 |
|
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
651 |
# generated by beremiz/svghmi/svghmi.py |
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
652 |
|
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
653 |
browser_proc = None |
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
654 |
|
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
655 |
def svghmi_{location}_watchdog_trigger(): |
3647
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
656 |
global browser_proc |
3681 | 657 |
watchdog_proc = {svghmi_cmds[Watchdog]} |
658 |
waitpid_timeout(watchdog_proc, "SVGHMI watchdog triggered command") |
|
3662
364f2409eeda
SVGHMI: watchdog now calls OnStart and OnStop commands just after calling OnWatchdog. Therefore, OnWatchdog command should not restart browser by itself.
Edouard Tisserant
parents:
3647
diff
changeset
|
659 |
stop_proc = {svghmi_cmds[Stop]} |
364f2409eeda
SVGHMI: watchdog now calls OnStart and OnStop commands just after calling OnWatchdog. Therefore, OnWatchdog command should not restart browser by itself.
Edouard Tisserant
parents:
3647
diff
changeset
|
660 |
waitpid_timeout(stop_proc, "SVGHMI stop command") |
3647
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
661 |
waitpid_timeout(browser_proc, "SVGHMI browser process") |
3662
364f2409eeda
SVGHMI: watchdog now calls OnStart and OnStop commands just after calling OnWatchdog. Therefore, OnWatchdog command should not restart browser by itself.
Edouard Tisserant
parents:
3647
diff
changeset
|
662 |
browser_proc = {svghmi_cmds[Start]} |
2824
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
663 |
|
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
664 |
max_svghmi_sessions = {maxConnections_total} |
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
665 |
|
2993
b76f303ffce6
Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents:
2984
diff
changeset
|
666 |
def _runtime_{location}_svghmi_start(): |
3647
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
667 |
global svghmi_watchdog, svghmi_servers, browser_proc |
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
668 |
|
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
669 |
srv = svghmi_servers.get("{interface}:{port}", None) |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
670 |
if srv is not None: |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
671 |
svghmi_root, svghmi_listener, path_list = srv |
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
672 |
if '{path}' in path_list: |
3290
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
673 |
raise Exception("SVGHMI {name}: path {path} already used on {interface}:{port}") |
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
674 |
else: |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
675 |
svghmi_root = Resource() |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
676 |
factory = HMIWebSocketServerFactory() |
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
677 |
factory.setProtocolOptions(maxConnections={maxConnections}) |
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
678 |
|
3817
3deeda82636a
Fix Py3 problems with basic SVGHMI build and run.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3750
diff
changeset
|
679 |
svghmi_root.putChild(b"ws", WebSocketResource(factory)) |
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
680 |
|
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
681 |
svghmi_listener = reactor.listenTCP({port}, Site(svghmi_root), interface='{interface}') |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
682 |
path_list = [] |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
683 |
svghmi_servers["{interface}:{port}"] = (svghmi_root, svghmi_listener, path_list) |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
684 |
|
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
685 |
svghmi_root.putChild( |
3817
3deeda82636a
Fix Py3 problems with basic SVGHMI build and run.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3750
diff
changeset
|
686 |
b'{path}', |
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
687 |
NoCacheFile('{xhtml}', |
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
688 |
defaultType='application/xhtml+xml')) |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
689 |
|
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
690 |
path_list.append("{path}") |
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
691 |
|
3647
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
692 |
browser_proc = {svghmi_cmds[Start]} |
2824
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
693 |
|
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
694 |
if {enable_watchdog}: |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
695 |
if svghmi_watchdog is None: |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
696 |
svghmi_watchdog = Watchdog( |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
697 |
{watchdog_initial}, |
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
698 |
{watchdog_interval}, |
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
699 |
svghmi_{location}_watchdog_trigger) |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
700 |
else: |
3290
f0c97422b34a
SVGHMI: Fix detection of library without instance and instances without library. Added one more widget in the widget library. Renamed "view_name" in "name" in commands substitutions.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3289
diff
changeset
|
701 |
raise Exception("SVGHMI {name}: only one watchdog allowed") |
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
702 |
|
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
703 |
|
2993
b76f303ffce6
Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents:
2984
diff
changeset
|
704 |
def _runtime_{location}_svghmi_stop(): |
3647
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
705 |
global svghmi_watchdog, svghmi_servers, browser_proc |
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
706 |
|
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
707 |
if svghmi_watchdog is not None: |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
708 |
svghmi_watchdog.cancel() |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
709 |
svghmi_watchdog = None |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
710 |
|
3269
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
711 |
svghmi_root, svghmi_listener, path_list = svghmi_servers["{interface}:{port}"] |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
712 |
svghmi_root.delEntity('{path}') |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
713 |
|
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
714 |
path_list.remove('{path}') |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
715 |
|
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
716 |
if len(path_list)==0: |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
717 |
svghmi_root.delEntity("ws") |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
718 |
svghmi_listener.stopListening() |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
719 |
svghmi_servers.pop("{interface}:{port}") |
5d174cdf4d98
SVGHMI: More configuration parameters : network interface, TCP port, URL path and watchdog enabling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3267
diff
changeset
|
720 |
|
3647
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
721 |
stop_proc = {svghmi_cmds[Stop]} |
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
722 |
waitpid_timeout(stop_proc, "SVGHMI stop command") |
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
723 |
waitpid_timeout(browser_proc, "SVGHMI browser process") |
7c427418396f
SVGHMI: prevent browser and watchdog commands to become zombie once finished.
Edouard Tisserant
parents:
3499
diff
changeset
|
724 |
browser_proc = None |
2824
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
725 |
|
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
726 |
""".format(location=location_str, |
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
727 |
xhtml=target_fname, |
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
728 |
svghmi_cmds=svghmi_cmds, |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
729 |
watchdog_initial = self.GetParamsAttributes("SVGHMI.WatchdogInitial")["value"], |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
730 |
watchdog_interval = self.GetParamsAttributes("SVGHMI.WatchdogInterval")["value"], |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
3269
diff
changeset
|
731 |
maxConnections = self.GetParamsAttributes("SVGHMI.MaxConnections")["value"], |
3286
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
732 |
maxConnections_total = maxConnectionsTotal, |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
733 |
**svghmi_options |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
734 |
)) |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
735 |
|
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
736 |
runtimefile.close() |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
737 |
|
2993
b76f303ffce6
Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents:
2984
diff
changeset
|
738 |
res += (("runtime_%s_svghmi.py" % location_str, open(runtimefile_path, "rb")),) |
2745 | 739 |
|
740 |
return res |
|
741 |
||
742 |
def _ImportSVG(self): |
|
3572
b46af5b80c7d
IDE: wxPython4 consequences : wx.OPEN -> wx.FD_OPEN
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3526
diff
changeset
|
743 |
dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a SVG file"), os.getcwd(), "", _("SVG files (*.svg)|*.svg|All files|*.*"), wx.FD_OPEN) |
2745 | 744 |
if dialog.ShowModal() == wx.ID_OK: |
745 |
svgpath = dialog.GetPath() |
|
746 |
if os.path.isfile(svgpath): |
|
747 |
shutil.copy(svgpath, self._getSVGpath()) |
|
748 |
else: |
|
749 |
self.GetCTRoot().logger.write_error(_("No such SVG file: %s\n") % svgpath) |
|
750 |
dialog.Destroy() |
|
751 |
||
3286
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
752 |
def getDefaultSVG(self): |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
753 |
return os.path.join(ScriptDirectory, "default.svg") |
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
754 |
|
2745 | 755 |
def _StartInkscape(self): |
756 |
svgfile = self._getSVGpath() |
|
757 |
open_inkscape = True |
|
758 |
if not self.GetCTRoot().CheckProjectPathPerm(): |
|
759 |
dialog = wx.MessageDialog(self.GetCTRoot().AppFrame, |
|
760 |
_("You don't have write permissions.\nOpen Inkscape anyway ?"), |
|
761 |
_("Open Inkscape"), |
|
762 |
wx.YES_NO | wx.ICON_QUESTION) |
|
763 |
open_inkscape = dialog.ShowModal() == wx.ID_YES |
|
764 |
dialog.Destroy() |
|
765 |
if open_inkscape: |
|
766 |
if not os.path.isfile(svgfile): |
|
3274
16066300b254
SVGHMI: default library path, default page when starting a SVGHMI project, error page when no SVG present
Edouard Tisserant
parents:
3270
diff
changeset
|
767 |
# make a copy of default svg from source |
3286
5a135e635bfa
SVGHMI: code refactoring allowing more in depth customization for substitution on start/stop/restart commands, and default SVG choice.
Edouard Tisserant
parents:
3277
diff
changeset
|
768 |
default = self.getDefaultSVG() |
3274
16066300b254
SVGHMI: default library path, default page when starting a SVGHMI project, error page when no SVG present
Edouard Tisserant
parents:
3270
diff
changeset
|
769 |
shutil.copyfile(default, svgfile) |
2745 | 770 |
open_svg(svgfile) |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
771 |
|
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
772 |
def _StartPOEdit(self, POFile): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
773 |
open_poedit = True |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
774 |
if not self.GetCTRoot().CheckProjectPathPerm(): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
775 |
dialog = wx.MessageDialog(self.GetCTRoot().AppFrame, |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
776 |
_("You don't have write permissions.\nOpen POEdit anyway ?"), |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
777 |
_("Open POEdit"), |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
778 |
wx.YES_NO | wx.ICON_QUESTION) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
779 |
open_poedit = dialog.ShowModal() == wx.ID_YES |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
780 |
dialog.Destroy() |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
781 |
if open_poedit: |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
782 |
open_pofile(POFile) |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
783 |
|
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
784 |
def _EditPO(self): |
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
785 |
""" Select a specific translation and edit it with POEdit """ |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
786 |
project_path = self.CTNPath() |
3572
b46af5b80c7d
IDE: wxPython4 consequences : wx.OPEN -> wx.FD_OPEN
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3526
diff
changeset
|
787 |
dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a PO file"), project_path, "", _("PO files (*.po)|*.po"), wx.FD_OPEN) |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
788 |
if dialog.ShowModal() == wx.ID_OK: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
789 |
POFile = dialog.GetPath() |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
790 |
if os.path.isfile(POFile): |
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
791 |
if os.path.relpath(POFile, project_path) == os.path.basename(POFile): |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
792 |
self._StartPOEdit(POFile) |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
793 |
else: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
794 |
self.GetCTRoot().logger.write_error(_("PO file misplaced: %s is not in %s\n") % (POFile,project_path)) |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
795 |
else: |
3158
4171f7dd109a
SVGHMI: Fixed/extended error message when failing to launch POEdit.
Edouard Tisserant
parents:
3140
diff
changeset
|
796 |
self.GetCTRoot().logger.write_error(_("PO file does not exist: %s\n") % POFile) |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
797 |
dialog.Destroy() |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
798 |
|
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
799 |
def _OpenPOT(self): |
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
800 |
""" Start POEdit with untouched empty catalog """ |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
801 |
POFile = self._getPOTpath() |
3158
4171f7dd109a
SVGHMI: Fixed/extended error message when failing to launch POEdit.
Edouard Tisserant
parents:
3140
diff
changeset
|
802 |
if os.path.isfile(POFile): |
4171f7dd109a
SVGHMI: Fixed/extended error message when failing to launch POEdit.
Edouard Tisserant
parents:
3140
diff
changeset
|
803 |
self._StartPOEdit(POFile) |
4171f7dd109a
SVGHMI: Fixed/extended error message when failing to launch POEdit.
Edouard Tisserant
parents:
3140
diff
changeset
|
804 |
else: |
4171f7dd109a
SVGHMI: Fixed/extended error message when failing to launch POEdit.
Edouard Tisserant
parents:
3140
diff
changeset
|
805 |
self.GetCTRoot().logger.write_error(_("POT file does not exist, add translatable text (label starting with '_') in Inkscape first\n")) |
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3068
diff
changeset
|
806 |
|
3210
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
807 |
def _AddFont(self): |
3211
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
808 |
dialog = wx.FileDialog( |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
809 |
self.GetCTRoot().AppFrame, |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
810 |
_("Choose a font"), |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
811 |
os.path.expanduser("~"), |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
812 |
"", |
3572
b46af5b80c7d
IDE: wxPython4 consequences : wx.OPEN -> wx.FD_OPEN
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3526
diff
changeset
|
813 |
_("Font files (*.ttf;*.otf;*.woff;*.woff2)|*.ttf;*.otf;*.woff;*.woff2"), wx.FD_OPEN) |
3211
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
814 |
|
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
815 |
if dialog.ShowModal() == wx.ID_OK: |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
816 |
fontfile = dialog.GetPath() |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
817 |
if os.path.isfile(fontfile): |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
818 |
familyname, uniquename, formatname, mimetype = GetFontTypeAndFamilyName(fontfile) |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
819 |
else: |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
820 |
self.GetCTRoot().logger.write_error( |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
821 |
_('Selected font %s is not a readable file\n')%fontfile) |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
822 |
return |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
823 |
if familyname is None or uniquename is None or formatname is None or mimetype is None: |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
824 |
self.GetCTRoot().logger.write_error( |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
825 |
_('Selected font file %s is invalid or incompatible\n')%fontfile) |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
826 |
return |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
827 |
|
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
828 |
project_path = self.CTNPath() |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
829 |
|
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
830 |
fontfname = uniquename + "." + mimetype.split('/')[1] |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
831 |
fontdir = os.path.join(project_path, "fonts") |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
832 |
newfontfile = os.path.join(fontdir, fontfname) |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
833 |
|
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
834 |
if not os.path.exists(fontdir): |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
835 |
os.mkdir(fontdir) |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
836 |
|
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
837 |
shutil.copyfile(fontfile, newfontfile) |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
838 |
|
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
839 |
self.GetCTRoot().logger.write( |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
840 |
_('Added font %s as %s\n')%(fontfile,newfontfile)) |
3210
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
841 |
|
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
842 |
def _DelFont(self): |
3211
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
843 |
project_path = self.CTNPath() |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
844 |
fontdir = os.path.join(project_path, "fonts") |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
845 |
dialog = wx.FileDialog( |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
846 |
self.GetCTRoot().AppFrame, |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
847 |
_("Choose a font to remove"), |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
848 |
fontdir, |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
849 |
"", |
3572
b46af5b80c7d
IDE: wxPython4 consequences : wx.OPEN -> wx.FD_OPEN
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3526
diff
changeset
|
850 |
_("Font files (*.ttf;*.otf;*.woff;*.woff2)|*.ttf;*.otf;*.woff;*.woff2"), wx.FD_OPEN) |
3211
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
851 |
if dialog.ShowModal() == wx.ID_OK: |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
852 |
fontfile = dialog.GetPath() |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
853 |
if os.path.isfile(fontfile): |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
854 |
if os.path.relpath(fontfile, fontdir) == os.path.basename(fontfile): |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
855 |
os.remove(fontfile) |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
856 |
self.GetCTRoot().logger.write( |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
857 |
_('Removed font %s\n')%fontfile) |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
858 |
else: |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
859 |
self.GetCTRoot().logger.write_error( |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
860 |
_("Font to remove %s is not in %s\n") % (fontfile,fontdir)) |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
861 |
else: |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
862 |
self.GetCTRoot().logger.write_error( |
938b55abe946
SVGHMI: Implemented "Add Font" and "Remove Font", add font embedding in CSS at build time, tested ok with some OTF for now.
Edouard Tisserant
parents:
3210
diff
changeset
|
863 |
_("Font file does not exist: %s\n") % fontfile) |
3210
0ddefd20ca2b
SVGHMI: Add font management buttons and icons, doing nothing for now
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
864 |
|
3381
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
865 |
def CTNGlobalInstances(self): |
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
866 |
location_str = "_".join(map(str, self.GetCurrentLocation())) |
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
867 |
return [("CURRENT_PAGE_"+location_str, "HMI_STRING", "")] |
3a0908b0319d
SVGHMI: add CURRENT_PAGE_{location} global variable to reflect currently visible page. If PLC wites some valid page reference in that variable, it triggers page switch. Additionally, fixed /HEARTBEAT being subscribed systematically by JS code even when wtchdog is not enabled.
Edouard Tisserant
parents:
3375
diff
changeset
|
868 |
|
3267
5f20f391ae31
SVGHMI: Prepare accepting multiple clients on multiple HMI: Use POULibrary new capability to add variables to PLC Configuration. Now heartbeat and HMI tree root are added by the library part of SVGHMI, and not by each instance.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3218
diff
changeset
|
869 |
## In case one day we support more than one heartbeat |
5f20f391ae31
SVGHMI: Prepare accepting multiple clients on multiple HMI: Use POULibrary new capability to add variables to PLC Configuration. Now heartbeat and HMI tree root are added by the library part of SVGHMI, and not by each instance.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3218
diff
changeset
|
870 |
# view_name = self.BaseParams.getName() |
5f20f391ae31
SVGHMI: Prepare accepting multiple clients on multiple HMI: Use POULibrary new capability to add variables to PLC Configuration. Now heartbeat and HMI tree root are added by the library part of SVGHMI, and not by each instance.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3218
diff
changeset
|
871 |
# return [(view_name + "_HEARTBEAT", "HMI_INT", "")] |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
872 |
|
3159 | 873 |
def GetIconName(self): |
874 |
return "SVGHMI" |