dialogs/FindInPouDialog.py
changeset 738 1ccd08cfae0c
child 739 ed87f96c7c12
equal deleted inserted replaced
737:85a4bc7dc31e 738:1ccd08cfae0c
       
     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.TAB_TRAVERSAL|
       
    35                                             wx.RESIZE_BORDER|
       
    36                                             wx.STAY_ON_TOP)
       
    37         
       
    38         main_sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5)
       
    39         main_sizer.AddGrowableCol(0)
       
    40         main_sizer.AddGrowableRow(0)
       
    41         
       
    42         controls_sizer = wx.BoxSizer(wx.VERTICAL)
       
    43         main_sizer.AddSizer(controls_sizer, border=20, 
       
    44               flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
       
    45         
       
    46         patterns_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5)
       
    47         patterns_sizer.AddGrowableCol(1)
       
    48         controls_sizer.AddSizer(patterns_sizer, border=5, flag=wx.GROW|wx.BOTTOM)
       
    49         
       
    50         find_label = wx.StaticText(self, label=_("Find:"))
       
    51         patterns_sizer.AddWindow(find_label, flag=wx.ALIGN_CENTER_VERTICAL)
       
    52         
       
    53         self.FindPattern = wx.TextCtrl(self)
       
    54         self.Bind(wx.EVT_TEXT, self.OnFindPatternChanged, self.FindPattern)
       
    55         patterns_sizer.AddWindow(self.FindPattern, flag=wx.GROW)
       
    56         
       
    57         params_sizer = wx.BoxSizer(wx.HORIZONTAL)
       
    58         controls_sizer.AddSizer(params_sizer, border=5, flag=wx.GROW|wx.BOTTOM)
       
    59         
       
    60         direction_staticbox = wx.StaticBox(self, label=_("Direction"))
       
    61         direction_staticboxsizer = wx.StaticBoxSizer(
       
    62               direction_staticbox, wx.VERTICAL)
       
    63         params_sizer.AddSizer(direction_staticboxsizer, 1, border=5, 
       
    64               flag=wx.GROW|wx.RIGHT)
       
    65         
       
    66         self.Forward = wx.RadioButton(self, label=_("Forward"), 
       
    67               style=wx.RB_GROUP)
       
    68         direction_staticboxsizer.AddWindow(self.Forward, border=5, 
       
    69               flag=wx.ALL|wx.GROW)
       
    70         
       
    71         self.Backward = wx.RadioButton(self, label=_("Backward"))
       
    72         direction_staticboxsizer.AddWindow(self.Backward, border=5, 
       
    73               flag=wx.ALL|wx.GROW)
       
    74         
       
    75         options_staticbox = wx.StaticBox(self, label=_("Options"))
       
    76         options_staticboxsizer = wx.StaticBoxSizer(
       
    77               options_staticbox, wx.VERTICAL)
       
    78         params_sizer.AddSizer(options_staticboxsizer, 1, flag=wx.GROW)
       
    79         
       
    80         self.CaseSensitive = wx.CheckBox(self, label=_("Case sensitive"))
       
    81         self.CaseSensitive.SetValue(True)
       
    82         options_staticboxsizer.AddWindow(self.CaseSensitive, border=5, 
       
    83               flag=wx.ALL|wx.GROW)
       
    84         
       
    85         self.WrapSearch = wx.CheckBox(self, label=_("Wrap search"))
       
    86         self.WrapSearch.SetValue(True)
       
    87         options_staticboxsizer.AddWindow(self.WrapSearch, border=5, 
       
    88               flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
       
    89         
       
    90         self.RegularExpressions = wx.CheckBox(self, label=_("Regular expressions"))
       
    91         options_staticboxsizer.AddWindow(self.RegularExpressions, border=5, 
       
    92               flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
       
    93         
       
    94         buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
       
    95         main_sizer.AddSizer(buttons_sizer, border=20, 
       
    96               flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT)
       
    97         
       
    98         self.FindButton = wx.Button(self, label=_("Find"))
       
    99         self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton)
       
   100         buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT)
       
   101         
       
   102         self.CloseButton = wx.Button(self, label=("Close"))
       
   103         self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton)
       
   104         buttons_sizer.AddWindow(self.CloseButton)
       
   105         
       
   106         self.SetSizer(main_sizer)
       
   107         
       
   108         self.ParentWindow = parent
       
   109         
       
   110         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
       
   111     
       
   112         self.RefreshButtonsState()
       
   113     
       
   114     def RefreshButtonsState(self):
       
   115         find_pattern = self.FindPattern.GetValue()
       
   116         self.FindButton.Enable(find_pattern != "")
       
   117     
       
   118     def OnCloseFrame(self, event):
       
   119         self.Hide()
       
   120         event.Veto()
       
   121         
       
   122     def OnCloseButton(self, event):
       
   123         self.Hide()
       
   124         event.Skip()
       
   125 
       
   126     def OnFindPatternChanged(self, event):
       
   127         self.RefreshButtonsState()
       
   128         event.Skip()
       
   129 
       
   130     def OnFindButton(self, event):
       
   131         infos = {
       
   132             "find_pattern": self.FindPattern.GetValue(),
       
   133             "wrap": self.WrapSearch.GetValue(),
       
   134             "case_sensitive": self.CaseSensitive.GetValue(),
       
   135             "regular_expression": self.RegularExpressions.GetValue()}
       
   136         wx.CallAfter(self.ParentWindow.FindInPou,
       
   137             {True: 1, False:-1}[self.Forward.GetValue()],
       
   138             infos)
       
   139         event.Skip()