svghmi/ui.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Wed, 09 Jun 2021 10:06:23 +0200
branchsvghmi
changeset 3251 6d4ff271ebf1
parent 3250 22da8e0b07b8
child 3252 352b2111ca66
child 3253 9233e60a8317
permissions -rw-r--r--
SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
2745
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
     3
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
     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
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
     6
#
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
     7
# See COPYING file for copyrights details.
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
     8
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
     9
from __future__ import absolute_import
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
    10
import os
2789
ba0dd2ec6dc4 SVGHMI: now built.
Edouard Tisserant
parents: 2788
diff changeset
    11
import hashlib
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
    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
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
    14
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
    15
import wx
3245
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
    16
from wx.lib.scrolledpanel import ScrolledPanel
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
    17
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
    18
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
    19
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
    20
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
    21
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
    22
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
    23
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
    24
from docutil import get_inkscape_path
2745
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
    25
2756
f94bc35a023e SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents: 2753
diff changeset
    26
from util.ProcessLogger import ProcessLogger
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
    27
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
    28
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
    29
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    30
HMITreeDndMagicWord = "text/beremiz-hmitree"
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    31
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    32
class HMITreeSelector(wx.TreeCtrl):
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    33
    def __init__(self, parent):
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    34
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
    35
        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
    36
            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
    37
            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
    38
            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
    39
            wx.TR_LINES_AT_ROOT))
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    40
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    41
        self.ordered_items = []
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    42
        self.parent = parent
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    43
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    44
        self.MakeTree()
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    45
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    46
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeNodeSelection)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    47
        self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnTreeBeginDrag)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    48
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    49
    def _recurseTree(self, current_hmitree_root, current_tc_root):
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    50
        for c in current_hmitree_root.children:
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    51
            if hasattr(c, "children"):
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    52
                display_name = ('{} (class={})'.format(c.name, c.hmiclass)) \
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    53
                               if c.hmiclass is not None else c.name
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    54
                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
    55
                self.SetPyData(tc_child, c)
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    56
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    57
                self._recurseTree(c,tc_child)
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    58
            else:
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    59
                display_name = '{} {}'.format(c.nodetype[4:], c.name)
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    60
                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
    61
                self.SetPyData(tc_child, c)
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    62
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    63
    def OnTreeNodeSelection(self, event):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    64
        items = self.GetSelections()
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    65
        items_pydata = [self.GetPyData(item) for item in items]
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    66
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    67
        # append new items to ordered item list
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    68
        for item_pydata in items_pydata:
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    69
            if item_pydata not in self.ordered_items:
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    70
                self.ordered_items.append(item_pydata)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    71
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    72
        # filter out vanished items
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    73
        self.ordered_items = [
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    74
            item_pydata 
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    75
            for item_pydata in self.ordered_items 
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    76
            if item_pydata in items_pydata]
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    77
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    78
        self.parent.OnHMITreeNodeSelection(self.ordered_items)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    79
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    80
    def OnTreeBeginDrag(self, event):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    81
        """
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    82
        Called when a drag is started in tree
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    83
        @param event: wx.TreeEvent
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    84
        """
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    85
        if self.ordered_items:
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    86
            print("boink")
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    87
            # Just send a recognizable mime-type, drop destination
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    88
            # will get python data from parent
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    89
            data = wx.CustomDataObject(HMITreeDndMagicWord)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    90
            dragSource = wx.DropSource(self)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    91
            dragSource.SetData(data)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    92
            dragSource.DoDragDrop()
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
    93
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
    94
    def MakeTree(self, hmi_tree_root=None):
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    95
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    96
        self.Freeze()
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    97
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    98
        self.root = None
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    99
        self.DeleteAllItems()
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   100
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
   101
        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
   102
            if hmi_tree_root is None else "HMI"
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   103
        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
   104
        self.SetPyData(self.root, hmi_tree_root)
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   105
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   106
        if hmi_tree_root is not None:
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   107
            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
   108
            self.Expand(self.root)
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   109
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   110
        self.Thaw()
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
   111
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
   112
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
   113
    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
   114
        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
   115
            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
   116
            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
   117
            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
   118
            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
   119
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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.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
   121
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
    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
   123
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        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
   125
        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
   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
        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
   128
        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
   129
            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
   130
            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
   131
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
                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
   133
                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
   134
                    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
   135
                    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
   136
                    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
   137
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
            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
   139
                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
   140
                    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
   141
                    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
   142
                        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
   143
                        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
   144
                        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
   145
                    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
   146
                    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
   147
                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
   148
                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
   149
        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
   150
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
    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
   152
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        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
   154
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        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
   156
        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
   157
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        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
   159
            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
   160
        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
   161
        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
   162
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        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
   164
            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
   165
            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
   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.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
   168
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   169
class PathDropTarget(wx.DropTarget):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   170
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   171
    def __init__(self, parent):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   172
        data = wx.CustomDataObject(HMITreeDndMagicWord)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   173
        wx.DropTarget.__init__(self, data)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   174
        self.ParentWindow = parent
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   175
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   176
    def OnDrop(self, x, y):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   177
        self.ParentWindow.OnHMITreeDnD()
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   178
        return True
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   179
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   180
class ParamEditor(wx.Panel):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   181
    def __init__(self, parent, paramdesc):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   182
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   183
        wx.Panel.__init__(self, parent.main_panel)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   184
        label = paramdesc.get("name")+ ": " + paramdesc.get("accepts") 
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   185
        if paramdesc.text:
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   186
            label += "\n\"" + paramdesc.text + "\""
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   187
        self.desc = wx.StaticText(self, label=label)
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   188
        self.valid_bmp = wx.ArtProvider.GetBitmap(wx.ART_TICK_MARK, wx.ART_TOOLBAR, (16,16))
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   189
        self.invalid_bmp = wx.ArtProvider.GetBitmap(wx.ART_CROSS_MARK, wx.ART_TOOLBAR, (16,16))
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   190
        self.validity_sbmp = wx.StaticBitmap(self, -1, self.invalid_bmp)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   191
        self.edit = wx.TextCtrl(self)
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   192
        self.edit_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   193
        self.edit_sizer.AddGrowableCol(0)
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   194
        self.edit_sizer.AddGrowableRow(0)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   195
        self.edit_sizer.Add(self.edit, flag=wx.GROW)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   196
        self.edit_sizer.Add(self.validity_sbmp, flag=wx.GROW)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   197
        self.main_sizer = wx.BoxSizer(wx.VERTICAL)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   198
        self.main_sizer.Add(self.desc, flag=wx.GROW)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   199
        self.main_sizer.Add(self.edit_sizer, flag=wx.GROW)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   200
        self.SetSizer(self.main_sizer)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   201
        self.main_sizer.Fit(self)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   202
