--- a/dialogs/FindInPouDialog.py Sun Mar 05 00:38:25 2017 +0000
+++ b/dialogs/FindInPouDialog.py Fri Mar 24 12:07:47 2017 +0000
@@ -1,39 +1,45 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
-#based on the plcopen standard.
+# This file is part of Beremiz, a Integrated Development Environment for
+# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
#
-#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
#
-#See COPYING file for copyrights details.
+# See COPYING file for copyrights details.
#
-#This library is free software; you can redistribute it and/or
-#modify it under the terms of the GNU General Public
-#License as published by the Free Software Foundation; either
-#version 2.1 of the License, or (at your option) any later version.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
#
-#This library is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-#General Public License for more details.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-#You should have received a copy of the GNU General Public
-#License along with this library; if not, write to the Free Software
-#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import wx
+from plcopen.plcopen import *
-class FindInPouDialog(wx.Frame):
+class FindInPouDialog(wx.Dialog):
+ def _init_icon(self, parent):
+ if parent and parent.icon:
+ self.SetIcon(parent.icon)
+
+
def __init__(self, parent):
- wx.Frame.__init__(self, parent, title=_("Find"),
- size=wx.Size(400, 250), style=wx.CAPTION|
+ wx.Dialog.__init__(self, parent, title=_("Find"),
+ size=wx.Size(500, 280), style=wx.CAPTION|
wx.CLOSE_BOX|
wx.CLIP_CHILDREN|
- wx.RESIZE_BORDER|
- wx.STAY_ON_TOP)
+ wx.RESIZE_BORDER)
+ self._init_icon(parent)
panel = wx.Panel(self, style=wx.TAB_TRAVERSAL)
main_sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5)
@@ -53,6 +59,7 @@
self.FindPattern = wx.TextCtrl(panel)
self.Bind(wx.EVT_TEXT, self.OnFindPatternChanged, self.FindPattern)
+ self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey)
patterns_sizer.AddWindow(self.FindPattern, flag=wx.GROW)
params_sizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -101,16 +108,21 @@
self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton)
buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT)
- self.CloseButton = wx.Button(panel, label=("Close"))
+ self.CloseButton = wx.Button(panel, label=_("Close"))
self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton)
buttons_sizer.AddWindow(self.CloseButton)
+
+ self.StatusLabel = wx.StaticText(panel, label= "")
+ controls_sizer.AddWindow(self.StatusLabel, flag=wx.ALIGN_CENTER_VERTICAL)
panel.SetSizer(main_sizer)
+ main_sizer.Fit(self)
self.ParentWindow = parent
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
-
+ self.infosPrev = {}
+ self.criteria = {}
self.FindPattern.SetFocus()
self.RefreshButtonsState()
@@ -126,17 +138,41 @@
self.Hide()
event.Skip()
+ def OnEscapeKey(self, event):
+ keycode = event.GetKeyCode()
+ if keycode == wx.WXK_ESCAPE:
+ self.OnCloseButton(event)
+ else:
+ event.Skip()
+
def OnFindPatternChanged(self, event):
self.RefreshButtonsState()
event.Skip()
+ def SetStatusText(self, msg):
+ self.StatusLabel.SetLabel(msg)
+ self.Layout()
+
def OnFindButton(self, event):
infos = {
"find_pattern": self.FindPattern.GetValue(),
"wrap": self.WrapSearch.GetValue(),
"case_sensitive": self.CaseSensitive.GetValue(),
- "regular_expression": self.RegularExpressions.GetValue()}
- wx.CallAfter(self.ParentWindow.FindInPou,
- {True: 1, False:-1}[self.Forward.GetValue()],
- infos)
+ "regular_expression": self.RegularExpressions.GetValue(),
+ "filter": "all"}
+
+ if self.infosPrev != infos:
+ self.infosPrev = infos
+ message = ""
+ try:
+ self.criteria = infos
+ CompilePattern(self.criteria)
+ except:
+ self.criteria.clear()
+ message = _("Syntax error in regular expression of pattern to search!")
+ self.SetStatusText(message)
+ if len(self.criteria) > 0:
+ wx.CallAfter(self.ParentWindow.FindInPou,
+ {True: 1, False:-1}[self.Forward.GetValue()],
+ self.criteria)
event.Skip()