svghmi/ui.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Sun, 12 Mar 2023 00:51:53 +0100
branchwxPython4
changeset 3746 41be039fbb8c
parent 3609 51a3d6f39944
child 3750 f62625418bff
permissions -rw-r--r--
IDE: fix again ruberband with gtk3.

DC logical functions are now disabled when using GTK3.
Apparently using XOR was still having an effect.
Use regular black pen with no logical funciton instead.
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
3252
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
    13
import re
3499
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
    14
import tempfile
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
    15
from threading import Thread, Lock
3252
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
    16
from functools import reduce
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
    17
from itertools import izip
3252
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
    18
from operator import or_
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
    19
from tempfile import NamedTemporaryFile
2745
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
    20
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
    21
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
    22
from wx.lib.scrolledpanel import ScrolledPanel
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
    23
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
    24
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
    25
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
    26
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
    27
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
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
    29
from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath
3499
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
    30
from docutil import get_inkscape_path, get_inkscape_version
2745
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
    31
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
    32
from util.ProcessLogger import ProcessLogger
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
    33
3573
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    34
# When running as a confined Snap, /tmp isn't accessible from the outside
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    35
# and Widget DnD to Inkscape can't work, since it can't find generated svg 
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    36
# This forces tmp directory in $SNAP_USER_DATA, accessible from other apps
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    37
if os.environ.has_key("SNAP"):
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    38
     NamedTemporaryFile_orig = NamedTemporaryFile
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    39
     tmpdir = os.path.join(os.environ["SNAP_USER_DATA"], ".tmp")
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    40
     if not os.path.exists(tmpdir):
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    41
         os.mkdir(tmpdir)
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    42
     def NamedTemporaryFile(*args,**kwargs):
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    43
        kwargs["dir"] = tmpdir
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    44
        return NamedTemporaryFile_orig(*args, **kwargs)
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    45
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
    46
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
    47
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
    48
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
    49
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
    50
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    51
class HMITreeSelector(wx.TreeCtrl):
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    52
    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
    53
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
    54
        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
    55
            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
    56
            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
    57
            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
    58
            wx.TR_LINES_AT_ROOT))
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    59
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
    60
        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
    61
        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
    62
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    63
        self.MakeTree()
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    64
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
    65
        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
    66
        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
    67
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    68
    def _recurseTree(self, current_hmitree_root, current_tc_root):
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    69
        for c in current_hmitree_root.children:
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    70
            if hasattr(c, "children"):
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    71
                display_name = ('{} (class={})'.format(c.name, c.hmiclass)) \
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    72
                               if c.hmiclass is not None else c.name
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    73
                tc_child = self.AppendItem(current_tc_root, display_name)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3279
diff changeset
    74
                self.SetItemData(tc_child, c)
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    75
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    76
                self._recurseTree(c,tc_child)
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    77
            else:
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    78
                display_name = '{} {}'.format(c.nodetype[4:], c.name)
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    79
                tc_child = self.AppendItem(current_tc_root, display_name)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3279
diff changeset
    80
                self.SetItemData(tc_child, c)
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    81
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
    82
    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
    83
        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
    84
        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
    85
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
        # 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
    87
        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
    88
            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
    89
                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
    90
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
        # 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
    92
        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
    93
            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
    94
            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
    95
            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
    96
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
    97
        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
    98
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
    99
    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
   100
        """
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
   101
        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
   102
        @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
   103
        """
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
   104
        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
   105
            # 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
   106
            # 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
   107
            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
   108
            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
   109
            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
   110
            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
   111
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
   112
    def MakeTree(self, hmi_tree_root=None):
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   113
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   114
        self.Freeze()
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   115
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   116
        self.root = None
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   117
        self.DeleteAllItems()
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   118
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
   119
        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
   120
            if hmi_tree_root is None else "HMI"
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   121
        self.root = self.AddRoot(root_display_name)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3279
diff changeset
   122
        self.SetItemData(self.root, hmi_tree_root)
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   123
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   124
        if hmi_tree_root is not None:
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   125
            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
   126
            self.Expand(self.root)
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   127
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   128
        self.Thaw()
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
   129
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
   130
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
   131
    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
   132
        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
   133
            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
   134
            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
   135
            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
   136
            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
   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
        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
   139
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
    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
   141
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   142
        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
   143
        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
   144
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   145
        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
   146
        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
   147
            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
   148
            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
   149
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
                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
   151
                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
   152
                    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
   153
                    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
   154
                    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
   155
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
            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
   157
                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
   158
                    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
   159
                    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
   160
                        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
   161
                        res.append(current_tc_root)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3279