3251
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   203
    def setValidityNOK(self):
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   204
        self.validity_sbmp.SetBitmap(self.invalid_bmp)
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   205
        self.validity_sbmp.Show(True)
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   206
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   207
    def setValidityOK(self):
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   208
        self.validity_sbmp.SetBitmap(self.valid_bmp)
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   209
        self.validity_sbmp.Show(True)
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   210
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   211
    def setValidityUnknown(self):
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   212
        self.validity_sbmp.Show(False)
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   213
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   214
class ArgEditor(ParamEditor):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   215
    pass
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   216
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   217
class PathEditor(ParamEditor):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   218
    def __init__(self, parent, pathdesc):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   219
        ParamEditor.__init__(self, parent, pathdesc)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   220
        self.ParentObj = parent
3251
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   221
        self.pathdesc = pathdesc
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   222
        DropTarget = PathDropTarget(self)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   223
        self.edit.SetDropTarget(DropTarget)
3251
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   224
        self.Bind(wx.EVT_TEXT, self.OnPathChanged, self.edit)
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   225
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   226
    def OnHMITreeDnD(self):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   227
        self.ParentObj.GotPathDnDOn(self)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   228
3251
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   229
    def SetPath(self, hmitree_node):
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   230
        self.edit.ChangeValue(hmitree_node.hmi_path())
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   231
        if hmitree_node.nodetype in self.pathdesc.get("accepts").split(","):
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   232
            self.setValidityOK()
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   233
        else:
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   234
            self.setValidityNOK()
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   235
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   236
    def OnPathChanged(self, event):
3251
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   237
        # TODO : find corresponding hmitre node and type to update validity
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   238
        # Lazy way : hide validity
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   239
        self.setValidityUnknown()
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   240
        event.Skip()
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   241
    
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   242
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
   243
_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
   244
_preview_height = 200
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   245
_preview_margin = 5
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   246
class WidgetLibBrowser(wx.SplitterWindow):
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
   247
    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
   248
                 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
   249
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   250
        wx.SplitterWindow.__init__(self, parent,
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   251
                                   style=wx.SUNKEN_BORDER | wx.SP_3D)
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
   252
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        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
   254
        self.msg = None
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   255
        self.hmitree_nodes = []
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
   256
        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
   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.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
   259
        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
   260
