author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Tue, 03 Oct 2017 16:07:02 +0300 | |
changeset 1842 | 05c1f7aa8991 |
parent 1782 | 5b6ad7a7fd9d |
child 1847 | 6198190bc121 |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
814 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
814 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
814 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
19 |
# GNU General Public License for more details. |
814 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1528
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
25 |
import wx |
|
26 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
27 |
# ------------------------------------------------------------------------------- |
814 | 28 |
# Helpers |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
29 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
30 |
|
814 | 31 |
|
32 |
[CATEGORY, BLOCK] = range(2) |
|
33 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
34 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
35 |
# ------------------------------------------------------------------------------- |
814 | 36 |
# Library Panel |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
37 |
# ------------------------------------------------------------------------------- |
814 | 38 |
|
1230 | 39 |
|
814 | 40 |
class LibraryPanel(wx.Panel): |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
41 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
42 |
Class that implements a panel displaying a tree containing an hierarchical list |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
43 |
of functions and function blocks available in project an a search control for |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
44 |
quickly find one functions or function blocks in this list and a text control |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
45 |
displaying informations about selected functions or function blocks |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
46 |
""" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
47 |
|
814 | 48 |
def __init__(self, parent, enable_drag=False): |
1230 | 49 |
""" |
50 |
Constructor |
|
51 |
@param parent: Parent wx.Window of LibraryPanel |
|
52 |
@param enable_drag: Flag indicating that function or function block can |
|
53 |
be drag'n drop from LibraryPanel (default: False) |
|
54 |
""" |
|
814 | 55 |
wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
56 |
|
1230 | 57 |
# Define LibraryPanel main sizer |
814 | 58 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
59 |
main_sizer.AddGrowableCol(0) |
|
60 |
main_sizer.AddGrowableRow(1) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
61 |
|
1230 | 62 |
# Add SearchCtrl to main sizer |
814 | 63 |
self.SearchCtrl = wx.SearchCtrl(self) |
1230 | 64 |
# Add a button with a magnifying glass, essentially to show that this |
65 |
# control is for searching in tree |
|
814 | 66 |
self.SearchCtrl.ShowSearchButton(True) |
67 |
self.Bind(wx.EVT_TEXT, self.OnSearchCtrlChanged, self.SearchCtrl) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
68 |
self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, |
1230 | 69 |
self.OnSearchButtonClick, self.SearchCtrl) |
70 |
# Bind keyboard event on SearchCtrl text control to catch UP and DOWN |
|
71 |
# for search previous and next occurrence |
|
1528
d551f2925a86
Fixed crash when starts on OS X with wxPython 3.0.x
alexander@macbook-pro-alexander.local
parents:
1501
diff
changeset
|
72 |
|
d551f2925a86
Fixed crash when starts on OS X with wxPython 3.0.x
alexander@macbook-pro-alexander.local
parents:
1501
diff
changeset
|
73 |
# This protects from fail to start when no children[0] available (possible for wxPython 3.0) |
d551f2925a86
Fixed crash when starts on OS X with wxPython 3.0.x
alexander@macbook-pro-alexander.local
parents:
1501
diff
changeset
|
74 |
if self.SearchCtrl.GetChildren(): |
d551f2925a86
Fixed crash when starts on OS X with wxPython 3.0.x
alexander@macbook-pro-alexander.local
parents:
1501
diff
changeset
|
75 |
search_textctrl = self.SearchCtrl.GetChildren()[0] |
d551f2925a86
Fixed crash when starts on OS X with wxPython 3.0.x
alexander@macbook-pro-alexander.local
parents:
1501
diff
changeset
|
76 |
search_textctrl.Bind(wx.EVT_CHAR, self.OnKeyDown) |
d551f2925a86
Fixed crash when starts on OS X with wxPython 3.0.x
alexander@macbook-pro-alexander.local
parents:
1501
diff
changeset
|
77 |
|
814 | 78 |
main_sizer.AddWindow(self.SearchCtrl, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
79 |
|
1230 | 80 |
# Add Splitter window for tree and block comment to main sizer |
814 | 81 |
splitter_window = wx.SplitterWindow(self) |
82 |
splitter_window.SetSashGravity(1.0) |
|
83 |
main_sizer.AddWindow(splitter_window, flag=wx.GROW) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
84 |
|
1230 | 85 |
# Add TreeCtrl for functions and function blocks library in splitter |
86 |
# window |
|
814 | 87 |
self.Tree = wx.TreeCtrl(splitter_window, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
88 |
size=wx.Size(0, 0), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
89 |
style=(wx.TR_HAS_BUTTONS | |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
90 |
wx.TR_SINGLE | |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
91 |
wx.SUNKEN_BORDER | |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
92 |
wx.TR_HIDE_ROOT | |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
93 |
wx.TR_LINES_AT_ROOT)) |
814 | 94 |
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeItemSelected, self.Tree) |
95 |
self.Tree.Bind(wx.EVT_CHAR, self.OnKeyDown) |
|
1230 | 96 |
# If drag'n drop is enabled, bind event generated when a drag begins on |
97 |
# tree to start a drag'n drop |
|
814 | 98 |
if enable_drag: |
99 |
self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnTreeBeginDrag, self.Tree) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
100 |
|
1230 | 101 |
# Add TextCtrl for function and function block informations |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
102 |
self.Comment = wx.TextCtrl(splitter_window, size=wx.Size(0, 80), |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
103 |
style=wx.TE_READONLY | wx.TE_MULTILINE) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
104 |
|
814 | 105 |
splitter_window.SplitHorizontally(self.Tree, self.Comment, -80) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
106 |
|
814 | 107 |
self.SetSizer(main_sizer) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
108 |
|
1230 | 109 |
# Reference to the project controller |
814 | 110 |
self.Controller = None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
111 |
|
1230 | 112 |
# Variable storing functions and function blocks library to display |
814 | 113 |
self.BlockList = None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
114 |
|
814 | 115 |
def __del__(self): |
1230 | 116 |
""" |
117 |
Destructor |
|
118 |
""" |
|
119 |
# Remove reference to project controller |
|
814 | 120 |
self.Controller = None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
121 |
|
814 | 122 |
def SetController(self, controller): |
1230 | 123 |
""" |
124 |
Set reference to project controller |
|
125 |
@param controller: Reference to project controller |
|
126 |
""" |
|
814 | 127 |
self.Controller = controller |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
128 |
|
814 | 129 |
def SetBlockList(self, blocklist): |
1230 | 130 |
""" |
131 |
Set function and function block library to display in TreeCtrl |
|
132 |
@param blocklist: Function and function block library |
|
133 |
""" |
|
134 |
# Save functions and function blocks library |
|
814 | 135 |
self.BlockList = blocklist |
1230 | 136 |
# Refresh TreeCtrl values |
814 | 137 |
self.RefreshTree() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
138 |
|
814 | 139 |
def SetFocus(self): |
1230 | 140 |
""" |
141 |
Called to give focus to LibraryPanel |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
142 |
Override wx.Window SetFocus method |
1230 | 143 |
""" |
144 |
# Give focus to SearchCtrl |
|
814 | 145 |
self.SearchCtrl.SetFocus() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
146 |
|
814 | 147 |
def ResetTree(self): |
1230 | 148 |
""" |
149 |
Reset LibraryPanel values displayed in controls |
|
150 |
""" |
|
151 |
# Clear SearchCtrl, TreeCtrl and TextCtrl |
|
814 | 152 |
self.SearchCtrl.SetValue("") |
153 |
self.Tree.DeleteAllItems() |
|
154 |
self.Comment.SetValue("") |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
155 |
|
814 | 156 |
def RefreshTree(self): |
1230 | 157 |
""" |
158 |
Refresh LibraryPanel values displayed in controls |
|
159 |
""" |
|
160 |
# Get function and function blocks library |
|
161 |
blocktypes = self.BlockList |
|
162 |
if blocktypes is None and self.Controller is not None: |
|
163 |
# Get library from project controller if not defined |
|
164 |
blocktypes = self.Controller.GetBlockTypes() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
165 |
|
1230 | 166 |
# Refresh TreeCtrl values if a library is defined |
167 |
if blocktypes is not None: |
|
168 |
# List that will contain tree items to be deleted when TreeCtrl |
|
169 |
# will be refreshed |
|
170 |
items_to_delete = [] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
171 |
|
1230 | 172 |
# Get current selected item for selected it when values refreshed |
173 |
selected_item = self.Tree.GetSelection() |
|
174 |
selected_pydata = (self.Tree.GetPyData(selected_item) |
|
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
175 |
if (selected_item.IsOk() and |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
176 |
selected_item != self.Tree.GetRootItem()) |
1230 | 177 |
else None) |
178 |
# Don't save selected item if it is a category |
|
179 |
selected_infos = ((self.Tree.GetItemText(selected_item), |
|
180 |
selected_pydata["inputs"]) |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
181 |
if (selected_pydata is not None and |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
182 |
selected_pydata["type"] == BLOCK) |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
183 |
else (None, None)) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
184 |
|
1230 | 185 |
# Get TreeCtrl root item (hidden) |
814 | 186 |
root = self.Tree.GetRootItem() |
187 |
if not root.IsOk(): |
|
1230 | 188 |
# Create root if not present |
814 | 189 |
root = self.Tree.AddRoot("") |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
190 |
|
1230 | 191 |
# Iterate over functions and function blocks library categories and |
192 |
# add a tree item to root item for each of them |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
193 |
|
1230 | 194 |
# Get first child under root item |
814 | 195 |
category_item, root_cookie = self.Tree.GetFirstChild(root) |
196 |
for category in blocktypes: |
|
1230 | 197 |
# Store category name in a local variable to prevent script |
198 |
# extracting translated strings for gettext to consider "name" |
|
199 |
# to be translated |
|
814 | 200 |
category_name = category["name"] |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
201 |
|
1230 | 202 |
# Tree item already exists, set item label |
203 |
if category_item.IsOk(): |
|
204 |
self.Tree.SetItemText(category_item, _(category_name)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
205 |
|
1230 | 206 |
# Tree item doesn't exist, add new one to root |
207 |
else: |
|
814 | 208 |
category_item = self.Tree.AppendItem(root, _(category_name)) |
1230 | 209 |
# On Windows, needs to get next child of root to have a |
210 |
# reference to the newly added tree item |
|
814 | 211 |
if wx.Platform != '__WXMSW__': |
1230 | 212 |
category_item, root_cookie = \ |
213 |
self.Tree.GetNextChild(root, root_cookie) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
214 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
215 |
# Set data associated to tree item (only save that item is a |
1230 | 216 |
# category) |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
217 |
self.Tree.SetPyData(category_item, {"type": CATEGORY}) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
218 |
|
1230 | 219 |
# Iterate over functions and function blocks defined in library |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
220 |
# category add a tree item to category tree item for each of |
1230 | 221 |
# them |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
222 |
|
1230 | 223 |
# Get first child under category tree item |
224 |
blocktype_item, category_cookie = \ |
|
225 |
self.Tree.GetFirstChild(category_item) |
|
814 | 226 |
for blocktype in category["list"]: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
227 |
|
1230 | 228 |
# Tree item already exists, set item label |
229 |
if blocktype_item.IsOk(): |
|
230 |
self.Tree.SetItemText(blocktype_item, blocktype["name"]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
231 |
|
1230 | 232 |
# Tree item doesn't exist, add new one to category item |
233 |
else: |
|
234 |
blocktype_item = self.Tree.AppendItem( |
|
235 |
category_item, blocktype["name"]) |
|
236 |
# See comment when adding category |
|
814 | 237 |
if wx.Platform != '__WXMSW__': |
1230 | 238 |
blocktype_item, category_cookie = \ |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
239 |
self.Tree.GetNextChild(category_item, |
1230 | 240 |
category_cookie) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
241 |
|
1230 | 242 |
# Define data to associate to block tree item |
243 |
comment = blocktype["comment"] |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
244 |
block_data = { |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
245 |
"type": BLOCK, |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
246 |
"block_type": blocktype["type"], |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
247 |
"inputs": tuple([type |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
248 |
for name, type, modifier |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
249 |
in blocktype["inputs"]]), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
250 |
"extension": (len(blocktype["inputs"]) |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
251 |
if blocktype["extensible"] else None), |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
252 |
"comment": _(comment) + blocktype.get("usage", "") |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
253 |
} |
814 | 254 |
self.Tree.SetPyData(blocktype_item, block_data) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
255 |
|
1230 | 256 |
# Select block tree item in tree if it corresponds to |
257 |
# previously selected one |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
258 |
if selected_infos == (blocktype["name"], |
1230 | 259 |
blocktype["inputs"]): |
814 | 260 |
self.Tree.SelectItem(blocktype_item) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
261 |
|
1230 | 262 |
# Update TextCtrl value |
263 |
self.Comment.SetValue(block_data["comment"]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
264 |
|
1230 | 265 |
# Get next block tree item under category tree item |
266 |
blocktype_item, category_cookie = \ |
|
267 |
self.Tree.GetNextChild(category_item, category_cookie) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
268 |
|
1230 | 269 |
# Add every remaining tree item under category tree item after |
270 |
# updating all block items to the list of items to delete |
|
814 | 271 |
while blocktype_item.IsOk(): |
1230 | 272 |
items_to_delete.append(blocktype_item) |
273 |
blocktype_item, category_cookie = \ |
|
274 |
self.Tree.GetNextChild(category_item, category_cookie) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
275 |
|
1230 | 276 |
# Get next category tree item under root item |
277 |
category_item, root_cookie = \ |
|
278 |
self.Tree.GetNextChild(root, root_cookie) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
279 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
280 |
# Add every remaining tree item under root item after updating all |
1230 | 281 |
# category items to the list of items to delete |
814 | 282 |
while category_item.IsOk(): |
1230 | 283 |
items_to_delete.append(category_item) |
284 |
category_item, root_cookie = \ |
|
285 |
self.Tree.GetNextChild(root, root_cookie) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
286 |
|
1230 | 287 |
# Remove all items in list of items to delete from TreeCtrl |
288 |
for item in items_to_delete: |
|
814 | 289 |
self.Tree.Delete(item) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
290 |
|
814 | 291 |
def GetSelectedBlock(self): |
1230 | 292 |
""" |
293 |
Get selected block informations |
|
294 |
@return: {"type": block_type_name, "inputs": [input_type,...]} or None |
|
295 |
if no block selected |
|
296 |
""" |
|
297 |
# Get selected item associated data in tree |
|
298 |
selected_item = self.Tree.GetSelection() |
|
299 |
selected_pydata = (self.Tree.GetPyData(selected_item) |
|
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
300 |
if (selected_item.IsOk() and |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
301 |
selected_item != self.Tree.GetRootItem()) |
1230 | 302 |
else None) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
303 |
|
1230 | 304 |
# Return value is None if selected tree item is root or a category |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
305 |
return ({"type": self.Tree.GetItemText(selected_item), |
1230 | 306 |
"inputs": selected_pydata["inputs"]} |
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
307 |
if (selected_pydata is not None and |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
308 |
selected_pydata["type"] == BLOCK) |
1230 | 309 |
else None) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
310 |
|
814 | 311 |
def SelectTreeItem(self, name, inputs): |
1230 | 312 |
""" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
313 |
Select Tree item corresponding to block informations given |
1230 | 314 |
@param name: Block type name |
315 |
@param inputs: List of block inputs type [input_type,...] |
|
316 |
""" |
|
317 |
# Find tree item corresponding to block informations |
|
814 | 318 |
item = self.FindTreeItem(self.Tree.GetRootItem(), name, inputs) |
319 |
if item is not None and item.IsOk(): |
|
1230 | 320 |
# Select tree item found |
814 | 321 |
self.Tree.SelectItem(item) |
322 |
self.Tree.EnsureVisible(item) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
323 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
324 |
def FindTreeItem(self, item, name, inputs=None): |
1230 | 325 |
""" |
326 |
Find Tree item corresponding to block informations given |
|
327 |
Function is recursive |
|
328 |
@param item: Item to test |
|
329 |
@param name: Block type name |
|
330 |
@param inputs: List of block inputs type [input_type,...] |
|
331 |
""" |
|
332 |
# Return immediately if item isn't valid |
|
333 |
if not item.IsOk(): |
|
334 |
return None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
335 |
|
1230 | 336 |
# Get data associated to item to test |
337 |
item_pydata = self.Tree.GetPyData(item) |
|
338 |
if item_pydata is not None and item_pydata["type"] == BLOCK: |
|
339 |
# Only test item corresponding to block |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
340 |
|
1230 | 341 |
# Test if block inputs type are the same than those given |
342 |
type_inputs = item_pydata.get("inputs", None) |
|
343 |
type_extension = item_pydata.get("extension", None) |
|
344 |
if inputs is not None and type_inputs is not None: |
|
345 |
same_inputs = reduce( |
|
346 |
lambda x, y: x and y, |
|
347 |
map( |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
348 |
lambda x: x[0] == x[1] or x[0] == 'ANY' or x[1] == 'ANY', |
1230 | 349 |
zip(type_inputs, |
350 |
(inputs[:type_extension] |
|
351 |
if type_extension is not None |
|
352 |
else inputs))), |
|
353 |
True) |
|
814 | 354 |
else: |
1230 | 355 |
same_inputs = True |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
356 |
|
1230 | 357 |
# Return item if block data corresponds to informations given |
358 |
if self.Tree.GetItemText(item) == name and same_inputs: |
|
359 |
return item |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
360 |
|
1230 | 361 |
# Test item children if item doesn't correspond |
362 |
child, child_cookie = self.Tree.GetFirstChild(item) |
|
363 |
while child.IsOk(): |
|
364 |
result = self.FindTreeItem(child, name, inputs) |
|
365 |
if result: |
|
366 |
return result |
|
367 |
child, child_cookie = self.Tree.GetNextChild(item, child_cookie) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
368 |
|
814 | 369 |
return None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
370 |
|
814 | 371 |
def SearchInTree(self, value, mode="first"): |
1230 | 372 |
""" |
373 |
Search in Tree and select item that name contains string given |
|
374 |
@param value: String contained in block name to find |
|
375 |
@param mode: Search mode ('first', 'previous' or 'next') |
|
376 |
(default: 'first') |
|
377 |
@return: True if an item was found |
|
378 |
""" |
|
379 |
# Return immediately if root isn't valid |
|
814 | 380 |
root = self.Tree.GetRootItem() |
381 |
if not root.IsOk(): |
|
382 |
return False |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
383 |
|
1230 | 384 |
# Set function to navigate in Tree item sibling according to search |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
385 |
# mode defined |
1230 | 386 |
sibling_function = (self.Tree.GetPrevSibling |
387 |
if mode == "previous" |
|
388 |
else self.Tree.GetNextSibling) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
389 |
|
1230 | 390 |
# Get current selected item (for next and previous mode) |
391 |
item = self.Tree.GetSelection() |
|
392 |
if not item.IsOk() or mode == "first": |
|
814 | 393 |
item, item_cookie = self.Tree.GetFirstChild(root) |
394 |
selected = None |
|
395 |
else: |
|
396 |
selected = item |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
397 |
|
1230 | 398 |
# Navigate through tree items until one matching found or reach tree |
399 |
# starting or ending |
|
814 | 400 |
while item.IsOk(): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
401 |
|
1230 | 402 |
# Get item data to get item type |
814 | 403 |
item_pydata = self.Tree.GetPyData(item) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
404 |
|
1230 | 405 |
# Item is a block category |
1501
d917c209529d
fix Traceback if search icon on library panel is clicked, when no
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1235
diff
changeset
|
406 |
if (item == root) or item_pydata["type"] == CATEGORY: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
407 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
408 |
# Get category first or last child according to search mode |
1230 | 409 |
# defined |
410 |
child = (self.Tree.GetLastChild(item) |
|
411 |
if mode == "previous" |
|
412 |
else self.Tree.GetFirstChild(item)[0]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
413 |
|
1230 | 414 |
# If category has no child, go to sibling category |
415 |
item = (child if child.IsOk() else sibling_function(item)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
416 |
|
1230 | 417 |
# Item is a block |
814 | 418 |
else: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
419 |
|
1230 | 420 |
# Extract item block name |
814 | 421 |
name = self.Tree.GetItemText(item) |
1230 | 422 |
# Test if block name contains string given |
1068
ef088254ba4b
Modify search algorithm in LibraryPanel to search match in whole block name, not only at beginning
Laurent Bessard
parents:
814
diff
changeset
|
423 |
if name.upper().find(value.upper()) != -1 and item != selected: |
1230 | 424 |
# Select block and collapse all categories other than block |
425 |
# category |
|
1235
1a30c70fa025
Fixed bug when searching in LibraryPanel on Windows
Laurent Bessard
parents:
1230
diff
changeset
|
426 |
child, child_cookie = self.Tree.GetFirstChild(root) |
1a30c70fa025
Fixed bug when searching in LibraryPanel on Windows
Laurent Bessard
parents:
1230
diff
changeset
|
427 |
while child.IsOk(): |
1a30c70fa025
Fixed bug when searching in LibraryPanel on Windows
Laurent Bessard
parents:
1230
diff
changeset
|
428 |
self.Tree.CollapseAllChildren(child) |
1a30c70fa025
Fixed bug when searching in LibraryPanel on Windows
Laurent Bessard
parents:
1230
diff
changeset
|
429 |
child, child_cookie = self.Tree.GetNextChild(root, child_cookie) |
814 | 430 |
self.Tree.SelectItem(item) |
431 |
self.Tree.EnsureVisible(item) |
|
432 |
return True |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
433 |
|
1230 | 434 |
# Go to next item sibling if block not found |
435 |
next = sibling_function(item) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
436 |
|
1230 | 437 |
# If category has no other child, go to next category sibling |
438 |
item = (next |
|
439 |
if next.IsOk() |
|
440 |
else sibling_function(self.Tree.GetItemParent(item))) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
441 |
|
814 | 442 |
return False |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
443 |
|
814 | 444 |
def OnSearchCtrlChanged(self, event): |
1230 | 445 |
""" |
446 |
Called when SearchCtrl text control value changed |
|
447 |
@param event: TextCtrl change event |
|
448 |
""" |
|
449 |
# Search for block containing SearchCtrl value in 'first' mode |
|
814 | 450 |
self.SearchInTree(self.SearchCtrl.GetValue()) |
451 |
event.Skip() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
452 |
|
814 | 453 |
def OnSearchButtonClick(self, event): |
1230 | 454 |
""" |
455 |
Called when SearchCtrl search button was clicked |
|
456 |
@param event: Button clicked event |
|
457 |
""" |
|
458 |
# Search for block containing SearchCtrl value in 'next' mode |
|
814 | 459 |
self.SearchInTree(self.SearchCtrl.GetValue(), "next") |
460 |
event.Skip() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
461 |
|
814 | 462 |
def OnTreeItemSelected(self, event): |
1230 | 463 |
""" |
464 |
Called when tree item is selected |
|
465 |
@param event: wx.TreeEvent |
|
466 |
""" |
|
467 |
# Update TextCtrl value with block selected usage |
|
468 |
item_pydata = self.Tree.GetPyData(event.GetItem()) |
|
469 |
self.Comment.SetValue( |
|
470 |
item_pydata["comment"] |
|
471 |
if item_pydata is not None and item_pydata["type"] == BLOCK |
|
472 |
else "") |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
473 |
|
1230 | 474 |
# Call extra function defined when tree item is selected |
814 | 475 |
if getattr(self, "_OnTreeItemSelected", None) is not None: |
476 |
self._OnTreeItemSelected(event) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
477 |
|
814 | 478 |
event.Skip() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
479 |
|
814 | 480 |
def OnTreeBeginDrag(self, event): |
1230 | 481 |
""" |
482 |
Called when a drag is started in tree |
|
483 |
@param event: wx.TreeEvent |
|
484 |
""" |
|
485 |
selected_item = event.GetItem() |
|
486 |
item_pydata = self.Tree.GetPyData(selected_item) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
487 |
|
1230 | 488 |
# Item dragged is a block |
489 |
if item_pydata is not None and item_pydata["type"] == BLOCK: |
|
490 |
# Start a drag'n drop |
|
491 |
data = wx.TextDataObject(str( |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
492 |
(self.Tree.GetItemText(selected_item), |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
493 |
item_pydata["block_type"], |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
494 |
"", |
1230 | 495 |
item_pydata["inputs"]))) |
814 | 496 |
dragSource = wx.DropSource(self.Tree) |
497 |
dragSource.SetData(data) |
|
498 |
dragSource.DoDragDrop() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
499 |
|
814 | 500 |
def OnKeyDown(self, event): |
1230 | 501 |
""" |
502 |
Called when key is pressed in SearchCtrl text control |
|
503 |
@param event: wx.KeyEvent |
|
504 |
""" |
|
505 |
# Get event keycode and value in SearchCtrl |
|
814 | 506 |
keycode = event.GetKeyCode() |
507 |
search_value = self.SearchCtrl.GetValue() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
508 |
|
1230 | 509 |
# Up key was pressed and SearchCtrl isn't empty, search for block in |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
510 |
# 'previous' mode |
814 | 511 |
if keycode == wx.WXK_UP and search_value != "": |
512 |
self.SearchInTree(search_value, "previous") |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
513 |
|
1230 | 514 |
# Down key was pressed and SearchCtrl isn't empty, search for block in |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
515 |
# 'next' mode |
814 | 516 |
elif keycode == wx.WXK_DOWN and search_value != "": |
517 |
self.SearchInTree(search_value, "next") |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
518 |
|
1230 | 519 |
# Handle key normally |
814 | 520 |
else: |
521 |
event.Skip() |