author | Laurent Bessard |
Sun, 12 May 2013 23:30:00 +0200 | |
changeset 1122 | 84de51ab40d2 |
parent 1098 | 0ead830daf26 |
child 1490 | f03bc6c9c146 |
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 |
||
29 |
def __init__(self, parent): |
|
30 |
wx.Frame.__init__(self, parent, title=_("Find"), |
|
31 |
size=wx.Size(400, 250), style=wx.CAPTION| |
|
32 |
wx.CLOSE_BOX| |
|
33 |
wx.CLIP_CHILDREN| |
|
34 |
wx.RESIZE_BORDER| |
|
35 |
wx.STAY_ON_TOP) |
|
36 |
||
37 |
panel = wx.Panel(self, style=wx.TAB_TRAVERSAL) |
|
38 |
||
39 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5) |
|
40 |
main_sizer.AddGrowableCol(0) |
|
41 |
main_sizer.AddGrowableRow(0) |
|
42 |
||
43 |
controls_sizer = wx.BoxSizer(wx.VERTICAL) |
|
44 |
main_sizer.AddSizer(controls_sizer, border=20, |
|
45 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
46 |
||
47 |
patterns_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5) |
|
48 |
patterns_sizer.AddGrowableCol(1) |
|
49 |
controls_sizer.AddSizer(patterns_sizer, border=5, flag=wx.GROW|wx.BOTTOM) |
|
50 |
||
51 |
find_label = wx.StaticText(panel, label=_("Find:")) |
|
52 |
patterns_sizer.AddWindow(find_label, flag=wx.ALIGN_CENTER_VERTICAL) |
|
53 |
||
54 |
self.FindPattern = wx.TextCtrl(panel) |
|
55 |
self.Bind(wx.EVT_TEXT, self.OnFindPatternChanged, self.FindPattern) |
|
56 |
patterns_sizer.AddWindow(self.FindPattern, flag=wx.GROW) |
|
57 |
||
58 |
params_sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
59 |
controls_sizer.AddSizer(params_sizer, border=5, flag=wx.GROW|wx.BOTTOM) |
|
60 |
||
61 |
direction_staticbox = wx.StaticBox(panel, label=_("Direction")) |
|
62 |
direction_staticboxsizer = wx.StaticBoxSizer( |
|
63 |
direction_staticbox, wx.VERTICAL) |
|
64 |
params_sizer.AddSizer(direction_staticboxsizer, 1, border=5, |
|
65 |
flag=wx.GROW|wx.RIGHT) |
|
66 |
||
67 |
self.Forward = wx.RadioButton(panel, label=_("Forward"), |
|
68 |
style=wx.RB_GROUP) |
|
69 |
direction_staticboxsizer.AddWindow(self.Forward, border=5, |
|
70 |
flag=wx.ALL|wx.GROW) |
|
71 |
||
72 |
self.Backward = wx.RadioButton(panel, label=_("Backward")) |
|
73 |
direction_staticboxsizer.AddWindow(self.Backward, border=5, |
|
74 |
flag=wx.ALL|wx.GROW) |
|
75 |
||
76 |
options_staticbox = wx.StaticBox(panel, label=_("Options")) |
|
77 |
options_staticboxsizer = wx.StaticBoxSizer( |
|
78 |
options_staticbox, wx.VERTICAL) |
|
79 |
params_sizer.AddSizer(options_staticboxsizer, 1, flag=wx.GROW) |
|
80 |
||
81 |
self.CaseSensitive = wx.CheckBox(panel, label=_("Case sensitive")) |
|
82 |
self.CaseSensitive.SetValue(True) |
|
83 |
options_staticboxsizer.AddWindow(self.CaseSensitive, border=5, |
|
84 |
flag=wx.ALL|wx.GROW) |
|
85 |
||
86 |
self.WrapSearch = wx.CheckBox(panel, label=_("Wrap search")) |
|
87 |
self.WrapSearch.SetValue(True) |
|
88 |
options_staticboxsizer.AddWindow(self.WrapSearch, border=5, |
|
89 |
flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW) |
|
90 |
||
91 |
self.RegularExpressions = wx.CheckBox(panel, label=_("Regular expressions")) |
|
92 |
options_staticboxsizer.AddWindow(self.RegularExpressions, border=5, |
|
93 |
flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW) |
|
94 |
||
95 |
buttons_sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
96 |
main_sizer.AddSizer(buttons_sizer, border=20, |
|
97 |
flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT) |
|
98 |
||
99 |
self.FindButton = wx.Button(panel, label=_("Find")) |
|
1098
0ead830daf26
Fixed bug when pressing Return key in FindInPouDialog
Laurent Bessard
parents:
1056
diff
changeset
|
100 |
self.FindButton.SetDefault() |
814 | 101 |
self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton) |
102 |
buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT) |
|
103 |
||
104 |
self.CloseButton = wx.Button(panel, label=("Close")) |
|
105 |
self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton) |
|
106 |
buttons_sizer.AddWindow(self.CloseButton) |
|
107 |
||
108 |
panel.SetSizer(main_sizer) |
|
109 |
||
110 |
self.ParentWindow = parent |
|
111 |
||
112 |
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
|
113 |
|
f7aaf31d000f
Fixed pattern textctrl in FindInPouDialog to get focus when dialog appear
Laurent Bessard
parents:
814
diff
changeset
|
114 |
self.FindPattern.SetFocus() |
814 | 115 |
self.RefreshButtonsState() |
116 |
||
117 |
def RefreshButtonsState(self): |
|
118 |
find_pattern = self.FindPattern.GetValue() |
|
119 |
self.FindButton.Enable(find_pattern != "") |
|
120 |
||
121 |
def OnCloseFrame(self, event): |
|
122 |
self.Hide() |
|
123 |
event.Veto() |
|
124 |
||
125 |
def OnCloseButton(self, event): |
|
126 |
self.Hide() |
|
127 |
event.Skip() |
|
128 |
||
129 |
def OnFindPatternChanged(self, event): |
|
130 |
self.RefreshButtonsState() |
|
131 |
event.Skip() |
|
132 |
||
133 |
def OnFindButton(self, event): |
|
134 |
infos = { |
|
135 |
"find_pattern": self.FindPattern.GetValue(), |
|
136 |
"wrap": self.WrapSearch.GetValue(), |
|
137 |
"case_sensitive": self.CaseSensitive.GetValue(), |
|
138 |
"regular_expression": self.RegularExpressions.GetValue()} |
|
139 |
wx.CallAfter(self.ParentWindow.FindInPou, |
|
140 |
{True: 1, False:-1}[self.Forward.GetValue()], |
|
141 |
infos) |
|
142 |
event.Skip() |