3245
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   261
        self.picker_desc_splitter = wx.SplitterWindow(self, style=wx.SUNKEN_BORDER | wx.SP_3D)
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   262
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   263
        self.picker_panel = wx.Panel(self.picker_desc_splitter)
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   264
        self.picker_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   265
        self.picker_sizer.AddGrowableCol(0)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   266
        self.picker_sizer.AddGrowableRow(1)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   267
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   268
        self.widgetpicker = WidgetPicker(self.picker_panel, self.libdir)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   269
        self.libbutton = wx.Button(self.picker_panel, -1, _("Select SVG widget library"))
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   270
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   271
        self.picker_sizer.Add(self.libbutton, flag=wx.GROW)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   272
        self.picker_sizer.Add(self.widgetpicker, flag=wx.GROW)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   273
        self.picker_sizer.Layout()
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   274
        self.picker_panel.SetAutoLayout(True)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   275
        self.picker_panel.SetSizer(self.picker_sizer)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   276
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   277
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnWidgetSelection, self.widgetpicker)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   278
        self.Bind(wx.EVT_BUTTON, self.OnSelectLibDir, self.libbutton)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   279
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   280
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   281
3245
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   282
        self.main_panel = ScrolledPanel(parent=self,
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   283
                                                name='MiscellaneousPanel',
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   284
                                                style=wx.TAB_TRAVERSAL)
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   285
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   286
        self.main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=0)
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   287
        self.main_sizer.AddGrowableCol(0)
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   288
        self.main_sizer.AddGrowableRow(2)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   289
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   290
        self.staticmsg = wx.StaticText(self, label = _("Drag selected Widget from here to Inkscape"))
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   291
        self.preview = wx.Panel(self.main_panel, size=(-1, _preview_height + _preview_margin*2))
3237
d000a91d1e95 SVGHMI: Intermediate state while updating UI, preparing for displaying widget description and multiple variables selections
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3235
diff changeset
   292
        self.signature_sizer = wx.BoxSizer(wx.VERTICAL)
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   293
        self.args_box = wx.StaticBox(self.main_panel, -1,
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   294
                                     _("Widget's arguments"),
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   295
                                     style = wx.ALIGN_RIGHT)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   296
        self.args_sizer = wx.StaticBoxSizer(self.args_box, wx.VERTICAL)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   297
        self.paths_box = wx.StaticBox(self.main_panel, -1,
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   298
                                      _("Widget's variables"),
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   299
                                      style = wx.ALIGN_RIGHT)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   300
        self.paths_sizer = wx.StaticBoxSizer(self.paths_box, wx.VERTICAL)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   301
        self.signature_sizer.Add(self.args_sizer, flag=wx.GROW)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   302
        self.signature_sizer.AddSpacer(5)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   303
        self.signature_sizer.Add(self.paths_sizer, flag=wx.GROW)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   304
        self.main_sizer.Add(self.staticmsg, flag=wx.GROW)
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   305
        self.main_sizer.Add(self.preview, flag=wx.GROW)
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   306
        self.main_sizer.Add(self.signature_sizer, flag=wx.GROW)
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   307
        self.main_sizer.Layout()
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   308
        self.main_panel.SetAutoLayout(True)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   309
        self.main_panel.SetSizer(self.main_sizer)
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   310
        self.main_sizer.Fit(self.main_panel)
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
   311
        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
   312
        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
   313
3245
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   314
        self.desc = wx.TextCtrl(self.picker_desc_splitter, size=wx.Size(-1, 160),
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   315
                                   style=wx.TE_READONLY | wx.TE_MULTILINE)
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   316
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   317
        self.picker_desc_splitter.SplitHorizontally(self.picker_panel, self.desc, 400)
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   318
        self.SplitVertically(self.main_panel, self.picker_desc_splitter, 300)
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
   319
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
   320
        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
   321
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   322
        self.args_editors = []
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   323
        self.paths_editors = []
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   324
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   325
    def ResetSignature(self):
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   326
        self.args_sizer.Clear()
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   327
        for editor in self.args_editors:
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   328
            editor.Destroy()
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   329
        self.args_editors = []
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   330
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   331
        self.paths_sizer.Clear()
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   332
        for editor in self.paths_editors:
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   333
            editor.Destroy()
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   334
        self.paths_editors = []
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   335
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   336
    def AddArgToSignature(self, arg):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   337
        new_editor = ArgEditor(self, arg)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   338
        self.args_editors.append(new_editor)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   339
        self.args_sizer.Add(new_editor, flag=wx.GROW)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   340
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   341
    def AddPathToSignature(self, path):
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   342
        new_editor = PathEditor(self, path)
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   343
        self.paths_editors.append(new_editor)
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   344
        self.paths_sizer.Add(new_editor, flag=wx.GROW)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   345
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   346
    def GotPathDnDOn(self, target_editor):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   347
        dndindex = self.paths_editors.index(target_editor)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   348
