author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Sat, 19 Aug 2017 21:06:54 +0300 | |
changeset 1781 | b112bfdde5cc |
parent 1773 | 38fde37c3766 |
child 1782 | 5b6ad7a7fd9d |
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:
1556
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:
1556
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
6 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
8 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
10 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
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:
1556
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:
1556
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:
1556
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
15 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
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:
1556
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:
1556
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:
1556
diff
changeset
|
19 |
# GNU General Public License for more details. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
20 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
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:
1556
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:
1556
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
25 |
from types import TupleType |
|
26 |
||
27 |
import wx |
|
28 |
import wx.lib.buttons |
|
29 |
import wx.lib.agw.customtreectrl as CT |
|
30 |
||
31 |
from PLCControler import * |
|
32 |
from util.BitmapLibrary import GetBitmap |
|
33 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1733
diff
changeset
|
34 |
|
814 | 35 |
def GenerateName(infos): |
36 |
if infos[0] in ["input", "output", "value"]: |
|
37 |
return "%s %d:" % (infos[0], infos[1]) |
|
38 |
elif infos[0] == "range": |
|
39 |
return "%s %d %s" % (infos[0], infos[1], infos[2]) |
|
40 |
elif infos[0] == "struct": |
|
41 |
return "element %d %s" % (infos[1], infos[2]) |
|
42 |
return "%s:" % infos[0] |
|
43 |
||
44 |
#------------------------------------------------------------------------------- |
|
45 |
# Search Result Panel |
|
46 |
#------------------------------------------------------------------------------- |
|
47 |
||
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
48 |
|
1773
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
49 |
[ |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
50 |
ID_SEARCHRESULTPANEL, ID_SEARCHRESULTPANELHEADERLABEL, |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
51 |
ID_SEARCHRESULTPANELSEARCHRESULTSTREE, ID_SEARCHRESULTPANELRESETBUTTON, |
814 | 52 |
] = [wx.NewId() for _init_ctrls in range(4)] |
53 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1733
diff
changeset
|
54 |
|
814 | 55 |
class SearchResultPanel(wx.Panel): |
56 |
||
57 |
if wx.VERSION < (2, 6, 0): |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
58 |
def Bind(self, event, function, id=None): |
814 | 59 |
if id is not None: |
60 |
event(self, id, function) |
|
61 |
else: |
|
62 |
event(self, function) |
|
63 |
||
64 |
def _init_coll_MainSizer_Items(self, parent): |
|
65 |
parent.AddSizer(self.HeaderSizer, 0, border=0, flag=wx.GROW) |
|
66 |
parent.AddWindow(self.SearchResultsTree, 1, border=0, flag=wx.GROW) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
67 |
|
814 | 68 |
def _init_coll_MainSizer_Growables(self, parent): |
69 |
parent.AddGrowableCol(0) |
|
70 |
parent.AddGrowableRow(1) |
|
71 |
||
72 |
def _init_coll_HeaderSizer_Items(self, parent): |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
73 |
parent.AddWindow(self.HeaderLabel, 1, border=5, flag=wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL) |
814 | 74 |
parent.AddWindow(self.ResetButton, 0, border=0, flag=0) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
75 |
|
814 | 76 |
def _init_coll_HeaderSizer_Growables(self, parent): |
77 |
parent.AddGrowableCol(0) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
78 |
|
814 | 79 |
def _init_sizers(self): |
80 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
81 |
self.HeaderSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
82 |
|
814 | 83 |
self._init_coll_MainSizer_Items(self.MainSizer) |
84 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
|
85 |
self._init_coll_HeaderSizer_Items(self.HeaderSizer) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
86 |
|
814 | 87 |
self.SetSizer(self.MainSizer) |
88 |
||
89 |
def _init_ctrls(self, prnt): |
|
90 |
wx.Panel.__init__(self, id=ID_SEARCHRESULTPANEL, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
91 |
name='SearchResultPanel', parent=prnt, pos=wx.Point(0, 0), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
92 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
814 | 93 |
|
94 |
self.HeaderLabel = wx.StaticText(id=ID_SEARCHRESULTPANELHEADERLABEL, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
95 |
name='HeaderLabel', parent=self, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
96 |
pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
97 |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
98 |
search_results_tree_style = CT.TR_HAS_BUTTONS | CT.TR_NO_LINES | CT.TR_HAS_VARIABLE_ROW_HEIGHT |
814 | 99 |
self.SearchResultsTree = CT.CustomTreeCtrl(id=ID_SEARCHRESULTPANELSEARCHRESULTSTREE, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
100 |
name="SearchResultsTree", parent=self, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
101 |
pos=wx.Point(0, 0), style=search_results_tree_style) |
814 | 102 |
if wx.VERSION >= (2, 8, 11): |
103 |
self.SearchResultsTree.SetAGWWindowStyleFlag(search_results_tree_style) |
|
104 |
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnSearchResultsTreeItemActivated, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
105 |
id=ID_SEARCHRESULTPANELSEARCHRESULTSTREE) |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
106 |
|
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
107 |
self.ResetButton = wx.lib.buttons.GenBitmapButton( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
108 |
self, bitmap=GetBitmap("reset"), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
109 |
size=wx.Size(28, 28), style=wx.NO_BORDER) |
814 | 110 |
self.ResetButton.SetToolTipString(_("Reset search result")) |
111 |
self.Bind(wx.EVT_BUTTON, self.OnResetButton, self.ResetButton) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
112 |
|
814 | 113 |
self._init_sizers() |
114 |
||
115 |
def __init__(self, parent, window): |
|
116 |
self.ParentWindow = window |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
117 |
|
814 | 118 |
self._init_ctrls(parent) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
119 |
|
814 | 120 |
# Define Tree item icon list |
121 |
self.TreeImageList = wx.ImageList(16, 16) |
|
122 |
self.TreeImageDict = {} |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
123 |
|
814 | 124 |
# Icons for other items |
125 |
for imgname, itemtype in [ |
|
1766
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
126 |
# editables |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
127 |
("PROJECT", ITEM_PROJECT), |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
128 |
("TRANSITION", ITEM_TRANSITION), |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
129 |
("ACTION", ITEM_ACTION), |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
130 |
("CONFIGURATION", ITEM_CONFIGURATION), |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
131 |
("RESOURCE", ITEM_RESOURCE), |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
132 |
("DATATYPE", ITEM_DATATYPE), |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
133 |
("ACTION", "action_block"), |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
134 |
("IL", "IL"), |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
135 |
("ST", "ST")]: |
814 | 136 |
self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname)) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
137 |
|
814 | 138 |
for itemtype in ["function", "functionBlock", "program", |
139 |
"comment", "block", "io_variable", |
|
140 |
"connector", "contact", "coil", |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
141 |
"step", "transition", "jump", |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
142 |
"var_local", "var_input", |
814 | 143 |
"var_inout", "var_output"]: |
144 |
self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(itemtype.upper())) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
145 |
|
814 | 146 |
# Assign icon list to TreeCtrl |
147 |
self.SearchResultsTree.SetImageList(self.TreeImageList) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
148 |
|
814 | 149 |
self.ResetSearchResults() |
150 |
||
151 |
def SetSearchResults(self, criteria, search_results): |
|
152 |
self.Criteria = criteria |
|
153 |
self.SearchResults = {} |
|
154 |
self.ElementsOrder = [] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
155 |
|
814 | 156 |
for infos, start, end, text in search_results: |
157 |
if infos[0] not in self.ElementsOrder: |
|
158 |
self.ElementsOrder.append(infos[0]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
159 |
|
814 | 160 |
results = self.SearchResults.setdefault(infos[0], []) |
161 |
results.append((infos, start, end, text)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
162 |
|
814 | 163 |
self.RefreshView() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
164 |
|
814 | 165 |
def ResetSearchResults(self): |
166 |
self.Criteria = None |
|
167 |
self.ElementsOrder = [] |
|
168 |
self.SearchResults = {} |
|
169 |
self.RefreshView() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
170 |
|
814 | 171 |
def RefreshView(self): |
172 |
self.SearchResultsTree.DeleteAllItems() |
|
173 |
if self.Criteria is None: |
|
174 |
self.HeaderLabel.SetLabel(_("No search results available.")) |
|
175 |
self.ResetButton.Enable(False) |
|
176 |
else: |
|
177 |
matches_number = 0 |
|
1773
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
178 |
search_results_tree_infos = { |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
179 |
"name": _("Project '%s':") % self.ParentWindow.Controler.GetProjectName(), |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
180 |
"type": ITEM_PROJECT, |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
181 |
"data": None, |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
182 |
"text": None, |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
183 |
"matches": None, |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
184 |
} |
814 | 185 |
search_results_tree_children = search_results_tree_infos.setdefault("children", []) |
186 |
for tagname in self.ElementsOrder: |
|
187 |
results = self.SearchResults.get(tagname, []) |
|
188 |
matches_number += len(results) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
189 |
|
814 | 190 |
words = tagname.split("::") |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
191 |
|
814 | 192 |
element_type = self.ParentWindow.Controler.GetElementType(tagname) |
193 |
if element_type == ITEM_POU: |
|
194 |
element_type = self.ParentWindow.Controler.GetPouType(words[1]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
195 |
|
814 | 196 |
element_infos = {"name": words[-1], |
197 |
"type": element_type, |
|
198 |
"data": tagname, |
|
199 |
"text": None, |
|
200 |
"matches": len(results)} |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
201 |
|
814 | 202 |
children = element_infos.setdefault("children", []) |
203 |
for infos, start, end, text in results: |
|
204 |
if infos[1] == "name" or element_type == ITEM_DATATYPE: |
|
205 |
child_name = GenerateName(infos[1:]) |
|
206 |
child_type = element_type |
|
207 |
else: |
|
208 |
if element_type == ITEM_RESOURCE: |
|
209 |
child_type = element_type |
|
210 |
else: |
|
211 |
child_type = infos[1] |
|
212 |
if child_type == "name": |
|
213 |
child_name = "name" |
|
214 |
elif child_type == "body": |
|
215 |
child_name = "body" |
|
216 |
if element_type == ITEM_TRANSITION: |
|
217 |
child_type = self.ParentWindow.Controler.GetTransitionBodyType(words[1], words[2]) |
|
218 |
elif element_type == ITEM_ACTION: |
|
219 |
child_type = self.ParentWindow.Controler.GetActionBodyType(words[1], words[2]) |
|
220 |
else: |
|
221 |
child_type = self.ParentWindow.Controler.GetPouBodyType(words[1]) |
|
222 |
else: |
|
223 |
child_name = GenerateName(infos[3:]) |
|
1773
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
224 |
child_infos = { |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
225 |
"name": child_name, |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
226 |
"type": child_type, |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
227 |
"data": (infos, start, end, None), |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
228 |
"text": text, |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
229 |
"matches": 1, |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
230 |
"children": [], |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
231 |
} |
814 | 232 |
children.append(child_infos) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
233 |
|
814 | 234 |
if len(words) > 2: |
235 |
for _element_infos in search_results_tree_children: |
|
236 |
if _element_infos["name"] == words[1]: |
|
237 |
_element_infos["matches"] += len(children) |
|
238 |
_element_infos["children"].append(element_infos) |
|
239 |
break |
|
899
64aa66d481c5
Fix bug in resource search result highlighting
Laurent Bessard
parents:
814
diff
changeset
|
240 |
if element_type == ITEM_RESOURCE: |
64aa66d481c5
Fix bug in resource search result highlighting
Laurent Bessard
parents:
814
diff
changeset
|
241 |
search_results_tree_children.append(element_infos) |
814 | 242 |
else: |
243 |
search_results_tree_children.append(element_infos) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
244 |
|
814 | 245 |
if matches_number < 2: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
246 |
header_format = _("'{a1}' - {a2} match in project") |
814 | 247 |
else: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
248 |
header_format = _("'{a1}' - {a2} matches in project") |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
249 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
250 |
self.HeaderLabel.SetLabel(header_format.format(a1=self.Criteria["find_pattern"], a2=matches_number)) |
814 | 251 |
self.ResetButton.Enable(True) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
252 |
|
814 | 253 |
if matches_number > 0: |
254 |
root = self.SearchResultsTree.GetRootItem() |
|
255 |
if root is None: |
|
256 |
root = self.SearchResultsTree.AddRoot(search_results_tree_infos["name"]) |
|
257 |
self.GenerateSearchResultsTreeBranch(root, search_results_tree_infos) |
|
258 |
self.SearchResultsTree.Expand(root) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
259 |
|
814 | 260 |
def GetTextCtrlClickFunction(self, item): |
261 |
def OnTextCtrlClick(event): |
|
262 |
self.SearchResultsTree.SelectItem(item) |
|
263 |
event.Skip() |
|
264 |
return OnTextCtrlClick |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
265 |
|
814 | 266 |
def GetTextCtrlDClickFunction(self, item): |
267 |
def OnTextCtrlDClick(event): |
|
268 |
self.ShowSearchResults(item) |
|
269 |
event.Skip() |
|
270 |
return OnTextCtrlDClick |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
271 |
|
814 | 272 |
def GenerateSearchResultsTreeBranch(self, root, infos): |
273 |
to_delete = [] |
|
274 |
if infos["name"] == "body": |
|
275 |
item_name = "%d:" % infos["data"][1][0] |
|
276 |
else: |
|
277 |
item_name = infos["name"] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
278 |
|
814 | 279 |
self.SearchResultsTree.SetItemText(root, item_name) |
280 |
self.SearchResultsTree.SetPyData(root, infos["data"]) |
|
281 |
self.SearchResultsTree.SetItemBackgroundColour(root, wx.WHITE) |
|
282 |
self.SearchResultsTree.SetItemTextColour(root, wx.BLACK) |
|
283 |
if infos["type"] is not None: |
|
284 |
if infos["type"] == ITEM_POU: |
|
285 |
self.SearchResultsTree.SetItemImage(root, self.TreeImageDict[self.ParentWindow.Controler.GetPouType(infos["name"])]) |
|
286 |
else: |
|
287 |
self.SearchResultsTree.SetItemImage(root, self.TreeImageDict[infos["type"]]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
288 |
|
814 | 289 |
text = None |
290 |
if infos["text"] is not None: |
|
291 |
text = infos["text"] |
|
292 |
start, end = infos["data"][1:3] |
|
293 |
text_lines = infos["text"].splitlines() |
|
294 |
start_idx = start[1] |
|
295 |
end_idx = reduce(lambda x, y: x + y, map(lambda x: len(x) + 1, text_lines[:end[0] - start[0]]), end[1] + 1) |
|
296 |
style = wx.TextAttr(wx.BLACK, wx.Colour(206, 204, 247)) |
|
297 |
elif infos["type"] is not None and infos["matches"] > 1: |
|
298 |
text = _("(%d matches)") % infos["matches"] |
|
299 |
start_idx, end_idx = 0, len(text) |
|
300 |
style = wx.TextAttr(wx.Colour(0, 127, 174)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
301 |
|
814 | 302 |
if text is not None: |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
303 |
text_ctrl_style = wx.BORDER_NONE | wx.TE_READONLY | wx.TE_RICH2 |
814 | 304 |
if wx.Platform != '__WXMSW__' or len(text.splitlines()) > 1: |
305 |
text_ctrl_style |= wx.TE_MULTILINE |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
306 |
text_ctrl = wx.TextCtrl(id=-1, parent=self.SearchResultsTree, pos=wx.Point(0, 0), |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
307 |
value=text, style=text_ctrl_style) |
814 | 308 |
width, height = text_ctrl.GetTextExtent(text) |
309 |
text_ctrl.SetClientSize(wx.Size(width + 1, height)) |
|
310 |
text_ctrl.SetBackgroundColour(self.SearchResultsTree.GetBackgroundColour()) |
|
311 |
text_ctrl.Bind(wx.EVT_LEFT_DOWN, self.GetTextCtrlClickFunction(root)) |
|
312 |
text_ctrl.Bind(wx.EVT_LEFT_DCLICK, self.GetTextCtrlDClickFunction(root)) |
|
313 |
text_ctrl.SetInsertionPoint(0) |
|
314 |
text_ctrl.SetStyle(start_idx, end_idx, style) |
|
315 |
self.SearchResultsTree.SetItemWindow(root, text_ctrl) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
316 |
|
814 | 317 |
if wx.VERSION >= (2, 6, 0): |
318 |
item, root_cookie = self.SearchResultsTree.GetFirstChild(root) |
|
319 |
else: |
|
320 |
item, root_cookie = self.SearchResultsTree.GetFirstChild(root, 0) |
|
321 |
for child in infos["children"]: |
|
322 |
if item is None: |
|
323 |
item = self.SearchResultsTree.AppendItem(root, "") |
|
324 |
item, root_cookie = self.SearchResultsTree.GetNextChild(root, root_cookie) |
|
325 |
self.GenerateSearchResultsTreeBranch(item, child) |
|
326 |
item, root_cookie = self.SearchResultsTree.GetNextChild(root, root_cookie) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
327 |
|
814 | 328 |
def ShowSearchResults(self, item): |
329 |
data = self.SearchResultsTree.GetPyData(item) |
|
330 |
if isinstance(data, TupleType): |
|
331 |
search_results = [data] |
|
332 |
else: |
|
333 |
search_results = self.SearchResults.get(data, []) |
|
1622
a0c7a6cb1690
fix highlight of search result in Search Result Panel
Surkov Sergey <surkovsv93@gmail.com>
parents:
1621
diff
changeset
|
334 |
self.ParentWindow.ClearHighlights(SEARCH_RESULT_HIGHLIGHT) |
814 | 335 |
for infos, start, end, text in search_results: |
336 |
self.ParentWindow.ShowSearchResult(infos, start, end) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
337 |
|
814 | 338 |
def OnSearchResultsTreeItemActivated(self, event): |
339 |
self.ShowSearchResults(event.GetItem()) |
|
340 |
event.Skip() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
341 |
|
814 | 342 |
def OnResetButton(self, event): |
343 |
self.ResetSearchResults() |
|
344 |
self.ParentWindow.ClearSearchResults() |
|
345 |
event.Skip() |