author | Sergey Surkov <surkovsv93@gmail.com> |
Tue, 18 Oct 2016 17:44:08 +0300 | |
changeset 1544 | 2969c2123105 |
parent 1490 | f03bc6c9c146 |
child 1556 | 32e9d0ef30dc |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
import wx |
|
26 |
||
27 |
class FindInPouDialog(wx.Frame): |
|
28 |
||
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
|
29 |
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
|
30 |
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
|
31 |
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
|
32 |
|
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 |
|
814 | 34 |
def __init__(self, parent): |
35 |
wx.Frame.__init__(self, parent, title=_("Find"), |
|
36 |
size=wx.Size(400, 250), style=wx.CAPTION| |
|
37 |
wx.CLOSE_BOX| |
|
38 |
wx.CLIP_CHILDREN| |
|
39 |
wx.RESIZE_BORDER| |
|
40 |
wx.STAY_ON_TOP) |
|
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) |
|
62 |
patterns_sizer.AddWindow(self.FindPattern, flag=wx.GROW) |
|
63 |
||
64 |
params_sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
65 |
controls_sizer.AddSizer(params_sizer, border=5, flag=wx.GROW|wx.BOTTOM) |
|
66 |
||
67 |
direction_staticbox = wx.StaticBox(panel, label=_("Direction")) |
|
68 |
direction_staticboxsizer = wx.StaticBoxSizer( |
|
69 |
direction_staticbox, wx.VERTICAL) |
|
70 |
params_sizer.AddSizer(direction_staticboxsizer, 1, border=5, |
|
71 |
flag=wx.GROW|wx.RIGHT) |
|
72 |
||
73 |
self.Forward = wx.RadioButton(panel, label=_("Forward"), |
|
74 |
style=wx.RB_GROUP) |
|
75 |
direction_staticboxsizer.AddWindow(self.Forward, border=5, |
|
76 |
flag=wx.ALL|wx.GROW) |
|
77 |
||
78 |
self.Backward = wx.RadioButton(panel, label=_("Backward")) |
|
79 |
direction_staticboxsizer.AddWindow(self.Backward, border=5, |
|
80 |
flag=wx.ALL|wx.GROW) |
|
81 |
||
82 |
options_staticbox = wx.StaticBox(panel, label=_("Options")) |
|
83 |
options_staticboxsizer = wx.StaticBoxSizer( |
|
84 |
options_staticbox, wx.VERTICAL) |
|
85 |
params_sizer.AddSizer(options_staticboxsizer, 1, flag=wx.GROW) |
|
86 |
||
87 |
self.CaseSensitive = wx.CheckBox(panel, label=_("Case sensitive")) |
|
88 |
self.CaseSensitive.SetValue(True) |
|
89 |
options_staticboxsizer.AddWindow(self.CaseSensitive, border=5, |
|
90 |
flag=wx.ALL|wx.GROW) |
|
91 |
||
92 |
self.WrapSearch = wx.CheckBox(panel, label=_("Wrap search")) |
|
93 |
self.WrapSearch.SetValue(True) |
|
94 |
options_staticboxsizer.AddWindow(self.WrapSearch, border=5, |
|
95 |
flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW) |
|
96 |
||
97 |
self.RegularExpressions = wx.CheckBox(panel, label=_("Regular expressions")) |
|
98 |
options_staticboxsizer.AddWindow(self.RegularExpressions, border=5, |
|
99 |
flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW) |
|
100 |
||
101 |
buttons_sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
102 |
main_sizer.AddSizer(buttons_sizer, border=20, |
|
103 |
flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT) |
|
104 |
||
105 |
self.FindButton = wx.Button(panel, label=_("Find")) |
|
1098
0ead830daf26
Fixed bug when pressing Return key in FindInPouDialog
Laurent Bessard
parents:
1056
diff
changeset
|
106 |
self.FindButton.SetDefault() |
814 | 107 |
self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton) |
108 |
buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT) |
|
109 |
||
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
|
110 |
self.CloseButton = wx.Button(panel, label=_("Close")) |
814 | 111 |
self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton) |
112 |
buttons_sizer.AddWindow(self.CloseButton) |
|
113 |
||
114 |
panel.SetSizer(main_sizer) |
|
115 |
||
116 |
self.ParentWindow = parent |
|
117 |
||
118 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
|
1056
f7aaf31d000f
Fixed pattern textctrl in FindInPouDialog to get focus when dialog appear
Laurent Bessard
parents:
814
diff
changeset
|
119 |
|
f7aaf31d000f
Fixed pattern textctrl in FindInPouDialog to get focus when dialog appear
Laurent Bessard
parents:
814
diff
changeset
|
120 |
self.FindPattern.SetFocus() |
814 | 121 |
self.RefreshButtonsState() |
122 |
||
123 |
def RefreshButtonsState(self): |
|
124 |
find_pattern = self.FindPattern.GetValue() |
|
125 |
self.FindButton.Enable(find_pattern != "") |
|
126 |
||
127 |
def OnCloseFrame(self, event): |
|
128 |
self.Hide() |
|
129 |
event.Veto() |
|
130 |
||
131 |
def OnCloseButton(self, event): |
|
132 |
self.Hide() |
|
133 |
event.Skip() |
|
134 |
||
135 |
def OnFindPatternChanged(self, event): |
|
136 |
self.RefreshButtonsState() |
|
137 |
event.Skip() |
|
138 |
||
139 |
def OnFindButton(self, event): |
|
140 |
infos = { |
|
141 |
"find_pattern": self.FindPattern.GetValue(), |
|
142 |
"wrap": self.WrapSearch.GetValue(), |
|
143 |
"case_sensitive": self.CaseSensitive.GetValue(), |
|
144 |
"regular_expression": self.RegularExpressions.GetValue()} |
|
145 |
wx.CallAfter(self.ParentWindow.FindInPou, |
|
146 |
{True: 1, False:-1}[self.Forward.GetValue()], |
|
147 |
infos) |
|
148 |
event.Skip() |