3251
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   349
        for hmitree_node,editor in zip(self.hmitree_nodes,
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   350
                                   self.paths_editors[dndindex:]):
3251
6d4ff271ebf1 SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3250
diff changeset
   351
            editor.SetPath(hmitree_node)
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   352
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
   353
    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
   354
        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
   355
        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
   356
            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
   357
        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
   358
            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
   359
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   360
    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
   361
        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
   362
                          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
   363
        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
   364
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   365
    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
   366
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   367
        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
   368
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   369
        # 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
   370
        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
   371
        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
   372
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   373
        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
   374
            # 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
   375
            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
   376
            w = self.bmp.GetWidth()
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   377
            dc.DrawBitmap(self.bmp, (sz.width - w)/2, _preview_margin)
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
   378
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   379
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   380
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   381
    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
   382
        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
   383
        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
   384
            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
   385
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   386
        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
   387
                              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
   388
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   389
        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
   390
            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
   391
            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
   392
            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
   393
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   394
        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
   395
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   396
    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
   397
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   398
        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
   399
        @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
   400
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   401
        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
   402
        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
   403
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   404
    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
   405
        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
   406
        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
   407
            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
   408
            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
   409
        # 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
   410
        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
   411
            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
   412
            '"' + 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
   413
            '" -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
   414
        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
   415
            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
   416
            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
   417
        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
   418
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   419
    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
   420
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   421
        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
   422
        @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
   423
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   424
        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
   425
        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
   426
            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
   427
            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
   428
            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
   429
            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
   430
            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
   431
                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
   432
                    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
   433
                    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
   434
                        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
   435
                    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
   436
                        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
   437
            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
   438
            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
   439
            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
   440
            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
   441
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   442
            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
   443
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
   444
            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
   445
                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
   446
                    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
   447
                        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
   448
                    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
   449
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
   450
                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
   451
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
   452
                self.selected_SVG = svgpath if have_thumb else None
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   453
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   454
                self.AnalyseWidgetAndUpdateUI(fname)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   455
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   456
                if self.msg:
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   457
                    self.staticmsg.Show()
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   458
                    self.staticmsg.SetLabel(self.msg)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   459
                else:
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   460
                    self.staticmsg.Hide()
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   461
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   462
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
   463
            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
   464
                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
   465
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   466
            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
   467
        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
   468
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
   469
    def OnHMITreeNodeSelection(self, hmitree_nodes):
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   470
        self.hmitree_nodes = hmitree_nodes
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   471
        # [0] if len(hmitree_nodes) else None
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   472
        # self.ValidateWidget()
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   473
        # self.Refresh()
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
   474
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
   475
    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
   476
        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
   477
            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
   478
            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
   479
            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
   480
            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
   481
            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
   482
            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
   483
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
   484
    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
   485
        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
   486
            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
   487
        
3234
f2bfb047d0e6 SVGHMI: drop useless code from gen_dnd_widget.yslt2, renamed python callback to pass messages
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3231
diff changeset
   488
    def PassMessage(self, _context, msgs):
f2bfb047d0e6 SVGHMI: drop useless code from gen_dnd_widget.yslt2, renamed python callback to pass messages
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3231
diff changeset
   489
        for msg in msgs:
f2bfb047d0e6 SVGHMI: drop useless code from gen_dnd_widget.yslt2, renamed python callback to pass messages
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3231
diff changeset
   490
            self.msg += msg.text + "\n"
f2bfb047d0e6 SVGHMI: drop useless code from gen_dnd_widget.yslt2, renamed python callback to pass messages
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3231
diff changeset
   491
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
   492
    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
   493
        return [self.hmitree_node.etree()]
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   494
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   495
    def AnalyseWidgetAndUpdateUI(self, fname):
3235
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   496
        self.msg = ""
3245
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   497
        self.ResetSignature()
