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