author | Edouard Tisserant |
Mon, 17 May 2021 08:52:38 +0200 | |
branch | svghmi |
changeset 3240 | 5f756332ada1 |
parent 3231 | 5243c2a2f7f8 |
child 3234 | f2bfb047d0e6 |
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 |
||
9 |
from __future__ import absolute_import |
|
10 |
import os |
|
2789 | 11 |
import hashlib |
2816 | 12 |
import weakref |
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
13 |
from tempfile import NamedTemporaryFile |
2745 | 14 |
|
15 |
import wx |
|
2816 | 16 |
|
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
17 |
from lxml import etree |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
18 |
from lxml.etree import XSLTApplyError |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
19 |
from XSLTransform import XSLTransform |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
20 |
|
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
21 |
import util.paths as paths |
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
22 |
from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath |
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
|
23 |
from docutil import get_inkscape_path |
2745 | 24 |
|
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
|
25 |
from util.ProcessLogger import ProcessLogger |
2816 | 26 |
|
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
27 |
ScriptDirectory = paths.AbsDir(__file__) |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
28 |
|
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
29 |
class HMITreeSelector(wx.TreeCtrl): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
30 |
def __init__(self, parent): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
31 |
global on_hmitree_update |
3177
5a8abd549aa8
SVGHMI: Lighter display of HMI Tree, no more icons and use buttons. Auto expand root. Fix loading of HMI tree XML backup (hmiclass attribute wasn't kept).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3176
diff
changeset
|
32 |
wx.TreeCtrl.__init__(self, parent, style=( |
5a8abd549aa8
SVGHMI: Lighter display of HMI Tree, no more icons and use buttons. Auto expand root. Fix loading of HMI tree XML backup (hmiclass attribute wasn't kept).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3176
diff
changeset
|
33 |
wx.TR_MULTIPLE | |
5a8abd549aa8
SVGHMI: Lighter display of HMI Tree, no more icons and use buttons. Auto expand root. Fix loading of HMI tree XML backup (hmiclass attribute wasn't kept).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3176
diff
changeset
|
34 |
wx.TR_HAS_BUTTONS | |
5a8abd549aa8
SVGHMI: Lighter display of HMI Tree, no more icons and use buttons. Auto expand root. Fix loading of HMI tree XML backup (hmiclass attribute wasn't kept).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3176
diff
changeset
|
35 |
wx.SUNKEN_BORDER | |
5a8abd549aa8
SVGHMI: Lighter display of HMI Tree, no more icons and use buttons. Auto expand root. Fix loading of HMI tree XML backup (hmiclass attribute wasn't kept).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3176
diff
changeset
|
36 |
wx.TR_LINES_AT_ROOT)) |
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
37 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
38 |
self.MakeTree() |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
39 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
40 |
def _recurseTree(self, current_hmitree_root, current_tc_root): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
41 |
for c in current_hmitree_root.children: |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
42 |
if hasattr(c, "children"): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
43 |
display_name = ('{} (class={})'.format(c.name, c.hmiclass)) \ |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
44 |
if c.hmiclass is not None else c.name |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
45 |
tc_child = self.AppendItem(current_tc_root, display_name) |
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
46 |
self.SetPyData(tc_child, c) |
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
47 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
48 |
self._recurseTree(c,tc_child) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
49 |
else: |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
50 |
display_name = '{} {}'.format(c.nodetype[4:], c.name) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
51 |
tc_child = self.AppendItem(current_tc_root, display_name) |
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
52 |
self.SetPyData(tc_child, c) |
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
53 |
|
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
|
54 |
def MakeTree(self, hmi_tree_root=None): |
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
55 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
56 |
self.Freeze() |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
57 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
58 |
self.root = None |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
59 |
self.DeleteAllItems() |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
60 |
|
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
61 |
root_display_name = _("Please build to see HMI Tree") \ |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
62 |
if hmi_tree_root is None else "HMI" |
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
63 |
self.root = self.AddRoot(root_display_name) |
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
64 |
self.SetPyData(self.root, hmi_tree_root) |
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
65 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
66 |
if hmi_tree_root is not None: |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
67 |
self._recurseTree(hmi_tree_root, self.root) |
3177
5a8abd549aa8
SVGHMI: Lighter display of HMI Tree, no more icons and use buttons. Auto expand root. Fix loading of HMI tree XML backup (hmiclass attribute wasn't kept).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3176
diff
changeset
|
68 |
self.Expand(self.root) |
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
69 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
70 |
self.Thaw() |
2816 | 71 |
|
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
72 |
class WidgetPicker(wx.TreeCtrl): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
73 |
def __init__(self, parent, initialdir=None): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
74 |
wx.TreeCtrl.__init__(self, parent, style=( |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
75 |
wx.TR_MULTIPLE | |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
76 |
wx.TR_HAS_BUTTONS | |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
77 |
wx.SUNKEN_BORDER | |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
78 |
wx.TR_LINES_AT_ROOT)) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
79 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
80 |
self.MakeTree(initialdir) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
81 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
82 |
def _recurseTree(self, current_dir, current_tc_root, dirlist): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
83 |
""" |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
84 |
recurse through subdirectories, but creates tree nodes |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
85 |
only when (sub)directory conbtains .svg file |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
86 |
""" |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
87 |
res = [] |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
88 |
for f in sorted(os.listdir(current_dir)): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
89 |
p = os.path.join(current_dir,f) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
90 |
if os.path.isdir(p): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
91 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
92 |
r = self._recurseTree(p, current_tc_root, dirlist + [f]) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
93 |
if len(r) > 0 : |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
94 |
res = r |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
95 |
dirlist = [] |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
96 |
current_tc_root = res.pop() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
97 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
98 |
elif os.path.splitext(f)[1].upper() == ".SVG": |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
99 |
if len(dirlist) > 0 : |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
100 |
res = [] |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
101 |
for d in dirlist: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
102 |
current_tc_root = self.AppendItem(current_tc_root, d) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
103 |
res.append(current_tc_root) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
104 |
self.SetPyData(current_tc_root, None) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
105 |
dirlist = [] |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
106 |
res.pop() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
107 |
tc_child = self.AppendItem(current_tc_root, f) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
108 |
self.SetPyData(tc_child, p) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
109 |
return res |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
110 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
111 |
def MakeTree(self, lib_dir = None): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
112 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
113 |
self.Freeze() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
114 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
115 |
self.root = None |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
116 |
self.DeleteAllItems() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
117 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
118 |
root_display_name = _("Please select widget library directory") \ |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
119 |
if lib_dir is None else os.path.basename(lib_dir) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
120 |
self.root = self.AddRoot(root_display_name) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
121 |
self.SetPyData(self.root, None) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
122 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
123 |
if lib_dir is not None: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
124 |
self._recurseTree(lib_dir, self.root, []) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
125 |
self.Expand(self.root) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
126 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
127 |
self.Thaw() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
128 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
129 |
_conf_key = "SVGHMIWidgetLib" |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
130 |
_preview_height = 200 |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
131 |
class WidgetLibBrowser(wx.Panel): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
132 |
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
133 |
size=wx.DefaultSize): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
134 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
135 |
wx.Panel.__init__(self, parent, id, pos, size) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
136 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
137 |
self.bmp = None |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
138 |
self.msg = None |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
139 |
self.hmitree_node = None |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
140 |
self.selected_SVG = None |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
141 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
142 |
self.Config = wx.ConfigBase.Get() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
143 |
self.libdir = self.RecallLibDir() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
144 |
|
3228
80f96db773bd
SVGHMI: Added text box for tranformation feedback aside widget mignature
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3223
diff
changeset
|
145 |
sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=0) |
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
146 |
sizer.AddGrowableCol(0) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
147 |
sizer.AddGrowableRow(1) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
148 |
self.libbutton = wx.Button(self, -1, _("Select SVG widget library")) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
149 |
self.widgetpicker = WidgetPicker(self, self.libdir) |
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
150 |
self.preview = wx.Panel(self, size=(-1, _preview_height + 10)) |
3228
80f96db773bd
SVGHMI: Added text box for tranformation feedback aside widget mignature
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3223
diff
changeset
|
151 |
self.comment = wx.TextCtrl(self, size=wx.Size(-1, 80), |
80f96db773bd
SVGHMI: Added text box for tranformation feedback aside widget mignature
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3223
diff
changeset
|
152 |
style=wx.TE_READONLY | wx.TE_MULTILINE) |
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
153 |
sizer.AddWindow(self.libbutton, flag=wx.GROW) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
154 |
sizer.AddWindow(self.widgetpicker, flag=wx.GROW) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
155 |
sizer.AddWindow(self.preview, flag=wx.GROW) |
3228
80f96db773bd
SVGHMI: Added text box for tranformation feedback aside widget mignature
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3223
diff
changeset
|
156 |
sizer.AddWindow(self.comment, flag=wx.GROW) |
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
157 |
sizer.Layout() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
158 |
self.SetAutoLayout(True) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
159 |
self.SetSizer(sizer) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
160 |
sizer.Fit(self) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
161 |
self.Bind(wx.EVT_BUTTON, self.OnSelectLibDir, self.libbutton) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
162 |
self.preview.Bind(wx.EVT_PAINT, self.OnPaint) |
3213
afef7011f475
SVGHMI: Add file type drag'n'drop to widget picker, for now drops widget's original SVG.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
163 |
self.preview.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) |
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
164 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
165 |
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnWidgetSelection, self.widgetpicker) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
166 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
167 |
self.msg = _("Drag selected Widget from here to Inkscape") |
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
168 |
self.tempf = None |
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
169 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
170 |
def RecallLibDir(self): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
171 |
conf = self.Config.Read(_conf_key) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
172 |
if len(conf) == 0: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
173 |
return None |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
174 |
else: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
175 |
return DecodeFileSystemPath(conf) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
176 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
177 |
def RememberLibDir(self, path): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
178 |
self.Config.Write(_conf_key, |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
179 |
EncodeFileSystemPath(path)) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
180 |
self.Config.Flush() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
181 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
182 |
def DrawPreview(self): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
183 |
""" |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
184 |
Refresh preview panel |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
185 |
""" |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
186 |
# Init preview panel paint device context |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
187 |
dc = wx.PaintDC(self.preview) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
188 |
dc.Clear() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
189 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
190 |
if self.bmp: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
191 |
# Get Preview panel size |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
192 |
sz = self.preview.GetClientSize() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
193 |
w = self.bmp.GetWidth() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
194 |
dc.DrawBitmap(self.bmp, (sz.width - w)/2, 5) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
195 |
|
3228
80f96db773bd
SVGHMI: Added text box for tranformation feedback aside widget mignature
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3223
diff
changeset
|
196 |
self.comment.SetValue(self.msg) |
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
197 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
198 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
199 |
def OnSelectLibDir(self, event): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
200 |
defaultpath = self.RecallLibDir() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
201 |
if defaultpath == None: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
202 |
defaultpath = os.path.expanduser("~") |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
203 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
204 |
dialog = wx.DirDialog(self, _("Choose a widget library"), defaultpath, |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
205 |
style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
206 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
207 |
if dialog.ShowModal() == wx.ID_OK: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
208 |
self.libdir = dialog.GetPath() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
209 |
self.RememberLibDir(self.libdir) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
210 |
self.widgetpicker.MakeTree(self.libdir) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
211 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
212 |
dialog.Destroy() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
213 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
214 |
def OnPaint(self, event): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
215 |
""" |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
216 |
Called when Preview panel needs to be redrawn |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
217 |
@param event: wx.PaintEvent |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
218 |
""" |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
219 |
self.DrawPreview() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
220 |
event.Skip() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
221 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
222 |
def GenThumbnail(self, svgpath, thumbpath): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
223 |
inkpath = get_inkscape_path() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
224 |
if inkpath is None: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
225 |
self.msg = _("Inkscape is not installed.") |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
226 |
return False |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
227 |
# TODO: spawn a thread, to decouple thumbnail gen |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
228 |
status, result, _err_result = ProcessLogger( |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
229 |
None, |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
230 |
'"' + inkpath + '" "' + svgpath + '" -e "' + thumbpath + |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
231 |
'" -D -h ' + str(_preview_height)).spin() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
232 |
if status != 0: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
233 |
self.msg = _("Inkscape couldn't generate thumbnail.") |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
234 |
return False |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
235 |
return True |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
236 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
237 |
def OnWidgetSelection(self, event): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
238 |
""" |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
239 |
Called when tree item is selected |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
240 |
@param event: wx.TreeEvent |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
241 |
""" |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
242 |
item_pydata = self.widgetpicker.GetPyData(event.GetItem()) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
243 |
if item_pydata is not None: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
244 |
svgpath = item_pydata |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
245 |
dname = os.path.dirname(svgpath) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
246 |
fname = os.path.basename(svgpath) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
247 |
hasher = hashlib.new('md5') |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
248 |
with open(svgpath, 'rb') as afile: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
249 |
while True: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
250 |
buf = afile.read(65536) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
251 |
if len(buf) > 0: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
252 |
hasher.update(buf) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
253 |
else: |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
254 |
break |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
255 |
digest = hasher.hexdigest() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
256 |
thumbfname = os.path.splitext(fname)[0]+"_"+digest+".png" |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
257 |
thumbdir = os.path.join(dname, ".svghmithumbs") |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
258 |
thumbpath = os.path.join(thumbdir, thumbfname) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
259 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
260 |
have_thumb = os.path.exists(thumbpath) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
261 |
|
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
262 |
try: |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
263 |
if not have_thumb: |
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
264 |
if not os.path.exists(thumbdir): |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
265 |
os.mkdir(thumbdir) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
266 |
have_thumb = self.GenThumbnail(svgpath, thumbpath) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
267 |
|
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
268 |
self.bmp = wx.Bitmap(thumbpath) if have_thumb else None |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
269 |
|
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
270 |
self.selected_SVG = svgpath if have_thumb else None |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
271 |
self.ValidateWidget() |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
272 |
except IOError: |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
273 |
self.msg = _("Widget library must be writable") |
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
274 |
|
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
275 |
self.Refresh() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
276 |
event.Skip() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
277 |
|
3231
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
278 |
def OnHMITreeNodeSelection(self, hmitree_nodes): |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
279 |
self.hmitree_node = hmitree_nodes[0] if len(hmitree_nodes) else None |
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
280 |
self.ValidateWidget() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
281 |
self.Refresh() |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
282 |
|
3213
afef7011f475
SVGHMI: Add file type drag'n'drop to widget picker, for now drops widget's original SVG.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
283 |
def OnLeftDown(self, evt): |
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
284 |
if self.tempf is not None: |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
285 |
filename = self.tempf.name |
3213
afef7011f475
SVGHMI: Add file type drag'n'drop to widget picker, for now drops widget's original SVG.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
286 |
data = wx.FileDataObject() |
afef7011f475
SVGHMI: Add file type drag'n'drop to widget picker, for now drops widget's original SVG.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
287 |
data.AddFile(filename) |
afef7011f475
SVGHMI: Add file type drag'n'drop to widget picker, for now drops widget's original SVG.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
288 |
dropSource = wx.DropSource(self) |
afef7011f475
SVGHMI: Add file type drag'n'drop to widget picker, for now drops widget's original SVG.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
289 |
dropSource.SetData(data) |
afef7011f475
SVGHMI: Add file type drag'n'drop to widget picker, for now drops widget's original SVG.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
290 |
dropSource.DoDragDrop(wx.Drag_AllowMove) |
afef7011f475
SVGHMI: Add file type drag'n'drop to widget picker, for now drops widget's original SVG.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3208
diff
changeset
|
291 |
|
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
292 |
def GiveDetails(self, _context, msgs): |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
293 |
for msg in msgs: |
3222
6adeeb16ac3e
SVGHMI: Widget DnD to Inkscape : Added source SVG widget label parsing and pass selecte HMI subtree to XSLT tranform, so that SVG containing multiple widgets can later be matched against hmi tree fragments, in order to DnD complex groups of widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3221
diff
changeset
|
294 |
self.msg += msg.text + "\n" |
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
295 |
|
3222
6adeeb16ac3e
SVGHMI: Widget DnD to Inkscape : Added source SVG widget label parsing and pass selecte HMI subtree to XSLT tranform, so that SVG containing multiple widgets can later be matched against hmi tree fragments, in order to DnD complex groups of widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3221
diff
changeset
|
296 |
def GetSubHMITree(self, _context): |
6adeeb16ac3e
SVGHMI: Widget DnD to Inkscape : Added source SVG widget label parsing and pass selecte HMI subtree to XSLT tranform, so that SVG containing multiple widgets can later be matched against hmi tree fragments, in order to DnD complex groups of widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3221
diff
changeset
|
297 |
return [self.hmitree_node.etree()] |
6adeeb16ac3e
SVGHMI: Widget DnD to Inkscape : Added source SVG widget label parsing and pass selecte HMI subtree to XSLT tranform, so that SVG containing multiple widgets can later be matched against hmi tree fragments, in order to DnD complex groups of widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3221
diff
changeset
|
298 |
|
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
299 |
def ValidateWidget(self): |
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
300 |
self.msg = "" |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
301 |
|
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
302 |
if self.tempf is not None: |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
303 |
os.unlink(self.tempf.name) |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
304 |
self.tempf = None |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
305 |
|
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
306 |
try: |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
307 |
if self.selected_SVG is None: |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
308 |
raise Exception(_("No widget selected")) |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
309 |
if self.hmitree_node is None: |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
310 |
raise Exception(_("No HMI tree node selected")) |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
311 |
|
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
312 |
transform = XSLTransform( |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
313 |
os.path.join(ScriptDirectory, "gen_dnd_widget_svg.xslt"), |
3222
6adeeb16ac3e
SVGHMI: Widget DnD to Inkscape : Added source SVG widget label parsing and pass selecte HMI subtree to XSLT tranform, so that SVG containing multiple widgets can later be matched against hmi tree fragments, in order to DnD complex groups of widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3221
diff
changeset
|
314 |
[("GetSubHMITree", self.GetSubHMITree), |
6adeeb16ac3e
SVGHMI: Widget DnD to Inkscape : Added source SVG widget label parsing and pass selecte HMI subtree to XSLT tranform, so that SVG containing multiple widgets can later be matched against hmi tree fragments, in order to DnD complex groups of widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3221
diff
changeset
|
315 |
("GiveDetails", self.GiveDetails)]) |
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
316 |
|
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
317 |
svgdom = etree.parse(self.selected_SVG) |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
318 |
|
3223
061796d9855e
SVGHMI: Widget transform before DnD now should have HMI path as a parameter, but this path isn't computed for some reason... WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3222
diff
changeset
|
319 |
result = transform.transform( |
061796d9855e
SVGHMI: Widget transform before DnD now should have HMI path as a parameter, but this path isn't computed for some reason... WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3222
diff
changeset
|
320 |
svgdom, hmi_path = self.hmitree_node.hmi_path()) |
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
321 |
|
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
322 |
for entry in transform.get_error_log(): |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
323 |
self.msg += "XSLT: " + entry.message + "\n" |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
324 |
|
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
325 |
self.tempf = NamedTemporaryFile(suffix='.svg', delete=False) |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
326 |
result.write(self.tempf, encoding="utf-8") |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
327 |
self.tempf.close() |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
328 |
|
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
329 |
except Exception as e: |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
330 |
self.msg += str(e) |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
331 |
except XSLTApplyError as e: |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
332 |
self.msg += "Widget transform error: " + e.message |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
333 |
|
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
334 |
def __del__(self): |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
335 |
if self.tempf is not None: |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
336 |
os.unlink(self.tempf.name) |
2816 | 337 |
|
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
|
338 |
class SVGHMI_UI(wx.SplitterWindow): |
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
|
339 |
|
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
|
340 |
def __init__(self, parent, register_for_HMI_tree_updates): |
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
341 |
wx.SplitterWindow.__init__(self, parent, |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
342 |
style=wx.SUNKEN_BORDER | wx.SP_3D) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
343 |
|
3231
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
344 |
self.ordered_items = [] |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
345 |
|
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
346 |
self.SelectionTree = HMITreeSelector(self) |
3193
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
347 |
self.Staging = WidgetLibBrowser(self) |
8006bb60a4dd
SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3180
diff
changeset
|
348 |
self.SplitVertically(self.SelectionTree, self.Staging, 300) |
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
|
349 |
register_for_HMI_tree_updates(weakref.ref(self)) |
3221
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
350 |
self.Bind(wx.EVT_TREE_SEL_CHANGED, |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
351 |
self.OnHMITreeNodeSelection, self.SelectionTree) |
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
352 |
|
3d307ad803ea
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3213
diff
changeset
|
353 |
def OnHMITreeNodeSelection(self, event): |
3231
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
354 |
items = self.SelectionTree.GetSelections() |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
355 |
items_pydata = [self.SelectionTree.GetPyData(item) for item in items] |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
356 |
|
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
357 |
# append new items to ordered item list |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
358 |
for item_pydata in items_pydata: |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
359 |
if item_pydata not in self.ordered_items: |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
360 |
self.ordered_items.append(item_pydata) |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
361 |
|
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
362 |
# filter out vanished items |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
363 |
self.ordered_items = [ |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
364 |
item_pydata |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
365 |
for item_pydata in self.ordered_items |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
366 |
if item_pydata in items_pydata] |
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
367 |
|
5243c2a2f7f8
SVGHMI: keep track of order of selection in HMI tree, so that variable can be passed in same order to DnD widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3228
diff
changeset
|
368 |
self.Staging.OnHMITreeNodeSelection(items_pydata) |
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
|
369 |
|
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
|
370 |
def HMITreeUpdate(self, 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
|
371 |
self.SelectionTree.MakeTree(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
|
372 |