author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Mon, 31 Oct 2016 13:59:56 +0300 | |
changeset 1559 | 91129212e9a6 |
parent 1558 | d75cc9ad328e |
child 1571 | 486f94a8032c |
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 re |
|
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
26 |
from plcopen.plcopen import * |
814 | 27 |
import wx |
28 |
||
29 |
#------------------------------------------------------------------------------- |
|
30 |
# Search In Project Dialog |
|
31 |
#------------------------------------------------------------------------------- |
|
32 |
||
33 |
def GetElementsChoices(): |
|
34 |
_ = lambda x: x |
|
35 |
return [("datatype", _("Data Type")), |
|
36 |
("function", _("Function")), |
|
37 |
("functionBlock", _("Function Block")), |
|
38 |
("program", _("Program")), |
|
39 |
("configuration", _("Configuration"))] |
|
40 |
||
41 |
class SearchInProjectDialog(wx.Dialog): |
|
42 |
||
43 |
def __init__(self, parent): |
|
44 |
wx.Dialog.__init__(self, parent, title=_('Search in Project'), |
|
45 |
size=wx.Size(600, 350)) |
|
46 |
||
47 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
|
48 |
main_sizer.AddGrowableCol(0) |
|
49 |
main_sizer.AddGrowableRow(1) |
|
50 |
||
51 |
pattern_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=5) |
|
52 |
pattern_sizer.AddGrowableCol(0) |
|
53 |
main_sizer.AddSizer(pattern_sizer, border=20, |
|
54 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
55 |
||
56 |
pattern_label = wx.StaticText(self, label=_('Pattern to search:')) |
|
57 |
pattern_sizer.AddWindow(pattern_label, flag=wx.ALIGN_BOTTOM) |
|
58 |
||
59 |
self.CaseSensitive = wx.CheckBox(self, label=_('Case sensitive')) |
|
60 |
pattern_sizer.AddWindow(self.CaseSensitive, flag=wx.GROW) |
|
61 |
||
62 |
self.Pattern = wx.TextCtrl(self) |
|
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
63 |
self.Bind(wx.EVT_TEXT, self.FindPatternChanged, self.Pattern) |
814 | 64 |
pattern_sizer.AddWindow(self.Pattern, flag=wx.GROW) |
1558
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
65 |
self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey) |
814 | 66 |
self.RegularExpression = wx.CheckBox(self, label=_('Regular expression')) |
67 |
pattern_sizer.AddWindow(self.RegularExpression, flag=wx.GROW) |
|
68 |
||
69 |
scope_staticbox = wx.StaticBox(self, label=_('Scope')) |
|
70 |
scope_sizer = wx.StaticBoxSizer(scope_staticbox, wx.HORIZONTAL) |
|
71 |
main_sizer.AddSizer(scope_sizer, border=20, |
|
72 |
flag=wx.GROW|wx.LEFT|wx.RIGHT) |
|
73 |
||
74 |
scope_selection_sizer = wx.BoxSizer(wx.VERTICAL) |
|
75 |
scope_sizer.AddSizer(scope_selection_sizer, 1, border=5, |
|
76 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.BOTTOM) |
|
77 |
||
78 |
self.WholeProject = wx.RadioButton(self, label=_('Whole Project'), |
|
79 |
size=wx.Size(0, 24), style=wx.RB_GROUP) |
|
80 |
self.WholeProject.SetValue(True) |
|
81 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, self.WholeProject) |
|
82 |
scope_selection_sizer.AddWindow(self.WholeProject, border=5, |
|
83 |
flag=wx.GROW|wx.BOTTOM) |
|
84 |
||
85 |
self.OnlyElements = wx.RadioButton(self, |
|
86 |
label=_('Only Elements'), size=wx.Size(0, 24)) |
|
87 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, self.OnlyElements) |
|
88 |
self.OnlyElements.SetValue(False) |
|
89 |
scope_selection_sizer.AddWindow(self.OnlyElements, flag=wx.GROW) |
|
90 |
||
91 |
self.ElementsList = wx.CheckListBox(self) |
|
92 |
self.ElementsList.Enable(False) |
|
93 |
scope_sizer.AddWindow(self.ElementsList, 1, border=5, |
|
94 |
flag=wx.GROW|wx.TOP|wx.RIGHT|wx.BOTTOM) |
|
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
95 |
|
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
96 |
buttons_sizer = wx.BoxSizer(wx.HORIZONTAL) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
97 |
main_sizer.AddSizer(buttons_sizer, border=20, |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
98 |
flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_RIGHT) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
99 |
|
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
100 |
self.FindButton = wx.Button(self, label=_("Find")) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
101 |
self.FindButton.SetDefault() |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
102 |
self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
103 |
buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
104 |
|
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
105 |
self.CloseButton = wx.Button(self, label=_("Close")) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
106 |
self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
107 |
buttons_sizer.AddWindow(self.CloseButton) |
814 | 108 |
|
109 |
self.SetSizer(main_sizer) |
|
110 |
||
111 |
for name, label in GetElementsChoices(): |
|
112 |
self.ElementsList.Append(_(label)) |
|
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
113 |
self.infosPrev = {} |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
114 |
self.criteria = {} |
814 | 115 |
self.Pattern.SetFocus() |
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
116 |
self.RefreshButtonsState() |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
117 |
|
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
118 |
def RefreshButtonsState(self): |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
119 |
find_pattern = self.Pattern.GetValue() |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
120 |
self.FindButton.Enable(find_pattern != "") |
814 | 121 |
|
122 |
def GetCriteria(self): |
|
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
123 |
return self.criteria |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
124 |
|
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
125 |
def FindPatternChanged(self, event): |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
126 |
self.RefreshButtonsState() |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
127 |
event.Skip() |
1558
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
128 |
|
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
129 |
def OnScopeChanged(self, event): |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
130 |
self.ElementsList.Enable(self.OnlyElements.GetValue()) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
131 |
event.Skip() |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
132 |
|
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
133 |
def OnCloseButton(self, event): |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
134 |
self.EndModal(wx.ID_CANCEL) |
1558
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
135 |
|
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
136 |
def OnEscapeKey(self, event): |
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
137 |
keycode = event.GetKeyCode() |
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
138 |
if keycode == wx.WXK_ESCAPE: |
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
139 |
self.OnCloseButton(event) |
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
140 |
else: |
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
141 |
event.Skip() |
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
142 |
|
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
143 |
def OnFindButton(self, event): |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
144 |
message = None |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
145 |
infos = { |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
146 |
"find_pattern": self.Pattern.GetValue(), |
814 | 147 |
"case_sensitive": self.CaseSensitive.GetValue(), |
148 |
"regular_expression": self.RegularExpression.GetValue(), |
|
149 |
} |
|
150 |
if self.WholeProject.GetValue(): |
|
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
151 |
infos["filter"] = "all" |
814 | 152 |
elif self.OnlyElements.GetValue(): |
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
153 |
infos["filter"] = [] |
814 | 154 |
for index, (name, label) in enumerate(GetElementsChoices()): |
155 |
if self.ElementsList.IsChecked(index): |
|
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
156 |
infos["filter"].append(name) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
157 |
|
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
158 |
if self.infosPrev != infos: |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
159 |
try: |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
160 |
self.criteria = infos |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
161 |
CompilePattern(self.criteria) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
162 |
self.infosPrev = infos |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
163 |
except: |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
814
diff
changeset
|
164 |
self.criteria.clear() |
814 | 165 |
message = _("Syntax error in regular expression of pattern to search!") |
166 |
||
167 |
if message is not None: |
|
168 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
169 |
dialog.ShowModal() |
|
170 |
dialog.Destroy() |
|
171 |
else: |
|
172 |
self.EndModal(wx.ID_OK) |