dialogs/FindInPouDialog.py
changeset 1911 c1298e7ffe3a
parent 1620 3bffe3bd8d78
child 1696 8043f32de7b8
equal deleted inserted replaced
1910:a375e31bf312 1911:c1298e7ffe3a
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 
     3 
     4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
     4 # This file is part of Beremiz, a Integrated Development Environment for
     5 #based on the plcopen standard. 
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     6 #
     6 #
     7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     8 #
     8 #
     9 #See COPYING file for copyrights details.
     9 # See COPYING file for copyrights details.
    10 #
    10 #
    11 #This library is free software; you can redistribute it and/or
    11 # This program is free software; you can redistribute it and/or
    12 #modify it under the terms of the GNU General Public
    12 # modify it under the terms of the GNU General Public License
    13 #License as published by the Free Software Foundation; either
    13 # as published by the Free Software Foundation; either version 2
    14 #version 2.1 of the License, or (at your option) any later version.
    14 # of the License, or (at your option) any later version.
    15 #
    15 #
    16 #This library is distributed in the hope that it will be useful,
    16 # This program is distributed in the hope that it will be useful,
    17 #but WITHOUT ANY WARRANTY; without even the implied warranty of
    17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19 #General Public License for more details.
    19 # GNU General Public License for more details.
    20 #
    20 #
    21 #You should have received a copy of the GNU General Public
    21 # You should have received a copy of the GNU General Public License
    22 #License along with this library; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 import wx
    25 import wx
       
    26 from plcopen.plcopen import *
    26 
    27 
    27 class FindInPouDialog(wx.Frame):
    28 class FindInPouDialog(wx.Dialog):
    28 
    29 
       
    30     def _init_icon(self, parent):
       
    31         if parent and parent.icon:
       
    32                 self.SetIcon(parent.icon)
       
    33 
       
    34     
    29     def __init__(self, parent):
    35     def __init__(self, parent):
    30         wx.Frame.__init__(self, parent, title=_("Find"), 
    36         wx.Dialog.__init__(self, parent, title=_("Find"),         
    31               size=wx.Size(400, 250), style=wx.CAPTION|
    37               size=wx.Size(500, 280), style=wx.CAPTION|
    32                                             wx.CLOSE_BOX|
    38                                             wx.CLOSE_BOX|
    33                                             wx.CLIP_CHILDREN|
    39                                             wx.CLIP_CHILDREN|
    34                                             wx.RESIZE_BORDER|
    40                                             wx.RESIZE_BORDER)
    35                                             wx.STAY_ON_TOP)
       
    36         
    41         
       
    42         self._init_icon(parent)
    37         panel = wx.Panel(self, style=wx.TAB_TRAVERSAL)
    43         panel = wx.Panel(self, style=wx.TAB_TRAVERSAL)
    38         
    44         
    39         main_sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5)
    45         main_sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5)
    40         main_sizer.AddGrowableCol(0)
    46         main_sizer.AddGrowableCol(0)
    41         main_sizer.AddGrowableRow(0)
    47         main_sizer.AddGrowableRow(0)
    51         find_label = wx.StaticText(panel, label=_("Find:"))
    57         find_label = wx.StaticText(panel, label=_("Find:"))
    52         patterns_sizer.AddWindow(find_label, flag=wx.ALIGN_CENTER_VERTICAL)
    58         patterns_sizer.AddWindow(find_label, flag=wx.ALIGN_CENTER_VERTICAL)
    53         
    59         
    54         self.FindPattern = wx.TextCtrl(panel)
    60         self.FindPattern = wx.TextCtrl(panel)
    55         self.Bind(wx.EVT_TEXT, self.OnFindPatternChanged, self.FindPattern)
    61         self.Bind(wx.EVT_TEXT, self.OnFindPatternChanged, self.FindPattern)
       
    62         self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey)
    56         patterns_sizer.AddWindow(self.FindPattern, flag=wx.GROW)
    63         patterns_sizer.AddWindow(self.FindPattern, flag=wx.GROW)
    57         
    64         
    58         params_sizer = wx.BoxSizer(wx.HORIZONTAL)
    65         params_sizer = wx.BoxSizer(wx.HORIZONTAL)
    59         controls_sizer.AddSizer(params_sizer, border=5, flag=wx.GROW|wx.BOTTOM)
    66         controls_sizer.AddSizer(params_sizer, border=5, flag=wx.GROW|wx.BOTTOM)
    60         
    67         
    99         self.FindButton = wx.Button(panel, label=_("Find"))
   106         self.FindButton = wx.Button(panel, label=_("Find"))
   100         self.FindButton.SetDefault()
   107         self.FindButton.SetDefault()
   101         self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton)
   108         self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton)
   102         buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT)
   109         buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT)
   103         
   110         
   104         self.CloseButton = wx.Button(panel, label=("Close"))
   111         self.CloseButton = wx.Button(panel, label=_("Close"))
   105         self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton)
   112         self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton)
   106         buttons_sizer.AddWindow(self.CloseButton)
   113         buttons_sizer.AddWindow(self.CloseButton)
       
   114 
       
   115         self.StatusLabel = wx.StaticText(panel, label= "")
       
   116         controls_sizer.AddWindow(self.StatusLabel, flag=wx.ALIGN_CENTER_VERTICAL)
   107         
   117         
   108         panel.SetSizer(main_sizer)
   118         panel.SetSizer(main_sizer)
       
   119         main_sizer.Fit(self)
   109         
   120         
   110         self.ParentWindow = parent
   121         self.ParentWindow = parent
   111         
   122         
   112         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
   123         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
   113         
   124         self.infosPrev = {}
       
   125         self.criteria = {}
   114         self.FindPattern.SetFocus()
   126         self.FindPattern.SetFocus()
   115         self.RefreshButtonsState()
   127         self.RefreshButtonsState()
   116     
   128     
   117     def RefreshButtonsState(self):
   129     def RefreshButtonsState(self):
   118         find_pattern = self.FindPattern.GetValue()
   130         find_pattern = self.FindPattern.GetValue()
   124         
   136         
   125     def OnCloseButton(self, event):
   137     def OnCloseButton(self, event):
   126         self.Hide()
   138         self.Hide()
   127         event.Skip()
   139         event.Skip()
   128 
   140 
       
   141     def OnEscapeKey(self, event):
       
   142         keycode = event.GetKeyCode()
       
   143         if keycode == wx.WXK_ESCAPE:
       
   144             self.OnCloseButton(event)
       
   145         else:
       
   146             event.Skip()
       
   147 
   129     def OnFindPatternChanged(self, event):
   148     def OnFindPatternChanged(self, event):
   130         self.RefreshButtonsState()
   149         self.RefreshButtonsState()
   131         event.Skip()
   150         event.Skip()
   132 
   151 
       
   152     def SetStatusText(self, msg):
       
   153         self.StatusLabel.SetLabel(msg)
       
   154         self.Layout()
       
   155         
   133     def OnFindButton(self, event):
   156     def OnFindButton(self, event):
   134         infos = {
   157         infos = {
   135             "find_pattern": self.FindPattern.GetValue(),
   158             "find_pattern": self.FindPattern.GetValue(),
   136             "wrap": self.WrapSearch.GetValue(),
   159             "wrap": self.WrapSearch.GetValue(),
   137             "case_sensitive": self.CaseSensitive.GetValue(),
   160             "case_sensitive": self.CaseSensitive.GetValue(),
   138             "regular_expression": self.RegularExpressions.GetValue()}
   161             "regular_expression": self.RegularExpressions.GetValue(),
   139         wx.CallAfter(self.ParentWindow.FindInPou,
   162             "filter": "all"}
   140             {True: 1, False:-1}[self.Forward.GetValue()],
   163 
   141             infos)
   164         if self.infosPrev != infos:
       
   165             self.infosPrev = infos
       
   166             message = ""
       
   167             try:
       
   168                 self.criteria = infos
       
   169                 CompilePattern(self.criteria)
       
   170             except:
       
   171                 self.criteria.clear()
       
   172                 message = _("Syntax error in regular expression of pattern to search!")
       
   173             self.SetStatusText(message)
       
   174         if len(self.criteria) > 0:
       
   175             wx.CallAfter(self.ParentWindow.FindInPou,
       
   176                 {True: 1, False:-1}[self.Forward.GetValue()],
       
   177                 self.criteria)
   142         event.Skip()
   178         event.Skip()