dialogs/SearchInProjectDialog.py
author Laurent Bessard
Thu, 14 Jun 2012 18:13:32 +0200
changeset 711 5f6a743dcde5
parent 577 9dbb79722fbc
child 714 131ea7f237b9
permissions -rw-r--r--
Adding support for exporting graph value to csv formatted string to clipboard
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
     1
#!/usr/bin/env python
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
     3
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
     5
#based on the plcopen standard. 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
     6
#
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
     8
#
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
     9
#See COPYING file for copyrights details.
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    10
#
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    15
#
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    19
#General Public License for more details.
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    20
#
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    24
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    25
import re
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    26
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    27
import wx
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    28
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    29
RE_ESCAPED_CHARACTERS = ".*+()[]?:|{}^$<>=-,"
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    30
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    31
def EscapeText(text):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    32
    text = text.replace('\\', '\\\\')
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    33
    for c in RE_ESCAPED_CHARACTERS:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    34
        text = text.replace(c, '\\' + c)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    35
    return text
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    36
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    37
#-------------------------------------------------------------------------------
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    38
#                          Search In Project Dialog
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    39
#-------------------------------------------------------------------------------
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    40
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    41
def GetElementsChoices():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    42
    _ = lambda x: x
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    43
    return [("datatype", _("Data Type")), 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    44
            ("function", _("Function")), 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    45
            ("functionBlock", _("Function Block")), 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    46
            ("program", _("Program")), 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    47
            ("configuration", _("Configuration"))]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    48
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    49
[ID_SEARCHINPROJECTDIALOG, ID_SEARCHINPROJECTDIALOGPATTERNLABEL, 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    50
 ID_SEARCHINPROJECTDIALOGPATTERN, ID_SEARCHINPROJECTDIALOGCASESENSITIVE,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    51
 ID_SEARCHINPROJECTDIALOGREGULAREXPRESSION, ID_SEARCHINPROJECTDIALOGSCOPESTATICBOX, 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    52
 ID_SEARCHINPROJECTDIALOGWHOLEPROJECT, ID_SEARCHINPROJECTDIALOGONLYELEMENTS,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    53
 ID_SEARCHINPROJECTDIALOGELEMENTSLIST,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    54
] = [wx.NewId() for _init_ctrls in range(9)]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    55
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    56
class SearchInProjectDialog(wx.Dialog):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    57
    
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    58
    if wx.VERSION < (2, 6, 0):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    59
        def Bind(self, event, function, id = None):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    60
            if id is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    61
                event(self, id, function)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    62
            else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    63
                event(self, function)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    64
    
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    65
    def _init_coll_MainSizer_Items(self, parent):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    66
        parent.AddSizer(self.PatternSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    67
        parent.AddSizer(self.ScopeSizer, 0, border=20, flag=wx.GROW|wx.LEFT|wx.RIGHT)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    68
        parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    69
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    70
    def _init_coll_MainSizer_Growables(self, parent):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    71
        parent.AddGrowableCol(0)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    72
        parent.AddGrowableRow(1)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    73
    
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    74
    def _init_coll_PatternSizer_Items(self, parent):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    75
        parent.AddWindow(self.PatternLabel, 0, border=0, flag=wx.ALIGN_BOTTOM)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    76
        parent.AddWindow(self.CaseSensitive, 0, border=0, flag=wx.GROW)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    77
        parent.AddWindow(self.Pattern, 0, border=0, flag=wx.GROW)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    78
        parent.AddWindow(self.RegularExpression, 0, border=0, flag=wx.GROW)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    79
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    80
    def _init_coll_PatternSizer_Growables(self, parent):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    81
        parent.AddGrowableCol(0)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    82
    
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    83
    def _init_coll_ScopeSizer_Items(self, parent):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    84
        parent.AddSizer(self.ScopeSelectionSizer, 1, border=5, flag=wx.GROW|wx.TOP|wx.LEFT|wx.BOTTOM)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    85
        parent.AddWindow(self.ElementsList, 1, border=5, flag=wx.GROW|wx.TOP|wx.RIGHT|wx.BOTTOM)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    86
    
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    87
    def _init_coll_ScopeSelectionSizer_Items(self, parent):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    88
        parent.AddWindow(self.WholeProject, 0, border=5, flag=wx.GROW|wx.BOTTOM)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    89
        parent.AddWindow(self.OnlyElements, 0, border=0, flag=wx.GROW)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    90
    
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    91
    def _init_sizers(self):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    92
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    93
        self.PatternSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=5)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    94
        self.ScopeSizer = wx.StaticBoxSizer(self.ScopeStaticBox, wx.HORIZONTAL)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    95
        self.ScopeSelectionSizer = wx.BoxSizer(wx.VERTICAL)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    96
        
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    97
        self._init_coll_MainSizer_Items(self.MainSizer)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    98
        self._init_coll_MainSizer_Growables(self.MainSizer)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
    99
        self._init_coll_PatternSizer_Items(self.PatternSizer)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   100
        self._init_coll_PatternSizer_Growables(self.PatternSizer)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   101
        self._init_coll_ScopeSizer_Items(self.ScopeSizer)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   102
        self._init_coll_ScopeSelectionSizer_Items(self.ScopeSelectionSizer)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   103
        
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   104
        self.SetSizer(self.MainSizer)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   105
    
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   106
    def _init_ctrls(self, prnt):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   107
        wx.Dialog.__init__(self, id=ID_SEARCHINPROJECTDIALOG,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   108
              name='SearchInProjectDialog', parent=prnt,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   109
              size=wx.Size(600, 300), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   110
              title=_('Search in Project'))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   111
        
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   112
        self.PatternLabel = wx.StaticText(id=ID_SEARCHINPROJECTDIALOGPATTERNLABEL,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   113
              label=_('Pattern to search:'), name='PatternLabel', parent=self,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   114
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   115
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   116
        self.Pattern = wx.TextCtrl(id=ID_SEARCHINPROJECTDIALOGPATTERN,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   117
              name='Pattern', parent=self, pos=wx.Point(0, 0),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   118
              size=wx.Size(0, 24), style=0)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   119
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   120
        self.CaseSensitive = wx.CheckBox(id=ID_SEARCHINPROJECTDIALOGCASESENSITIVE,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   121
              label=_('Case sensitive'), name='CaseSensitive', parent=self, 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   122
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   123
        
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   124
        self.RegularExpression = wx.CheckBox(id=ID_SEARCHINPROJECTDIALOGREGULAREXPRESSION,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   125
              label=_('Regular expression'), name='RegularExpression', parent=self, 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   126
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   127
        
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   128
        self.ScopeStaticBox = wx.StaticBox(id=ID_SEARCHINPROJECTDIALOGSCOPESTATICBOX,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   129
              label=_('Scope'), name='ScopeStaticBox', parent=self,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   130
              pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   131
        
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   132
        self.WholeProject = wx.RadioButton(id=ID_SEARCHINPROJECTDIALOGWHOLEPROJECT,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   133
              label=_('Whole Project'), name='WholeProject', parent=self,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   134
              pos=wx.Point(0, 0), size=wx.Size(0, 24), style=wx.RB_GROUP)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   135
        self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, id=ID_SEARCHINPROJECTDIALOGWHOLEPROJECT)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   136
        self.WholeProject.SetValue(True)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   137
        
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   138
        self.OnlyElements = wx.RadioButton(id=ID_SEARCHINPROJECTDIALOGONLYELEMENTS,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   139
              label=_('Only Elements'), name='OnlyElements', parent=self,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   140
              pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   141
        self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, id=ID_SEARCHINPROJECTDIALOGONLYELEMENTS)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   142
        self.OnlyElements.SetValue(False)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   143
        
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   144
        self.ElementsList = wx.CheckListBox(id=ID_SEARCHINPROJECTDIALOGELEMENTSLIST,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   145
              name='ElementsList', parent=self, pos=wx.Point(0, 0), 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   146
              size=wx.Size(0, 0), style=0)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   147
        self.ElementsList.Enable(False)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   148
        
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   149
        self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   150
        if wx.VERSION >= (2, 5, 0):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   151
            ok_button = self.ButtonSizer.GetAffirmativeButton()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   152
        else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   153
            ok_button = self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   154
        ok_button.SetLabel(_('Search'))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   155
        self.Bind(wx.EVT_BUTTON, self.OnOK, id=ok_button.GetId())
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   156
        
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   157
        self._init_sizers()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   158
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   159
    def __init__(self, parent):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   160
        self._init_ctrls(parent)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   161
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   162
        for name, label in GetElementsChoices():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   163
            self.ElementsList.Append(_(label))
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 571
diff changeset
   164
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 571
diff changeset
   165
        self.Pattern.SetFocus()
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   166
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   167
    def GetCriteria(self):
571
79af7b821233 Fixing search in project feature for Windows
laurent
parents: 566
diff changeset
   168
        raw_pattern = pattern = self.Pattern.GetValue()
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   169
        if not self.CaseSensitive.GetValue():
571
79af7b821233 Fixing search in project feature for Windows
laurent
parents: 566
diff changeset
   170
            pattern = pattern.upper()
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   171
        if not self.RegularExpression.GetValue():
571
79af7b821233 Fixing search in project feature for Windows
laurent
parents: 566
diff changeset
   172
            pattern = EscapeText(pattern)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   173
        criteria = {
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   174
            "raw_pattern": raw_pattern, 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   175
            "pattern": re.compile(pattern),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   176
            "case_sensitive": self.CaseSensitive.GetValue(),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   177
            "regular_expression": self.RegularExpression.GetValue(),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   178
        }
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   179
        if self.WholeProject.GetValue():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   180
            criteria["filter"] = "all"
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   181
        elif self.OnlyElements.GetValue():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   182
            criteria["filter"] = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   183
            for index, (name, label) in enumerate(GetElementsChoices()):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   184
                if self.ElementsList.IsChecked(index):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   185
                    criteria["filter"].append(name)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   186
        return criteria
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   187
    
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   188
    def OnScopeChanged(self, event):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   189
        self.ElementsList.Enable(self.OnlyElements.GetValue())
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   190
        event.Skip()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   191
    
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   192
    def OnOK(self, event):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   193
        if self.Pattern.GetValue() == "":
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   194
            message = wx.MessageDialog(self, _("Form isn't complete. Pattern to search must be filled!"), _("Error"), wx.OK|wx.ICON_ERROR)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   195
            message.ShowModal()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   196
            message.Destroy()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   197
        else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   198
            wrong_pattern = False
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   199
            if self.RegularExpression.GetValue():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   200
                try:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   201
                    re.compile(self.Pattern.GetValue())
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   202
                except:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   203
                    wrong_pattern = True
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   204
            if wrong_pattern:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   205
                message = wx.MessageDialog(self, _("Syntax error in regular expression of pattern to search!"), _("Error"), wx.OK|wx.ICON_ERROR)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   206
                message.ShowModal()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   207
                message.Destroy()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   208
            else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents:
diff changeset
   209
                self.EndModal(wx.ID_OK)