author | Surkov Sergey <surkovsv93@gmail.com> |
Tue, 10 Jan 2017 14:08:49 +0300 | |
changeset 1621 | 4485e6478b91 |
parent 1620 | 3bffe3bd8d78 |
child 1696 | 8043f32de7b8 |
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:
1558
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:
1558
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1558
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
814 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1558
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
814 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1558
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:
1558
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:
1558
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:
1558
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
814 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1558
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:
1558
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:
1558
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:
1558
diff
changeset
|
19 |
# GNU General Public License for more details. |
814 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1558
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:
1558
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:
1558
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
25 |
import wx |
|
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
26 |
from plcopen.plcopen import * |
814 | 27 |
|
1618
474de7fdcfd9
convert FindInPouDialog from wx.Frame to wx.Dialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
28 |
class FindInPouDialog(wx.Dialog): |
814 | 29 |
|
1490
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1098
diff
changeset
|
30 |
def _init_icon(self, parent): |
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1098
diff
changeset
|
31 |
if parent and parent.icon: |
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1098
diff
changeset
|
32 |
self.SetIcon(parent.icon) |
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1098
diff
changeset
|
33 |
|
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1098
diff
changeset
|
34 |
|
814 | 35 |
def __init__(self, parent): |
1618
474de7fdcfd9
convert FindInPouDialog from wx.Frame to wx.Dialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
36 |
wx.Dialog.__init__(self, parent, title=_("Find"), |
474de7fdcfd9
convert FindInPouDialog from wx.Frame to wx.Dialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
37 |
size=wx.Size(500, 280), style=wx.CAPTION| |
814 | 38 |
wx.CLOSE_BOX| |
39 |
wx.CLIP_CHILDREN| |
|
1618
474de7fdcfd9
convert FindInPouDialog from wx.Frame to wx.Dialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
40 |
wx.RESIZE_BORDER) |
814 | 41 |
|
1490
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1098
diff
changeset
|
42 |
self._init_icon(parent) |
814 | 43 |
panel = wx.Panel(self, style=wx.TAB_TRAVERSAL) |
44 |
||
45 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5) |
|
46 |
main_sizer.AddGrowableCol(0) |
|
47 |
main_sizer.AddGrowableRow(0) |
|
48 |
||
49 |
controls_sizer = wx.BoxSizer(wx.VERTICAL) |
|
50 |
main_sizer.AddSizer(controls_sizer, border=20, |
|
51 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
52 |
||
53 |
patterns_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5) |
|
54 |
patterns_sizer.AddGrowableCol(1) |
|
55 |
controls_sizer.AddSizer(patterns_sizer, border=5, flag=wx.GROW|wx.BOTTOM) |
|
56 |
||
57 |
find_label = wx.StaticText(panel, label=_("Find:")) |
|
58 |
patterns_sizer.AddWindow(find_label, flag=wx.ALIGN_CENTER_VERTICAL) |
|
59 |
||
60 |
self.FindPattern = wx.TextCtrl(panel) |
|
61 |
self.Bind(wx.EVT_TEXT, self.OnFindPatternChanged, self.FindPattern) |
|
1558
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
62 |
self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey) |
814 | 63 |
patterns_sizer.AddWindow(self.FindPattern, flag=wx.GROW) |
64 |
||
65 |
params_sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
66 |
controls_sizer.AddSizer(params_sizer, border=5, flag=wx.GROW|wx.BOTTOM) |
|
67 |
||
68 |
direction_staticbox = wx.StaticBox(panel, label=_("Direction")) |
|
69 |
direction_staticboxsizer = wx.StaticBoxSizer( |
|
70 |
direction_staticbox, wx.VERTICAL) |
|
71 |
params_sizer.AddSizer(direction_staticboxsizer, 1, border=5, |
|
72 |
flag=wx.GROW|wx.RIGHT) |
|
73 |
||
74 |
self.Forward = wx.RadioButton(panel, label=_("Forward"), |
|
75 |
style=wx.RB_GROUP) |
|
76 |
direction_staticboxsizer.AddWindow(self.Forward, border=5, |
|
77 |
flag=wx.ALL|wx.GROW) |
|
78 |
||
79 |
self.Backward = wx.RadioButton(panel, label=_("Backward")) |
|
80 |
direction_staticboxsizer.AddWindow(self.Backward, border=5, |
|
81 |
flag=wx.ALL|wx.GROW) |
|
82 |
||
83 |
options_staticbox = wx.StaticBox(panel, label=_("Options")) |
|
84 |
options_staticboxsizer = wx.StaticBoxSizer( |
|
85 |
options_staticbox, wx.VERTICAL) |
|
86 |
params_sizer.AddSizer(options_staticboxsizer, 1, flag=wx.GROW) |
|
87 |
||
88 |
self.CaseSensitive = wx.CheckBox(panel, label=_("Case sensitive")) |
|
89 |
self.CaseSensitive.SetValue(True) |
|
90 |
options_staticboxsizer.AddWindow(self.CaseSensitive, border=5, |
|
91 |
flag=wx.ALL|wx.GROW) |
|
92 |
||
93 |
self.WrapSearch = wx.CheckBox(panel, label=_("Wrap search")) |
|
94 |
self.WrapSearch.SetValue(True) |
|
95 |
options_staticboxsizer.AddWindow(self.WrapSearch, border=5, |
|
96 |
flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW) |
|
97 |
||
98 |
self.RegularExpressions = wx.CheckBox(panel, label=_("Regular expressions")) |
|
99 |
options_staticboxsizer.AddWindow(self.RegularExpressions, border=5, |
|
100 |
flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW) |
|
101 |
||
102 |
buttons_sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
103 |
main_sizer.AddSizer(buttons_sizer, border=20, |
|
104 |
flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT) |
|
105 |
||
106 |
self.FindButton = wx.Button(panel, label=_("Find")) |
|
1098
0ead830daf26
Fixed bug when pressing Return key in FindInPouDialog
Laurent Bessard
parents:
1056
diff
changeset
|
107 |
self.FindButton.SetDefault() |
814 | 108 |
self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton) |
109 |
buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT) |
|
110 |
||
1490
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1098
diff
changeset
|
111 |
self.CloseButton = wx.Button(panel, label=_("Close")) |
814 | 112 |
self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton) |
113 |
buttons_sizer.AddWindow(self.CloseButton) |
|
1618
474de7fdcfd9
convert FindInPouDialog from wx.Frame to wx.Dialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
114 |
|
474de7fdcfd9
convert FindInPouDialog from wx.Frame to wx.Dialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
115 |
self.StatusLabel = wx.StaticText(panel, label= "") |
474de7fdcfd9
convert FindInPouDialog from wx.Frame to wx.Dialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
116 |
controls_sizer.AddWindow(self.StatusLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
814 | 117 |
|
118 |
panel.SetSizer(main_sizer) |
|
1620
3bffe3bd8d78
make FindInPouDialog work on Windows with wxPython 2.8
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1618
diff
changeset
|
119 |
main_sizer.Fit(self) |
814 | 120 |
|
121 |
self.ParentWindow = parent |
|
122 |
||
123 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
|
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
124 |
self.infosPrev = {} |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
125 |
self.criteria = {} |
1056
f7aaf31d000f
Fixed pattern textctrl in FindInPouDialog to get focus when dialog appear
Laurent Bessard
parents:
814
diff
changeset
|
126 |
self.FindPattern.SetFocus() |
814 | 127 |
self.RefreshButtonsState() |
128 |
||
129 |
def RefreshButtonsState(self): |
|
130 |
find_pattern = self.FindPattern.GetValue() |
|
131 |
self.FindButton.Enable(find_pattern != "") |
|
132 |
||
133 |
def OnCloseFrame(self, event): |
|
134 |
self.Hide() |
|
135 |
event.Veto() |
|
136 |
||
137 |
def OnCloseButton(self, event): |
|
138 |
self.Hide() |
|
139 |
event.Skip() |
|
140 |
||
1558
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
141 |
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
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
else: |
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
146 |
event.Skip() |
d75cc9ad328e
now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents:
1556
diff
changeset
|
147 |
|
814 | 148 |
def OnFindPatternChanged(self, event): |
149 |
self.RefreshButtonsState() |
|
150 |
event.Skip() |
|
151 |
||
1618
474de7fdcfd9
convert FindInPouDialog from wx.Frame to wx.Dialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
152 |
def SetStatusText(self, msg): |
474de7fdcfd9
convert FindInPouDialog from wx.Frame to wx.Dialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
153 |
self.StatusLabel.SetLabel(msg) |
474de7fdcfd9
convert FindInPouDialog from wx.Frame to wx.Dialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
154 |
self.Layout() |
474de7fdcfd9
convert FindInPouDialog from wx.Frame to wx.Dialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
155 |
|
814 | 156 |
def OnFindButton(self, event): |
157 |
infos = { |
|
158 |
"find_pattern": self.FindPattern.GetValue(), |
|
159 |
"wrap": self.WrapSearch.GetValue(), |
|
160 |
"case_sensitive": self.CaseSensitive.GetValue(), |
|
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
161 |
"regular_expression": self.RegularExpressions.GetValue(), |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
162 |
"filter": "all"} |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
163 |
|
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
164 |
if self.infosPrev != infos: |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
165 |
self.infosPrev = infos |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
166 |
message = "" |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
167 |
try: |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
168 |
self.criteria = infos |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
169 |
CompilePattern(self.criteria) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
170 |
except: |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
171 |
self.criteria.clear() |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
172 |
message = _("Syntax error in regular expression of pattern to search!") |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
173 |
self.SetStatusText(message) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
174 |
if len(self.criteria) > 0: |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
175 |
wx.CallAfter(self.ParentWindow.FindInPou, |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
176 |
{True: 1, False:-1}[self.Forward.GetValue()], |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1490
diff
changeset
|
177 |
self.criteria) |
814 | 178 |
event.Skip() |