diff changeset
   162
                        self.SetItemData(current_tc_root, 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
   163
                    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
   164
                    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
   165
                tc_child = self.AppendItem(current_tc_root, f)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3279
diff changeset
   166
                self.SetItemData(tc_child, p)
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
   167
        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
   168
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   169
    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
   170
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   171
        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
   172
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   173
        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
   174
        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
   175
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   176
        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
   177
            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
   178
        self.root = self.AddRoot(root_display_name)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3279
diff changeset
   179
        self.SetItemData(self.root, 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
   180
3253
9233e60a8317 SVGHMI: fix exception when stored widget library path does not exist anymore
Edouard Tisserant
parents: 3251
diff changeset
   181
        if lib_dir is not None and os.path.exists(lib_dir):
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
   182
            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
   183
            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
   184
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   185
        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
   186
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
   187
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
   188
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
    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
   190
        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
   191
        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
   192
        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
   193
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
   194
    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
   195
        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
   196
        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
   197
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
   198
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
   199
    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
   200
        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
   201
        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
   202
        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
   203
            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
   204
        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
   205
        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
   206
        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
   207
        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
   208
        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
   209
        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
   210
        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
   211
        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
   212
        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
   213
        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
   214
        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
   215
        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
   216
        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
   217
        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
   218
        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
   219
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   220
    def GetValue(self):
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   221
        return self.edit.GetValue()
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   222
3252
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   223
    def setValidity(self, validity):
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   224
        if validity is not None:
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   225
            bmp = self.valid_bmp if validity else self.invalid_bmp
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   226
            self.validity_sbmp.SetBitmap(bmp)
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   227
            self.validity_sbmp.Show(True)
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   228
        else :
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   229
            self.validity_sbmp.Show(False)
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   230
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   231
models = { typename: re.compile(regex) for typename, regex in [
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   232
    ("string", r".*"),
3263
1205b2d0acf2 SVGHMI: DnD UI: Fix SVG gen that was dropping widget name and making XSLTExceptions plus some UX enhancements.
Edouard Tisserant
parents: 3261
diff changeset
   233
    ("int", r"^-?([1-9][0-9]*|0)$"),
1205b2d0acf2 SVGHMI: DnD UI: Fix SVG gen that was dropping widget name and making XSLTExceptions plus some UX enhancements.
Edouard Tisserant
parents: 3261
diff changeset
   234
    ("real", r"^-?([1-9][0-9]*|0)(\.[0-9]+)?$")]}
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
   235
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
   236
class ArgEditor(ParamEditor):
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   237
    def __init__(self, parent, argdesc, prefillargdesc):
3252
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   238
        ParamEditor.__init__(self, parent, argdesc)
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   239
        self.ParentObj = parent
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   240
        self.argdesc = argdesc
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   241
        self.Bind(wx.EVT_TEXT, self.OnArgChanged, self.edit)
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   242
        prefill = "" if prefillargdesc is None else prefillargdesc.get("value")
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   243
        self.edit.SetValue(prefill)
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   244
        # TODO add a button to add more ArgEditror instance 
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   245
        #      when ordinality is multiple
3252
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   246
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   247
    def OnArgChanged(self, event):
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   248
        txt = self.edit.GetValue()
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   249
        accepts = self.argdesc.get("accepts").split(',')
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   250
        self.setValidity(
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   251
            reduce(or_,
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   252
                   map(lambda typename: 
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   253
                           models[typename].match(txt) is not None,
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   254
                       accepts), 
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   255
                   False)
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   256
            if accepts and txt else None)
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   257
        self.ParentObj.RegenSVGLater()
3252
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   258
        event.Skip()
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
   259
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
   260
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
   261
    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
   262
        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
   263
        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
   264
        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
   265
        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
   266
        self.edit.SetDropTarget(DropTarget)
3265
f3cb352048b6 SVGHMI: DnD UI: Add hint instructing user to Drag HMI tree items to text field.
Edouard Tisserant
parents: 3263
diff changeset
   267
        self.edit.SetHint(_("Drag'n'drop HMI variable here"))
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
   268
        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
   269
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
   270
    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
   271
        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
   272
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
   273
    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
   274
        self.edit.ChangeValue(hmitree_node.hmi_path())
3252
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   275
        self.setValidity(
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   276
            hmitree_node.nodetype in self.pathdesc.get("accepts").split(","))
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
   277
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
   278
    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
   279
        # 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
   280
        # Lazy way : hide validity
3252
352b2111ca66 SVGHMI: added checking of widget literal argument in DnD UI according to type given in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3251
diff changeset
   281
        self.setValidity(None)
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   282
        self.ParentObj.RegenSVGLater()
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
   283
        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
   284
    
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   285
def KeepDoubleNewLines(txt):
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   286
    return "\n\n".join(map(
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   287
        lambda s:re.sub(r'\s+',' ',s),
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   288
        txt.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
   289
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
   290
_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
   291
_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
   292
_preview_margin = 5
3499
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   293
thumbnail_temp_path = None
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   294
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   295
class WidgetLibBrowser(wx.SplitterWindow):
3499
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   296
    def __init__(self, parent, controler, id=wx.ID_ANY, pos=wx.DefaultPosition,
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
   297
                 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
   298
3243
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   299
        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
   300
                                   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
   301
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   302
        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
   303
        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
   304
        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
   305
        self.selected_SVG = None
3499
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   306
        self.Controler = controler
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
   307
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   308
        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
   309
        self.libdir = self.RecallLibDir()
3274
16066300b254 SVGHMI: default library path, default page when starting a SVGHMI project, error page when no SVG present
Edouard Tisserant
parents: 3265
diff changeset
   310
        if self.libdir is None:
16066300b254 SVGHMI: default library path, default page when starting a SVGHMI project, error page when no SVG present
Edouard Tisserant
parents: 3265
diff changeset
   311
            self.libdir = os.path.join(ScriptDirectory, "widgetlib") 
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
   312
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
   313
        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
   314
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
        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
   316
        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
   317
        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
   318
        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
   319
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   320
        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
   321
        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
   322
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   323
        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
   324
        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
   325
        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
   326
        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
   327
        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
   328
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   329
        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
   330
        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
   331
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   332
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   333
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
   334
        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
   335
                                                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
   336
                                                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
   337
92cc21f88bf8 SVGHMI: WIP: Widget Library UI: Reworking widget selection and binding.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3241
diff changeset
   338
        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
   339
        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
   340
        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
   341
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
        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
   343
        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
   344
        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
   345
        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
   346
                                     _("Widget's arguments"),
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   347
                                     style = wx.ALIGN_CENTRE_HORIZONTAL)
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
   348
        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
   349
        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
   350
                                      _("Widget's variables"),
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   351
                                      style = wx.ALIGN_CENTRE_HORIZONTAL)
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
   352
        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
   353
        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
   354
        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
   355
        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
   356
        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
   357
        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
   358
        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
   359
        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
   360
        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
   361
        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
   362
        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
   363
        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
   364
        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
   365
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
   366
        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
   367
                                   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
   368
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
   369
        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
   370
        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
   371
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
   372
        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
   373
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   374
        self.RegenSVGThread = None
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   375
        self.RegenSVGLock = Lock()
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   376
        self.RegenSVGTimer = wx.Timer(self, -1)
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   377
        self.RegenSVGParams = None
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   378
        self.Bind(wx.EVT_TIMER,
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   379
                  self.RegenSVG,
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   380
                  self.RegenSVGTimer)
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   381
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
   382
        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
   383
        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
   384
3263
1205b2d0acf2 SVGHMI: DnD UI: Fix SVG gen that was dropping widget name and making XSLTExceptions plus some UX enhancements.
Edouard Tisserant
parents: 3261
diff changeset
   385
    def SetMessage(self, msg):
1205b2d0acf2 SVGHMI: DnD UI: Fix SVG gen that was dropping widget name and making XSLTExceptions plus some UX enhancements.
Edouard Tisserant
parents: 3261
diff changeset
   386
        self.staticmsg.SetLabel(msg)
1205b2d0acf2 SVGHMI: DnD UI: Fix SVG gen that was dropping widget name and making XSLTExceptions plus some UX enhancements.
Edouard Tisserant
parents: 3261
diff changeset
   387
        self.main_sizer.Layout()
1205b2d0acf2 SVGHMI: DnD UI: Fix SVG gen that was dropping widget name and making XSLTExceptions plus some UX enhancements.
Edouard Tisserant
parents: 3261
diff changeset
   388
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
   389
    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
   390
        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
   391
        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
   392
            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
   393
        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
   394
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
   395
        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
   396
        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
   397
            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
   398
        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
   399
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   400
    def AddArgToSignature(self, arg, prefillarg):
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   401
        new_editor = ArgEditor(self, arg, prefillarg)
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
   402
        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
   403
        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
   404
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
   405
    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
   406
        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
   407
        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
   408
        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
   409
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
   410
    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
   411
        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
   412
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
   413
        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
   414
                                   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
   415
            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
   416
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   417
        self.RegenSVGNow()
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   418
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
   419
    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
   420
        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
   421
        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
   422
            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
   423
        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
   424
            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
   425
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
    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
   427
        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
   428
                          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
   429
        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
   430
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
    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
   432
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        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
   434
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        # 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
   436
        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
   437
        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
   438
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        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
   440
            # 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
   441
            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
   442
            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
   443
            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
   444
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   445
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
    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
   448
        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
   449
        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
   450
            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
   451
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   452
        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
   453
                              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
   454
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   455
        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
   456
            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
   457
            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
   458
            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
   459
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   460
        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
   461
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   462
    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
   463
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   464
        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
   465
        @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
   466
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        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
   468
        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
   469
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   470
    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
   471
        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
   472
        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
   473
            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
   474
            return False
3499
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   475
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   476
        export_opt = "-o" if get_inkscape_version()[0] > 0 else "-e"
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   477
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
   478
        # 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
   479
        status, result, _err_result = ProcessLogger(
3573
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
   480
            #self.Controler.GetCTRoot().logger,
1ee56fb544fc IDE, SVGHMI: Workaround Snap package not launching Inskape, POEdit or Chromium directly, producing lot of output in Incskape CLI, and messing with TMPDIR
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3526
diff changeset
   481
            None,
3499
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   482
            '"' + inkpath + '" "' + svgpath + '" ' +
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   483
            export_opt + ' "' + thumbpath +
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
   484
            '" -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
   485
        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
   486
            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
   487
            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
   488
        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
   489
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   490
    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
   491
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   492
        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
   493
        @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
   494
        """
3499
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   495
        global thumbnail_temp_path
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   496
        event.Skip()
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
   497
        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
   498
        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
   499
            svgpath = item_pydata
3499
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   500
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   501
            if thumbnail_temp_path is None:
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   502
                try:
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   503
                    dname = os.path.dirname(svgpath)
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   504
                    thumbdir = os.path.join(dname, ".svghmithumbs") 
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   505
                    if not os.path.exists(thumbdir):
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   506
                        os.mkdir(thumbdir)
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   507
                except Exception :
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   508
                    # library not writable : use temp dir
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   509
                    thumbnail_temp_path = os.path.join(
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   510
                        tempfile.gettempdir(), "svghmithumbs")
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   511
                    thumbdir = thumbnail_temp_path
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   512
                    if not os.path.exists(thumbdir):
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   513
                        os.mkdir(thumbdir)
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   514
            else:
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   515
                thumbdir = thumbnail_temp_path
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   516
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
   517
            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
   518
            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
   519
            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
   520
                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
   521
                    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
   522
                    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
   523
                        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
   524
                    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
   525
                        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
   526
            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
   527
            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
   528
            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
   529
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   530
            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
   531
3499
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   532
            if not have_thumb:
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   533
                self.Controler.GetCTRoot().logger.write(
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   534
                    "Rendering preview of " + fname + " widget.\n")
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   535
                have_thumb = self.GenThumbnail(svgpath, thumbpath)
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   536
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   537
            self.bmp = wx.Bitmap(thumbpath) if have_thumb else None
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   538
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   539
            self.selected_SVG = svgpath if have_thumb else None
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   540
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   541
            self.AnalyseWidgetAndUpdateUI(fname)
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   542
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   543
            self.SetMessage(self.msg)
3193
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   544
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   545
            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
   546
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
   547
    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
   548
        self.hmitree_nodes = 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
   549
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
   550
    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
   551
        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
   552
            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
   553
            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
   554
            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
   555
            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
   556
            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
   557
            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
   558
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   559
    def RegenSVGLater(self, when=1):
3263
1205b2d0acf2 SVGHMI: DnD UI: Fix SVG gen that was dropping widget name and making XSLTExceptions plus some UX enhancements.
Edouard Tisserant
parents: 3261
diff changeset
   560
        self.SetMessage(_("SVG generation pending"))
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   561
        self.RegenSVGTimer.Start(milliseconds=when*1000, oneShot=True)
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   562
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   563
    def RegenSVGNow(self):
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   564
        self.RegenSVGLater(when=0)
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   565
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   566
    def RegenSVG(self, event):
3263
1205b2d0acf2 SVGHMI: DnD UI: Fix SVG gen that was dropping widget name and making XSLTExceptions plus some UX enhancements.
Edouard Tisserant
parents: 3261
diff changeset
   567
        self.SetMessage(_("Generating SVG..."))
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   568
        args = [arged.GetValue() for arged in self.args_editors]
3263
1205b2d0acf2 SVGHMI: DnD UI: Fix SVG gen that was dropping widget name and making XSLTExceptions plus some UX enhancements.
Edouard Tisserant
parents: 3261
diff changeset
   569
        while args and not args[-1]: args.pop(-1)
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   570
        paths = [pathed.GetValue() for pathed in self.paths_editors]
3263
1205b2d0acf2 SVGHMI: DnD UI: Fix SVG gen that was dropping widget name and making XSLTExceptions plus some UX enhancements.
Edouard Tisserant
parents: 3261
diff changeset
   571
        while paths and not paths[-1]: paths.pop(-1)
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   572
        if self.RegenSVGLock.acquire(True):
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   573
            self.RegenSVGParams = (args, paths)
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   574
            if self.RegenSVGThread is None:
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   575
                self.RegenSVGThread = \
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   576
                    Thread(target=self.RegenSVGProc,
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   577
                           name="RegenSVGThread").start()
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   578
            self.RegenSVGLock.release()
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   579
        event.Skip()
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   580
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   581
    def RegenSVGProc(self):
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   582
        self.RegenSVGLock.acquire(True)
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   583
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   584
        newparams = self.RegenSVGParams
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   585
        self.RegenSVGParams = None
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   586
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   587
        while newparams is not None:
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   588
            self.RegenSVGLock.release()
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   589
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   590
            res = self.GenDnDSVG(newparams)
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   591
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   592
            self.RegenSVGLock.acquire(True)
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   593
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   594
            newparams = self.RegenSVGParams
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   595
            self.RegenSVGParams = None
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   596
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   597
        self.RegenSVGThread = None
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   598
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   599
        self.RegenSVGLock.release()
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   600
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   601
        wx.CallAfter(self.DoneRegenSVG)
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
   602
        
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   603
    def DoneRegenSVG(self):
3263
1205b2d0acf2 SVGHMI: DnD UI: Fix SVG gen that was dropping widget name and making XSLTExceptions plus some UX enhancements.
Edouard Tisserant
parents: 3261
diff changeset
   604
        self.SetMessage(self.msg if self.msg else _("SVG ready for drag'n'drop"))
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   605
        
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
    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
   607
        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
   608
        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
   609
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
   610
        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
   611
            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
   612
                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
   613
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
   614
            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
   615
                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
   616
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
   617
            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
   618
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
   619
            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
   620
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
   621
            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
   622
                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
   623
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
   624
        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
   625
            self.msg += str(e)
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   626
            return
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
   627
        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
   628
            self.msg += "Widget " + fname + " analysis error: " + e.message
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   629
            return
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
   630
            
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   631
        self.msg += "Widget " + fname + ": OK"
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   632
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   633
        widgets = signature.getroot()
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   634
        widget = widgets.find("widget")
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   635
        defs = widget.find("defs")
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   636
        # Keep double newlines (to mark paragraphs)
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   637
        widget_desc = widget.find("desc")
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   638
        self.desc.SetValue(
3279
5615e062a77d SVGHMI: DnD UI: Use widget's short description, initially forgoten.
Edouard Tisserant
parents: 3274
diff changeset
   639
            fname + ":\n\n" + (
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   640
                _("No description given") if widget_desc is None else 
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   641
                KeepDoubleNewLines(widget_desc.text)
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   642
            ) + "\n\n" +
3279
5615e062a77d SVGHMI: DnD UI: Use widget's short description, initially forgoten.
Edouard Tisserant
parents: 3274
diff changeset
   643
            defs.find("type").text + " Widget: "+defs.find("shortdesc").text+"\n\n" +
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   644
            KeepDoubleNewLines(defs.find("longdesc").text))
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   645
        prefillargs = widget.findall("arg")
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   646
        args = defs.findall("arg")
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   647
        # extend args description in prefilled args in longer 
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   648
        # (case of variable list of args)
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   649
        if len(prefillargs) < len(args):
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   650
            prefillargs += [None]*(len(args)-len(prefillargs))
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   651
        if args and len(prefillargs) > len(args):
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   652
            # TODO: check ordinality of last arg
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   653
            # TODO: check that only last arg has multiple ordinality
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   654
            args += [args[-1]]*(len(prefillargs)-len(args))
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   655
        self.args_box.Show(len(args)!=0)
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   656
        for arg, prefillarg in izip(args,prefillargs):
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   657
            self.AddArgToSignature(arg, prefillarg)
3454
0b5ab53007a9 SVGHMI: cosmetic fixes + removed dead code
Edouard Tisserant
parents: 3279
diff changeset
   658
0b5ab53007a9 SVGHMI: cosmetic fixes + removed dead code
Edouard Tisserant
parents: 3279
diff changeset
   659
        # TODO support predefined path count (as for XYGraph)
3259
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   660
        paths = defs.findall("path")
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   661
        self.paths_box.Show(len(paths)!=0)
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   662
        for path in paths:
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   663
            self.AddPathToSignature(path)
76da573569a6 SVGHMI: UI: added prefill of arguments according to values in widget instance in library. Also added library's widget instance description to description field.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3255
diff changeset
   664
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
   665
        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
   666
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   667
    def GetWidgetParams(self, _context):
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   668
        args,paths = self.GenDnDSVGParams
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   669
        root = etree.Element("params")
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   670
        for arg in args:
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   671
            etree.SubElement(root, "arg", value=arg)
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   672
        for path in paths:
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   673
            etree.SubElement(root, "path", value=path)
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   674
        return root
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   675
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   676
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   677
    def GenDnDSVG(self, newparams):
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
   678
        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
   679
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   680
        self.GenDnDSVGParams = newparams
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   681
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
   682
        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
   683
            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
   684
            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
   685
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
   686
        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
   687
            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
   688
                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
   689
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
   690
            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
   691
                os.path.join(ScriptDirectory, "gen_dnd_widget_svg.xslt"),
3263
1205b2d0acf2 SVGHMI: DnD UI: Fix SVG gen that was dropping widget name and making XSLTExceptions plus some UX enhancements.
Edouard Tisserant
parents: 3261
diff changeset
   692
                [("GetWidgetParams", self.GetWidgetParams)])
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
   693
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
   694
            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
   695
3261
06ea7a1152af SVGHMI: DnD UI: SVG for DnD now generated again based on paths and args entries filled by user.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3259
diff changeset
   696
            result = transform.transform(svgdom)
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
   697
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
   698
            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
   699
                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
   700
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
   701
            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
   702
            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
   703
            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
   704
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
   705
        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
   706
            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
   707
        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
   708
            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
   709
                
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
   710
    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
   711
        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
   712
            os.unlink(self.tempf.name)
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
   713
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
   714
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
   715
3499
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   716
    def __init__(self, parent, controler, register_for_HMI_tree_updates):
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   717
        wx.SplitterWindow.__init__(self, parent,
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   718
                                   style=wx.SUNKEN_BORDER | wx.SP_3D)
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   719
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   720
        self.SelectionTree = HMITreeSelector(self)
3499
72ee59ff959c SVGHMI: Adapt to Inkscape 0.92 "-e" replaced by "-o" in 1.2, and workaround access right problem when generating thumbnails.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3454
diff changeset
   721
        self.Staging = WidgetLibBrowser(self, controler)
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
   722
        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
   723
        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
   724
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
   725
    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
   726
        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
   727
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
   728
    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
   729
        self.Staging.OnHMITreeNodeSelection(hmitree_nodes)