author | Edouard Tisserant <edouard@beremiz.fr> |
Thu, 05 Dec 2024 16:45:37 +0100 | |
changeset 4061 | e0dfe8b8db4a |
parent 3971 | f1c673cddc1f |
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 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
25 |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3303
diff
changeset
|
26 |
|
2456
7373e3048167
python3 support: pylint,W1610 # (reduce-builtin) reduce built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2450
diff
changeset
|
27 |
from functools import reduce |
814 | 28 |
|
29 |
import wx |
|
30 |
import wx.lib.buttons |
|
31 |
import wx.lib.agw.customtreectrl as CT |
|
32 |
||
33 |
from PLCControler import * |
|
34 |
from util.BitmapLibrary import GetBitmap |
|
1948
b9a3f771aaab
Moved some definitions away from controller class, and adaped references them through all code.
Edouard Tisserant
parents:
1884
diff
changeset
|
35 |
from plcopen.types_enums import GetElementType |
814 | 36 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1733
diff
changeset
|
37 |
|
814 | 38 |
def GenerateName(infos): |
39 |
if infos[0] in ["input", "output", "value"]: |
|
40 |
return "%s %d:" % (infos[0], infos[1]) |
|
41 |
elif infos[0] == "range": |
|
42 |
return "%s %d %s" % (infos[0], infos[1], infos[2]) |
|
43 |
elif infos[0] == "struct": |
|
44 |
return "element %d %s" % (infos[1], infos[2]) |
|
45 |
return "%s:" % infos[0] |
|
46 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
47 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
48 |
# ------------------------------------------------------------------------------- |
814 | 49 |
# Search Result Panel |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
50 |
# ------------------------------------------------------------------------------- |
814 | 51 |
|
52 |
class SearchResultPanel(wx.Panel): |
|
53 |
||
54 |
def _init_coll_MainSizer_Items(self, parent): |
|
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:
2737
diff
changeset
|
55 |
parent.Add(self.HeaderSizer, 0, border=0, flag=wx.GROW) |
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:
2737
diff
changeset
|
56 |
parent.Add(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
|
57 |
|
814 | 58 |
def _init_coll_MainSizer_Growables(self, parent): |
59 |
parent.AddGrowableCol(0) |
|
60 |
parent.AddGrowableRow(1) |
|
61 |
||
62 |
def _init_coll_HeaderSizer_Items(self, parent): |
|
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:
2737
diff
changeset
|
63 |
parent.Add(self.HeaderLabel, 1, border=5, flag=wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL) |
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:
2737
diff
changeset
|
64 |
parent.Add(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
|
65 |
|
814 | 66 |
def _init_coll_HeaderSizer_Growables(self, parent): |
67 |
parent.AddGrowableCol(0) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
68 |
|
814 | 69 |
def _init_sizers(self): |
70 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
71 |
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
|
72 |
|
814 | 73 |
self._init_coll_MainSizer_Items(self.MainSizer) |
74 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
|
75 |
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
|
76 |
|
814 | 77 |
self.SetSizer(self.MainSizer) |
78 |
||
79 |
def _init_ctrls(self, prnt): |
|
2737
38afed869ff6
Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents:
2551
diff
changeset
|
80 |
self.HeaderLabel = wx.StaticText(name='HeaderLabel', parent=self, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
81 |
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
|
82 |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
83 |
search_results_tree_style = CT.TR_HAS_BUTTONS | CT.TR_NO_LINES | CT.TR_HAS_VARIABLE_ROW_HEIGHT |
2737
38afed869ff6
Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents:
2551
diff
changeset
|
84 |
self.SearchResultsTree = CT.CustomTreeCtrl(name="SearchResultsTree", parent=self, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
85 |
pos=wx.Point(0, 0), style=search_results_tree_style) |
2737
38afed869ff6
Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents:
2551
diff
changeset
|
86 |
self.SearchResultsTree.SetAGWWindowStyleFlag(search_results_tree_style) |
814 | 87 |
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnSearchResultsTreeItemActivated, |
2737
38afed869ff6
Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents:
2551
diff
changeset
|
88 |
self.SearchResultsTree) |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
89 |
|
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
90 |
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
|
91 |
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
|
92 |
size=wx.Size(28, 28), style=wx.NO_BORDER) |
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:
2737
diff
changeset
|
93 |
self.ResetButton.SetToolTip(_("Reset search result")) |
814 | 94 |
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
|
95 |
|
814 | 96 |
self._init_sizers() |
97 |
||
98 |
def __init__(self, parent, window): |
|
2737
38afed869ff6
Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents:
2551
diff
changeset
|
99 |
wx.Panel.__init__(self, |
1836
d42b6cf00fa6
fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
100 |
name='SearchResultPanel', parent=parent, |
d42b6cf00fa6
fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
101 |
pos=wx.Point(0, 0), |
d42b6cf00fa6
fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
102 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
d42b6cf00fa6
fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
103 |
|
814 | 104 |
self.ParentWindow = window |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
105 |
|
814 | 106 |
self._init_ctrls(parent) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
107 |
|
814 | 108 |
# Define Tree item icon list |
109 |
self.TreeImageList = wx.ImageList(16, 16) |
|
110 |
self.TreeImageDict = {} |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
111 |
|
814 | 112 |
# Icons for other items |
113 |
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
|
114 |
# 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
|
115 |
("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
|
116 |
("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
|
117 |
("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
|
118 |
("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
|
119 |
("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
|
120 |
("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
|
121 |
("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
|
122 |
("IL", "IL"), |
2524
c80b0d864475
WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents:
2456
diff
changeset
|
123 |
("ST", "ST"), |
2551
245644bfcd24
Make spaghetti-code-quality great again.
Edouard Tisserant
parents:
2529
diff
changeset
|
124 |
("FILE", ITEM_CONFNODE)]: |
814 | 125 |
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
|
126 |
|
814 | 127 |
for itemtype in ["function", "functionBlock", "program", |
128 |
"comment", "block", "io_variable", |
|
129 |
"connector", "contact", "coil", |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
130 |
"step", "transition", "jump", |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
131 |
"var_local", "var_input", |
814 | 132 |
"var_inout", "var_output"]: |
133 |
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
|
134 |
|
814 | 135 |
# Assign icon list to TreeCtrl |
136 |
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
|
137 |
|
814 | 138 |
self.ResetSearchResults() |
139 |
||
140 |
def SetSearchResults(self, criteria, search_results): |
|
141 |
self.Criteria = criteria |
|
142 |
self.SearchResults = {} |
|
143 |
self.ElementsOrder = [] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
144 |
|
814 | 145 |
for infos, start, end, text in search_results: |
146 |
if infos[0] not in self.ElementsOrder: |
|
147 |
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
|
148 |
|
814 | 149 |
results = self.SearchResults.setdefault(infos[0], []) |
150 |
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
|
151 |
|
814 | 152 |
self.RefreshView() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
153 |
|
814 | 154 |
def ResetSearchResults(self): |
155 |
self.Criteria = None |
|
156 |
self.ElementsOrder = [] |
|
157 |
self.SearchResults = {} |
|
158 |
self.RefreshView() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
159 |
|
814 | 160 |
def RefreshView(self): |
161 |
self.SearchResultsTree.DeleteAllItems() |
|
162 |
if self.Criteria is None: |
|
1884
48bd91d7a0ae
fix missing root in empty search results panel
Surkov Sergey <surkovsv93@gmail.com>
parents:
1881
diff
changeset
|
163 |
self.SearchResultsTree.AddRoot("") |
48bd91d7a0ae
fix missing root in empty search results panel
Surkov Sergey <surkovsv93@gmail.com>
parents:
1881
diff
changeset
|
164 |
root = self.SearchResultsTree.GetRootItem() |
48bd91d7a0ae
fix missing root in empty search results panel
Surkov Sergey <surkovsv93@gmail.com>
parents:
1881
diff
changeset
|
165 |
root.SetHilight(False) |
814 | 166 |
self.HeaderLabel.SetLabel(_("No search results available.")) |
167 |
self.ResetButton.Enable(False) |
|
168 |
else: |
|
169 |
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
|
170 |
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
|
171 |
"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
|
172 |
"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
|
173 |
"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
|
174 |
"text": None, |
3971
f1c673cddc1f
IDE: Fix search result not showing single occurrences
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3789
diff
changeset
|
175 |
"matches": 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
|
176 |
} |
814 | 177 |
search_results_tree_children = search_results_tree_infos.setdefault("children", []) |
178 |
for tagname in self.ElementsOrder: |
|
179 |
results = self.SearchResults.get(tagname, []) |
|
180 |
matches_number += len(results) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
181 |
|
814 | 182 |
words = tagname.split("::") |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
183 |
|
1948
b9a3f771aaab
Moved some definitions away from controller class, and adaped references them through all code.
Edouard Tisserant
parents:
1884
diff
changeset
|
184 |
element_type = GetElementType(tagname) |
814 | 185 |
if element_type == ITEM_POU: |
186 |
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
|
187 |
|
814 | 188 |
element_infos = {"name": words[-1], |
189 |
"type": element_type, |
|
190 |
"data": tagname, |
|
191 |
"text": None, |
|
192 |
"matches": len(results)} |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
193 |
|
814 | 194 |
children = element_infos.setdefault("children", []) |
195 |
for infos, start, end, text in results: |
|
2524
c80b0d864475
WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents:
2456
diff
changeset
|
196 |
if len(words) == 1: # CTN match |
2551
245644bfcd24
Make spaghetti-code-quality great again.
Edouard Tisserant
parents:
2529
diff
changeset
|
197 |
child_name = {"body": str(start[0])+":", |
245644bfcd24
Make spaghetti-code-quality great again.
Edouard Tisserant
parents:
2529
diff
changeset
|
198 |
"var_inout": _("Variable:")}[infos[1]] |
245644bfcd24
Make spaghetti-code-quality great again.
Edouard Tisserant
parents:
2529
diff
changeset
|
199 |
child_type = {"body": ITEM_CONFNODE, |
245644bfcd24
Make spaghetti-code-quality great again.
Edouard Tisserant
parents:
2529
diff
changeset
|
200 |
"var_inout": "var_inout"}[infos[1]] |
2524
c80b0d864475
WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents:
2456
diff
changeset
|
201 |
elif infos[1] == "name" or element_type == ITEM_DATATYPE: |
814 | 202 |
child_name = GenerateName(infos[1:]) |
203 |
child_type = element_type |
|
204 |
else: |
|
205 |
if element_type == ITEM_RESOURCE: |
|
206 |
child_type = element_type |
|
207 |
else: |
|
208 |
child_type = infos[1] |
|
209 |
if child_type == "name": |
|
210 |
child_name = "name" |
|
211 |
elif child_type == "body": |
|
212 |
child_name = "body" |
|
213 |
if element_type == ITEM_TRANSITION: |
|
214 |
child_type = self.ParentWindow.Controler.GetTransitionBodyType(words[1], words[2]) |
|
215 |
elif element_type == ITEM_ACTION: |
|
216 |
child_type = self.ParentWindow.Controler.GetActionBodyType(words[1], words[2]) |
|
217 |
else: |
|
218 |
child_type = self.ParentWindow.Controler.GetPouBodyType(words[1]) |
|
219 |
else: |
|
220 |
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
|
221 |
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
|
222 |
"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
|
223 |
"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
|
224 |
"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
|
225 |
"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
|
226 |
"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
|
227 |
"children": [], |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
228 |
} |
814 | 229 |
children.append(child_infos) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
230 |
|
2524
c80b0d864475
WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents:
2456
diff
changeset
|
231 |
# not Project node |
814 | 232 |
if len(words) > 2: |
233 |
for _element_infos in search_results_tree_children: |
|
234 |
if _element_infos["name"] == words[1]: |
|
235 |
_element_infos["matches"] += len(children) |
|
236 |
_element_infos["children"].append(element_infos) |
|
237 |
break |
|
899
64aa66d481c5
Fix bug in resource search result highlighting
Laurent Bessard
parents:
814
diff
changeset
|
238 |
if element_type == ITEM_RESOURCE: |
64aa66d481c5
Fix bug in resource search result highlighting
Laurent Bessard
parents:
814
diff
changeset
|
239 |
search_results_tree_children.append(element_infos) |
2524
c80b0d864475
WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents:
2456
diff
changeset
|
240 |
else: # Project node or CTN |
814 | 241 |
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
|
242 |
|
814 | 243 |
if matches_number < 2: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
244 |
header_format = _("'{a1}' - {a2} match in project") |
814 | 245 |
else: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
246 |
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
|
247 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
248 |
self.HeaderLabel.SetLabel(header_format.format(a1=self.Criteria["find_pattern"], a2=matches_number)) |
814 | 249 |
self.ResetButton.Enable(True) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
250 |
|
814 | 251 |
if matches_number > 0: |
252 |
root = self.SearchResultsTree.GetRootItem() |
|
253 |
if root is None: |
|
254 |
root = self.SearchResultsTree.AddRoot(search_results_tree_infos["name"]) |
|
255 |
self.GenerateSearchResultsTreeBranch(root, search_results_tree_infos) |
|
256 |
self.SearchResultsTree.Expand(root) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
257 |
|
814 | 258 |
def GetTextCtrlClickFunction(self, item): |
259 |
def OnTextCtrlClick(event): |
|
260 |
self.SearchResultsTree.SelectItem(item) |
|
261 |
event.Skip() |
|
262 |
return OnTextCtrlClick |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
263 |
|
814 | 264 |
def GetTextCtrlDClickFunction(self, item): |
265 |
def OnTextCtrlDClick(event): |
|
266 |
self.ShowSearchResults(item) |
|
267 |
event.Skip() |
|
268 |
return OnTextCtrlDClick |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
269 |
|
814 | 270 |
def GenerateSearchResultsTreeBranch(self, root, infos): |
271 |
if infos["name"] == "body": |
|
272 |
item_name = "%d:" % infos["data"][1][0] |
|
273 |
else: |
|
274 |
item_name = infos["name"] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
275 |
|
814 | 276 |
self.SearchResultsTree.SetItemText(root, item_name) |
277 |
self.SearchResultsTree.SetPyData(root, infos["data"]) |
|
278 |
self.SearchResultsTree.SetItemBackgroundColour(root, wx.WHITE) |
|
279 |
self.SearchResultsTree.SetItemTextColour(root, wx.BLACK) |
|
280 |
if infos["type"] is not None: |
|
281 |
if infos["type"] == ITEM_POU: |
|
282 |
self.SearchResultsTree.SetItemImage(root, self.TreeImageDict[self.ParentWindow.Controler.GetPouType(infos["name"])]) |
|
283 |
else: |
|
284 |
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
|
285 |
|
814 | 286 |
text = None |
287 |
if infos["text"] is not None: |
|
288 |
text = infos["text"] |
|
289 |
start, end = infos["data"][1:3] |
|
290 |
text_lines = infos["text"].splitlines() |
|
291 |
start_idx = start[1] |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3303
diff
changeset
|
292 |
end_idx = reduce(lambda x, y: x + y, [len(x) + 1 for x in text_lines[:end[0] - start[0]]], end[1] + 1) |
814 | 293 |
style = wx.TextAttr(wx.BLACK, wx.Colour(206, 204, 247)) |
3971
f1c673cddc1f
IDE: Fix search result not showing single occurrences
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3789
diff
changeset
|
294 |
elif infos["type"] is not None and infos["matches"] > 0: |
814 | 295 |
text = _("(%d matches)") % infos["matches"] |
296 |
start_idx, end_idx = 0, len(text) |
|
297 |
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
|
298 |
|
814 | 299 |
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
|
300 |
text_ctrl_style = wx.BORDER_NONE | wx.TE_READONLY | wx.TE_RICH2 |
814 | 301 |
if wx.Platform != '__WXMSW__' or len(text.splitlines()) > 1: |
2524
c80b0d864475
WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents:
2456
diff
changeset
|
302 |
text_ctrl_style |= wx.TE_MULTILINE | wx.TE_NO_VSCROLL |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
303 |
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
|
304 |
value=text, style=text_ctrl_style) |
814 | 305 |
width, height = text_ctrl.GetTextExtent(text) |
306 |
text_ctrl.SetClientSize(wx.Size(width + 1, height)) |
|
307 |
text_ctrl.SetBackgroundColour(self.SearchResultsTree.GetBackgroundColour()) |
|
308 |
text_ctrl.Bind(wx.EVT_LEFT_DOWN, self.GetTextCtrlClickFunction(root)) |
|
309 |
text_ctrl.Bind(wx.EVT_LEFT_DCLICK, self.GetTextCtrlDClickFunction(root)) |
|
310 |
text_ctrl.SetInsertionPoint(0) |
|
311 |
text_ctrl.SetStyle(start_idx, end_idx, style) |
|
312 |
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
|
313 |
|
1870
4d070115b552
fix pylint error '(too-many-function-args) Too many positional arguments for function call'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
314 |
item, root_cookie = self.SearchResultsTree.GetFirstChild(root) |
814 | 315 |
for child in infos["children"]: |
316 |
if item is None: |
|
317 |
item = self.SearchResultsTree.AppendItem(root, "") |
|
318 |
item, root_cookie = self.SearchResultsTree.GetNextChild(root, root_cookie) |
|
319 |
self.GenerateSearchResultsTreeBranch(item, child) |
|
320 |
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
|
321 |
|
814 | 322 |
def ShowSearchResults(self, item): |
3789
8def429216ca
fix wxPyDeprecationWarnings
GP Orcullo <kinsamanka@gmail.com>
parents:
3750
diff
changeset
|
323 |
data = self.SearchResultsTree.GetItemData(item) |
2450
5024c19ca8f0
python3 support: pylint, W1652 # (deprecated-types-field) Accessing a deprecated fields on the types module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2177
diff
changeset
|
324 |
if isinstance(data, tuple): |
814 | 325 |
search_results = [data] |
326 |
else: |
|
327 |
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
|
328 |
self.ParentWindow.ClearHighlights(SEARCH_RESULT_HIGHLIGHT) |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
329 |
for infos, start, end, _text in search_results: |
814 | 330 |
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
|
331 |
|
814 | 332 |
def OnSearchResultsTreeItemActivated(self, event): |
333 |
self.ShowSearchResults(event.GetItem()) |
|
334 |
event.Skip() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1622
diff
changeset
|
335 |
|
814 | 336 |
def OnResetButton(self, event): |
337 |
self.ResetSearchResults() |
|
338 |
self.ParentWindow.ClearSearchResults() |
|
339 |
event.Skip() |