dialogs/FindInPouDialog.py
author Laurent Bessard
Sat, 25 Aug 2012 14:44:49 +0200
changeset 745 ecd2effd4660
parent 739 ed87f96c7c12
permissions -rw-r--r--
Fix bug with Clipboard that generated segmentation fault when closing dialogs
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
     3
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
     6
#
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
     8
#
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    10
#
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    15
#
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    20
#
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    24
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    25
import wx
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    26
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    27
class FindInPouDialog(wx.Frame):
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    28
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    29
    def __init__(self, parent):
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    30
        wx.Frame.__init__(self, parent, title=_("Find"), 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    31
              size=wx.Size(400, 250), style=wx.CAPTION|
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    32
                                            wx.CLOSE_BOX|
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    33
                                            wx.CLIP_CHILDREN|
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    34
                                            wx.RESIZE_BORDER|
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    35
                                            wx.STAY_ON_TOP)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    36
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
    37
        panel = wx.Panel(self, style=wx.TAB_TRAVERSAL)
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
    38
        
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    39
        main_sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    40
        main_sizer.AddGrowableCol(0)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    41
        main_sizer.AddGrowableRow(0)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    42
        
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    43
        controls_sizer = wx.BoxSizer(wx.VERTICAL)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    44
        main_sizer.AddSizer(controls_sizer, border=20, 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    45
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    46
        
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    47
        patterns_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    48
        patterns_sizer.AddGrowableCol(1)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    49
        controls_sizer.AddSizer(patterns_sizer, border=5, flag=wx.GROW|wx.BOTTOM)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    50
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
    51
        find_label = wx.StaticText(panel, label=_("Find:"))
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    52
        patterns_sizer.AddWindow(find_label, flag=wx.ALIGN_CENTER_VERTICAL)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    53
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
    54
        self.FindPattern = wx.TextCtrl(panel)
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    55
        self.Bind(wx.EVT_TEXT, self.OnFindPatternChanged, self.FindPattern)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    56
        patterns_sizer.AddWindow(self.FindPattern, flag=wx.GROW)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    57
        
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    58
        params_sizer = wx.BoxSizer(wx.HORIZONTAL)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    59
        controls_sizer.AddSizer(params_sizer, border=5, flag=wx.GROW|wx.BOTTOM)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    60
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
    61
        direction_staticbox = wx.StaticBox(panel, label=_("Direction"))
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    62
        direction_staticboxsizer = wx.StaticBoxSizer(
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    63
              direction_staticbox, wx.VERTICAL)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    64
        params_sizer.AddSizer(direction_staticboxsizer, 1, border=5, 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    65
              flag=wx.GROW|wx.RIGHT)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    66
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
    67
        self.Forward = wx.RadioButton(panel, label=_("Forward"), 
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    68
              style=wx.RB_GROUP)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    69
        direction_staticboxsizer.AddWindow(self.Forward, border=5, 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    70
              flag=wx.ALL|wx.GROW)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    71
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
    72
        self.Backward = wx.RadioButton(panel, label=_("Backward"))
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    73
        direction_staticboxsizer.AddWindow(self.Backward, border=5, 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    74
              flag=wx.ALL|wx.GROW)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    75
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
    76
        options_staticbox = wx.StaticBox(panel, label=_("Options"))
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    77
        options_staticboxsizer = wx.StaticBoxSizer(
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    78
              options_staticbox, wx.VERTICAL)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    79
        params_sizer.AddSizer(options_staticboxsizer, 1, flag=wx.GROW)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    80
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
    81
        self.CaseSensitive = wx.CheckBox(panel, label=_("Case sensitive"))
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    82
        self.CaseSensitive.SetValue(True)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    83
        options_staticboxsizer.AddWindow(self.CaseSensitive, border=5, 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    84
              flag=wx.ALL|wx.GROW)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    85
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
    86
        self.WrapSearch = wx.CheckBox(panel, label=_("Wrap search"))
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    87
        self.WrapSearch.SetValue(True)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    88
        options_staticboxsizer.AddWindow(self.WrapSearch, border=5, 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    89
              flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    90
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
    91
        self.RegularExpressions = wx.CheckBox(panel, label=_("Regular expressions"))
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    92
        options_staticboxsizer.AddWindow(self.RegularExpressions, border=5, 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    93
              flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    94
        
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    95
        buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    96
        main_sizer.AddSizer(buttons_sizer, border=20, 
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    97
              flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
    98
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
    99
        self.FindButton = wx.Button(panel, label=_("Find"))
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   100
        self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   101
        buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   102
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
   103
        self.CloseButton = wx.Button(panel, label=("Close"))
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   104
        self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   105
        buttons_sizer.AddWindow(self.CloseButton)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   106
        
739
ed87f96c7c12 Fix FindInPouDialog background colour on Windows
Laurent Bessard
parents: 738
diff changeset
   107
        panel.SetSizer(main_sizer)
738
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   108
        
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   109
        self.ParentWindow = parent
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   110
        
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   111
        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   112
    
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   113
        self.RefreshButtonsState()
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   114
    
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   115
    def RefreshButtonsState(self):
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   116
        find_pattern = self.FindPattern.GetValue()
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   117
        self.FindButton.Enable(find_pattern != "")
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   118
    
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   119
    def OnCloseFrame(self, event):
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   120
        self.Hide()
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   121
        event.Veto()
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   122
        
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   123
    def OnCloseButton(self, event):
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   124
        self.Hide()
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   125
        event.Skip()
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   126
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   127
    def OnFindPatternChanged(self, event):
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   128
        self.RefreshButtonsState()
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   129
        event.Skip()
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   130
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   131
    def OnFindButton(self, event):
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   132
        infos = {
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   133
            "find_pattern": self.FindPattern.GetValue(),
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   134
            "wrap": self.WrapSearch.GetValue(),
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   135
            "case_sensitive": self.CaseSensitive.GetValue(),
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   136
            "regular_expression": self.RegularExpressions.GetValue()}
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   137
        wx.CallAfter(self.ParentWindow.FindInPou,
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   138
            {True: 1, False:-1}[self.Forward.GetValue()],
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   139
            infos)
1ccd08cfae0c Adding support for in POU graphical and textual editor
Laurent Bessard
parents:
diff changeset
   140
        event.Skip()