3235
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   498
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   499
        try:
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   500
            if self.selected_SVG is None:
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   501
                raise Exception(_("No widget selected"))
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   502
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   503
            transform = XSLTransform(
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   504
                os.path.join(ScriptDirectory, "analyse_widget.xslt"),[])
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   505
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   506
            svgdom = etree.parse(self.selected_SVG)
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   507
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   508
            signature = transform.transform(svgdom)
3235
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   509
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   510
            for entry in transform.get_error_log():
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   511
                self.msg += "XSLT: " + entry.message + "\n" 
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   512
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   513
        except Exception as e:
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   514
            self.msg += str(e)
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   515
        except XSLTApplyError as e:
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   516
            self.msg += "Widget " + fname + " analysis error: " + e.message
3235
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   517
        else:
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   518
            
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   519
            self.msg += "Widget " + fname + ": OK"
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   520
3235
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   521
            print(etree.tostring(signature, pretty_print=True))
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   522
            widgets = signature.getroot()
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   523
            for defs in widgets.iter("defs"):
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   524
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   525
                # Keep double newlines (to mark paragraphs)
3245
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   526
                self.desc.SetValue(defs.find("type").text + ":\n" + "\n\n".join(map(
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   527
                    lambda s:s.replace("\n"," ").replace("  ", " "),
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   528
                    defs.find("longdesc").text.split("\n\n"))))
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   529
                args = [arg for arg in defs.iter("arg")]
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   530
                self.args_box.Show(len(args)!=0)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   531
                for arg in args:
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   532
                    self.AddArgToSignature(arg)
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   533
                    print(arg.get("name"))
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   534
                    print(arg.get("accepts"))
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   535
                paths = [path for path in defs.iter("path")]
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   536
                self.paths_box.Show(len(paths)!=0)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   537
                for path in paths:
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   538
                    self.AddPathToSignature(path)
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   539
                    print(path.get("name"))
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   540
                    print(path.get("accepts"))
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   541
3235
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   542
            for widget in widgets:
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   543
                widget_type = widget.get("type")
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   544
                print(widget_type)
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   545
                for path in widget.iterchildren("path"):
3235
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   546
                    path_value = path.get("value")
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   547
                    path_accepts = map(
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   548
                        str.strip, path.get("accepts", '')[1:-1].split(','))
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3237
diff changeset
   549
                    print(path, path_value, path_accepts)
3235
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   550
3245
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   551
        self.main_panel.SetupScrolling(scroll_x=False)
c441181247cf SVGHMI: DnD UI : changed layout again, moved description in a vertical splitter, added scrollbar for preview and signature, fixed flickering description
Edouard Tisserant
parents: 3244
diff changeset
   552
3235
b2b6bf45aa2d SVGHMI: Add analyse_widget stylesheet and python code to execute it, in order to obtain widget signature independently of DnD SVG file generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3234
diff changeset
   553
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
   554
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
   555
    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
   556
        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
   557
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
   558
        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
   559
            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
   560
            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
   561
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
   562
        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
   563
            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
   564
                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
   565
            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
   566
                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
   567
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
   568
            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
   569
                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
   570
                [("GetSubHMITree", self.GetSubHMITree),
3234
f2bfb047d0e6 SVGHMI: drop useless code from gen_dnd_widget.yslt2, renamed python callback to pass messages
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3231
diff changeset
   571
                 ("PassMessage", 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
   572
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
   573
            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
   574
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
   575
            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
   576
                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
   577
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
   578
            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
   579
                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
   580
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
   581
            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
   582
            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
   583
            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
   584
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
   585
        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
   586
            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
   587
        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
   588
            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
   589
                
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
   590
    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
   591
        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
   592
            os.unlink(self.tempf.name)
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
   593
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
   594
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
   595
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
   596
    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
   597
        wx.SplitterWindow.__init__(self, parent,
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   598
                                   style=wx.SUNKEN_BORDER | wx.SP_3D)
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   599
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   600
        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
   601
        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
   602
        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
   603
        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
   604
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
   605
    def HMITreeUpdate(self, hmi_tree_root):
3247
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   606
        self.SelectionTree.MakeTree(hmi_tree_root)
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   607
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   608
    def OnHMITreeNodeSelection(self, hmitree_nodes):
7282b40374b0 SVGHMI: UI now have multiple HMI tree variables DnD to widget paths. Still no type checking, WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3245
diff changeset
   609
        self.Staging.OnHMITreeNodeSelection(hmitree_nodes)