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