author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Thu, 25 Mar 2021 13:08:19 +0100 | |
branch | svghmi |
changeset 3202 | 5d379934d5c9 |
parent 3201 | 6dadc1690284 |
child 3208 | b5330d76e225 |
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 |
2745 | 13 |
|
14 |
import wx |
|
2816 | 15 |
|
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
|
16 |
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
|
17 |
from docutil import get_inkscape_path |
2745 | 18 |
|
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
|
19 |
from util.ProcessLogger import ProcessLogger |
2816 | 20 |
|
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
|
21 |
def SVGHMIEditorUpdater(ref): |
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 |
def SVGHMIEditorUpdate(): |
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
|
23 |
o = ref() |
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
|
24 |
if o 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
|
25 |
wx.CallAfter(o.MakeTree) |
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
|
26 |
return SVGHMIEditorUpdate |
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
|
27 |
|
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
28 |
class HMITreeSelector(wx.TreeCtrl): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
29 |
def __init__(self, parent): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
30 |
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
|
31 |
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
|
32 |
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
|
33 |
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
|
34 |
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
|
35 |
wx.TR_LINES_AT_ROOT)) |
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
36 |
|
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
|
37 |
on_hmitree_update = SVGHMIEditorUpdater(weakref.ref(self)) |
2818
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) |
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
|
46 |
self.SetPyData(tc_child, None) # TODO |
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) |
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
|
52 |
self.SetPyData(tc_child, None) # TODO |
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) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
64 |
self.SetPyData(self.root, None) |
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 |
|
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
|
145 |
sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=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
|
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) |
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
|
150 |
self.preview = wx.Panel(self, size=(-1, _preview_height + 10)) #, style=wx.SIMPLE_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
|
151 |
#self.preview.SetBackgroundColour(wx.WHITE) |
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
|
152 |
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
|
153 |
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
|
154 |
sizer.AddWindow(self.preview, 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.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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
self.preview.Bind(wx.EVT_PAINT, self.OnPaint) |
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 |
|
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.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
|
163 |
|
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 |
self.msg = _("Drag selected Widget from here to Inkscape") |
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 |
|
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 |
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
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
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
|
172 |
|
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 |
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
|
174 |
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
|
175 |
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
|
176 |
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
|
177 |
|
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 |
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
|
179 |
""" |
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 |
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
|
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 |
# 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
|
183 |
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
|
184 |
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
|
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 |
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
|
187 |
# 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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
|
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 |
if self.msg: |
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 |
dc.SetFont(self.GetFont()) |
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.DrawText(self.msg, 25,25) |
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 |
|
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
|
196 |
|
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 |
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
|
198 |
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
|
199 |
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
|
200 |
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
|
201 |
|
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 |
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
|
203 |
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
|
204 |
|
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 |
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
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
|
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 |
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
|
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 |
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
|
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 |
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
|
215 |
@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
|
216 |
""" |
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 |
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
|
218 |
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
|
219 |
|
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 |
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
|
221 |
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
|
222 |
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
|
223 |
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
|
224 |
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
|
225 |
# 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
|
226 |
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
|
227 |
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
|
228 |
'"' + 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
|
229 |
'" -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
|
230 |
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
|
231 |
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
|
232 |
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
|
233 |
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
|
234 |
|
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 |
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
|
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 |
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
|
238 |
@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
|
239 |
""" |
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 |
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
|
241 |
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
|
242 |
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
|
243 |
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
|
244 |
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
|
245 |
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
|
246 |
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
|
247 |
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
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
|
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 |
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
|
259 |
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
|
260 |
|
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 |
if not have_thumb: |
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
|
262 |
try: |
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
|
263 |
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
|
264 |
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
|
265 |
except IOError: |
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 |
self.msg = _("Widget library must be writable") |
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 |
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
|
268 |
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
|
269 |
|
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
|
270 |
self.bmp = wx.Bitmap(thumbpath) if have_thumb else 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
|
271 |
|
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
|
272 |
self.selected_SVG = svgpath if have_thumb else 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
|
273 |
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
|
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 |
|
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
|
278 |
def OnHMITreeNodeSelection(self, hmitree_node): |
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
|
279 |
self.hmitree_node = hmitree_node |
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 |
|
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
|
283 |
def ValidateWidget(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
|
284 |
if self.selected_SVG 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
|
285 |
if self.hmitree_node 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
|
286 |
pass |
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
|
287 |
# XXX TODO: |
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
|
288 |
# - check SVG is valid for selected HMI tree item |
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
|
289 |
# - prepare for D'n'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
|
290 |
|
2816 | 291 |
|
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
|
292 |
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
|
293 |
|
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
|
294 |
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
|
295 |
wx.SplitterWindow.__init__(self, parent, |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
296 |
style=wx.SUNKEN_BORDER | wx.SP_3D) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
297 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
register_for_HMI_tree_updates(weakref.ref(self)) |
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
|
302 |
|
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
|
303 |
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
|
304 |
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
|
305 |