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