svghmi/ui.py
author Edouard Tisserant
Mon, 29 Mar 2021 14:35:45 +0200
branchsvghmi
changeset 3208 b5330d76e225
parent 3201 6dadc1690284
child 3213 afef7011f475
permissions -rw-r--r--
SVGHMI: Fix update of HMI tree in UI when loading from XML at start. Removed some dead code left after split of svghmi.py into svghmi.py+ui.py.
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
2745
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
    13
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
    14
import wx
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
    15
3193
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
    16
from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath
3201
6dadc1690284 SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3197
diff changeset
    17
from docutil import get_inkscape_path
2745
535eb0b8bd9d Skeleton for svghmi extension
Edouard Tisserant
parents:
diff changeset
    18
2756
f94bc35a023e SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents: 2753
diff changeset
    19
from util.ProcessLogger import ProcessLogger
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
    20
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    21
class HMITreeSelector(wx.TreeCtrl):
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    22
    def __init__(self, parent):
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    23
        global on_hmitree_update
3177
5a8abd549aa8 SVGHMI: Lighter display of HMI Tree, no more icons and use buttons. Auto expand root. Fix loading of HMI tree XML backup (hmiclass attribute wasn't kept).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3176
diff changeset
    24
        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
    25
            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
    26
            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
    27
            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
    28
            wx.TR_LINES_AT_ROOT))
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    29
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    30
        self.MakeTree()
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    31
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    32
    def _recurseTree(self, current_hmitree_root, current_tc_root):
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    33
        for c in current_hmitree_root.children:
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    34
            if hasattr(c, "children"):
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    35
                display_name = ('{} (class={})'.format(c.name, c.hmiclass)) \
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    36
                               if c.hmiclass is not None else c.name
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    37
                tc_child = self.AppendItem(current_tc_root, display_name)
3193
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
    38
                self.SetPyData(tc_child, None) # TODO
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    39
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    40
                self._recurseTree(c,tc_child)
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    41
            else:
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    42
                display_name = '{} {}'.format(c.nodetype[4:], c.name)
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    43
                tc_child = self.AppendItem(current_tc_root, display_name)
3193
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
    44
                self.SetPyData(tc_child, None) # TODO
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    45
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
    46
    def MakeTree(self, hmi_tree_root=None):
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    47
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    48
        self.Freeze()
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    49
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    50
        self.root = None
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    51
        self.DeleteAllItems()
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    52
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
    53
        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
    54
            if hmi_tree_root is None else "HMI"
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    55
        self.root = self.AddRoot(root_display_name)
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    56
        self.SetPyData(self.root, None)
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    57
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    58
        if hmi_tree_root is not None:
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    59
            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
    60
            self.Expand(self.root)
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    61
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
    62
        self.Thaw()
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
    63
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
    64
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
    65
    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
    66
        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
    67
            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
    68
            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
    69
            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
    70
            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
    71
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
    72
        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
    73
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
    74
    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
    75
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
    76
        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
    77
        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
    78
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
    79
        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
    80
        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
    81
            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
    82
            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
    83
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
    84
                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
    85
                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
    86
                    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
    87
                    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
    88
                    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
    89
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
    90
            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
    91
                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
    92
                    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
    93
                    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
    94
                        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
    95
                        res.append(current_tc_root)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
    96
                        self.SetPyData(current_tc_root, None)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
    97
                    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
    98
                    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
    99
                tc_child = self.AppendItem(current_tc_root, f)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   100
                self.SetPyData(tc_child, p)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   101
        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
   102
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   103
    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
   104
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   105
        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
   106
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   107
        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
   108
        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
   109
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   110
        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
   111
            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
   112
        self.root = self.AddRoot(root_display_name)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   113
        self.SetPyData(self.root, None)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   114
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   115
        if lib_dir is not None:
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   116
            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
   117
            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
   118
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        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
   120
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   121
_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
   122
