Laurent@738: #!/usr/bin/env python Laurent@738: # -*- coding: utf-8 -*- Laurent@738: Laurent@738: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor Laurent@738: #based on the plcopen standard. Laurent@738: # Laurent@738: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD Laurent@738: # Laurent@738: #See COPYING file for copyrights details. Laurent@738: # Laurent@738: #This library is free software; you can redistribute it and/or Laurent@738: #modify it under the terms of the GNU General Public Laurent@738: #License as published by the Free Software Foundation; either Laurent@738: #version 2.1 of the License, or (at your option) any later version. Laurent@738: # Laurent@738: #This library is distributed in the hope that it will be useful, Laurent@738: #but WITHOUT ANY WARRANTY; without even the implied warranty of Laurent@738: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Laurent@738: #General Public License for more details. Laurent@738: # Laurent@738: #You should have received a copy of the GNU General Public Laurent@738: #License along with this library; if not, write to the Free Software Laurent@738: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Laurent@738: Laurent@738: import wx Laurent@738: Laurent@738: class FindInPouDialog(wx.Frame): Laurent@738: Laurent@738: def __init__(self, parent): Laurent@738: wx.Frame.__init__(self, parent, title=_("Find"), Laurent@738: size=wx.Size(400, 250), style=wx.CAPTION| Laurent@738: wx.CLOSE_BOX| Laurent@738: wx.CLIP_CHILDREN| Laurent@738: wx.RESIZE_BORDER| Laurent@738: wx.STAY_ON_TOP) Laurent@738: Laurent@739: panel = wx.Panel(self, style=wx.TAB_TRAVERSAL) Laurent@739: Laurent@738: main_sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5) Laurent@738: main_sizer.AddGrowableCol(0) Laurent@738: main_sizer.AddGrowableRow(0) Laurent@738: Laurent@738: controls_sizer = wx.BoxSizer(wx.VERTICAL) Laurent@738: main_sizer.AddSizer(controls_sizer, border=20, Laurent@738: flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) Laurent@738: Laurent@738: patterns_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5) Laurent@738: patterns_sizer.AddGrowableCol(1) Laurent@738: controls_sizer.AddSizer(patterns_sizer, border=5, flag=wx.GROW|wx.BOTTOM) Laurent@738: Laurent@739: find_label = wx.StaticText(panel, label=_("Find:")) Laurent@738: patterns_sizer.AddWindow(find_label, flag=wx.ALIGN_CENTER_VERTICAL) Laurent@738: Laurent@739: self.FindPattern = wx.TextCtrl(panel) Laurent@738: self.Bind(wx.EVT_TEXT, self.OnFindPatternChanged, self.FindPattern) Laurent@738: patterns_sizer.AddWindow(self.FindPattern, flag=wx.GROW) Laurent@738: Laurent@738: params_sizer = wx.BoxSizer(wx.HORIZONTAL) Laurent@738: controls_sizer.AddSizer(params_sizer, border=5, flag=wx.GROW|wx.BOTTOM) Laurent@738: Laurent@739: direction_staticbox = wx.StaticBox(panel, label=_("Direction")) Laurent@738: direction_staticboxsizer = wx.StaticBoxSizer( Laurent@738: direction_staticbox, wx.VERTICAL) Laurent@738: params_sizer.AddSizer(direction_staticboxsizer, 1, border=5, Laurent@738: flag=wx.GROW|wx.RIGHT) Laurent@738: Laurent@739: self.Forward = wx.RadioButton(panel, label=_("Forward"), Laurent@738: style=wx.RB_GROUP) Laurent@738: direction_staticboxsizer.AddWindow(self.Forward, border=5, Laurent@738: flag=wx.ALL|wx.GROW) Laurent@738: Laurent@739: self.Backward = wx.RadioButton(panel, label=_("Backward")) Laurent@738: direction_staticboxsizer.AddWindow(self.Backward, border=5, Laurent@738: flag=wx.ALL|wx.GROW) Laurent@738: Laurent@739: options_staticbox = wx.StaticBox(panel, label=_("Options")) Laurent@738: options_staticboxsizer = wx.StaticBoxSizer( Laurent@738: options_staticbox, wx.VERTICAL) Laurent@738: params_sizer.AddSizer(options_staticboxsizer, 1, flag=wx.GROW) Laurent@738: Laurent@739: self.CaseSensitive = wx.CheckBox(panel, label=_("Case sensitive")) Laurent@738: self.CaseSensitive.SetValue(True) Laurent@738: options_staticboxsizer.AddWindow(self.CaseSensitive, border=5, Laurent@738: flag=wx.ALL|wx.GROW) Laurent@738: Laurent@739: self.WrapSearch = wx.CheckBox(panel, label=_("Wrap search")) Laurent@738: self.WrapSearch.SetValue(True) Laurent@738: options_staticboxsizer.AddWindow(self.WrapSearch, border=5, Laurent@738: flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW) Laurent@738: Laurent@739: self.RegularExpressions = wx.CheckBox(panel, label=_("Regular expressions")) Laurent@738: options_staticboxsizer.AddWindow(self.RegularExpressions, border=5, Laurent@738: flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW) Laurent@738: Laurent@738: buttons_sizer = wx.BoxSizer(wx.HORIZONTAL) Laurent@738: main_sizer.AddSizer(buttons_sizer, border=20, Laurent@738: flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT) Laurent@738: Laurent@739: self.FindButton = wx.Button(panel, label=_("Find")) Laurent@738: self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton) Laurent@738: buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT) Laurent@738: Laurent@739: self.CloseButton = wx.Button(panel, label=("Close")) Laurent@738: self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton) Laurent@738: buttons_sizer.AddWindow(self.CloseButton) Laurent@738: Laurent@739: panel.SetSizer(main_sizer) Laurent@738: Laurent@738: self.ParentWindow = parent Laurent@738: Laurent@738: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) Laurent@738: Laurent@738: self.RefreshButtonsState() Laurent@738: Laurent@738: def RefreshButtonsState(self): Laurent@738: find_pattern = self.FindPattern.GetValue() Laurent@738: self.FindButton.Enable(find_pattern != "") Laurent@738: Laurent@738: def OnCloseFrame(self, event): Laurent@738: self.Hide() Laurent@738: event.Veto() Laurent@738: Laurent@738: def OnCloseButton(self, event): Laurent@738: self.Hide() Laurent@738: event.Skip() Laurent@738: Laurent@738: def OnFindPatternChanged(self, event): Laurent@738: self.RefreshButtonsState() Laurent@738: event.Skip() Laurent@738: Laurent@738: def OnFindButton(self, event): Laurent@738: infos = { Laurent@738: "find_pattern": self.FindPattern.GetValue(), Laurent@738: "wrap": self.WrapSearch.GetValue(), Laurent@738: "case_sensitive": self.CaseSensitive.GetValue(), Laurent@738: "regular_expression": self.RegularExpressions.GetValue()} Laurent@738: wx.CallAfter(self.ParentWindow.FindInPou, Laurent@738: {True: 1, False:-1}[self.Forward.GetValue()], Laurent@738: infos) Laurent@738: event.Skip()