_preview_height = 200
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   123
class WidgetLibBrowser(wx.Panel):
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   124
    def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   125
                 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
   126
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   127
        wx.Panel.__init__(self, parent, id, pos, size)     
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   128
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   129
        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
   130
        self.msg = None
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   131
        self.hmitree_node = None
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   132
        self.selected_SVG = None
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   133
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        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
   135
        self.libdir = self.RecallLibDir()
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   136
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   137
        sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=0)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   138
        sizer.AddGrowableCol(0)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   139
        sizer.AddGrowableRow(1)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   140
        self.libbutton = wx.Button(self, -1, _("Select SVG widget library"))
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   141
        self.widgetpicker = WidgetPicker(self, self.libdir)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   142
        self.preview = wx.Panel(self, size=(-1, _preview_height + 10))  #, style=wx.SIMPLE_BORDER)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   143
        #self.preview.SetBackgroundColour(wx.WHITE)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   144
        sizer.AddWindow(self.libbutton, flag=wx.GROW)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   145
        sizer.AddWindow(self.widgetpicker, flag=wx.GROW)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   146
        sizer.AddWindow(self.preview, flag=wx.GROW)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   147
        sizer.Layout()
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   148
        self.SetAutoLayout(True)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   149
        self.SetSizer(sizer)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   150
        sizer.Fit(self)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   151
        self.Bind(wx.EVT_BUTTON, self.OnSelectLibDir, self.libbutton)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   152
        self.preview.Bind(wx.EVT_PAINT, self.OnPaint)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   153
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnWidgetSelection, self.widgetpicker)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   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
        self.msg = _("Drag selected Widget from here to Inkscape")
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   157
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   158
    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
   159
        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
   160
        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
   161
            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
   162
        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
   163
            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
   164
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   165
    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
   166
        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
   167
                          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
   168
        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
   169
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   170
    def 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
   171
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        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
   173
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing 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
        # 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
   175
        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
   176
        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
   177
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   178
        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
   179
            # 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
   180
            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
   181
            w = self.bmp.GetWidth()
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   182
            dc.DrawBitmap(self.bmp, (sz.width - w)/2, 5)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   183
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   184
        if self.msg:
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   185
            dc.SetFont(self.GetFont())
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   186
            dc.DrawText(self.msg, 25,25)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   187
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   188
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   189
    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
   190
        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
   191
        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
   192
            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
   193
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   194
        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
   195
                              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
   196
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   197
        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
   198
            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
   199
            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
   200
            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
   201
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   202
        dialog.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
   203
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   204
    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
   205
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   206
        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
   207
        @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
   208
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   209
        self.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
   210
        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
   211
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   212
    def 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
   213
        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
   214
        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
   215
            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
   216
            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
   217
        # 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
   218
        status, result, _err_result = ProcessLogger(
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   219
            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
   220
            '"' + inkpath + '" "' + svgpath + '" -e "' + thumbpath +
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   221
            '" -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
   222
        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
   223
            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
   224
            return False
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   225
        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
   226
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   227
    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
   228
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   229
        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
   230
        @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
   231
        """
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   232
        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
   233
        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
   234
            svgpath = item_pydata
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   235
            dname = os.path.dirname(svgpath)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   236
            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
   237
            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
   238
            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
   239
                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
   240
                    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
   241
                    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
   242
                        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
   243
                    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
   244
                        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
   245
            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
   246
            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
   247
            thumbdir = os.path.join(dname, ".svghmithumbs") 
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   248
            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
   249
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   250
            self.msg = None
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   251
            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
   252
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   253
            if not have_thumb:
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   254
                try:
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   255
                    if not os.path.exists(thumbdir):
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   256
                        os.mkdir(thumbdir)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   257
                except IOError:
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   258
                    self.msg = _("Widget library must be writable")
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   259
                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
   260
                    have_thumb = self.GenThumbnail(svgpath, thumbpath)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   261
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   262
            self.bmp = wx.Bitmap(thumbpath) if have_thumb else None
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   263
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   264
            self.selected_SVG = svgpath if have_thumb else None
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   265
            self.ValidateWidget()
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   266
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   267
            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
   268
        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
   269
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   270
    def OnHMITreeNodeSelection(self, hmitree_node):
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   271
        self.hmitree_node = hmitree_node
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   272
        self.ValidateWidget()
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   273
        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
   274
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   275
    def ValidateWidget(self):
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   276
        if self.selected_SVG is not None:
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   277
            if self.hmitree_node is not None:
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   278
                pass
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   279
        # XXX TODO: 
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   280
        #      - check SVG is valid for selected HMI tree item
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   281
        #      - prepare for D'n'D
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   282
2816
d813ecfe8941 SVGHMI: Added simple HMI Tree View.
Edouard Tisserant
parents: 2815
diff changeset
   283
3201
6dadc1690284 SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3197
diff changeset
   284
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
   285
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
   286
    def __init__(self, parent, register_for_HMI_tree_updates):
2818
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   287
        wx.SplitterWindow.__init__(self, parent,
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   288
                                   style=wx.SUNKEN_BORDER | wx.SP_3D)
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   289
65f32c94d7ec SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents: 2817
diff changeset
   290
        self.SelectionTree = HMITreeSelector(self)
3193
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   291
        self.Staging = WidgetLibBrowser(self)
8006bb60a4dd SVGHMI: Added SVG widget library browser. Supports browsing and previewing widgets. Widget validation and drag'n'drop are still to be implemented.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3180
diff changeset
   292
        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
   293
        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
   294
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
   295
    def HMITreeUpdate(self, hmi_tree_root):
6dadc1690284 SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3197
diff changeset
   296
            self.SelectionTree.MakeTree(hmi_tree_root)
6dadc1690284 SVGHMI: split svghmi.py into svghmi.py (Config Tree Node + code gen) and ui.py (UI for HMI tree and Widget picking)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3197
diff changeset
   297