dialogs/SearchInProjectDialog.py
author Sergey Surkov <surkovsv93@gmail.com>
Fri, 28 Oct 2016 18:11:43 +0300
changeset 1556 32e9d0ef30dc
parent 814 5743cbdff669
child 1558 d75cc9ad328e
permissions -rw-r--r--
fix major bugs in Find and Search in Project functionality.

fix case sensitive and regexp search, remove duplicating code

Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
import re
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
    26
from plcopen.plcopen import *
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
#                          Search In Project Dialog
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
def GetElementsChoices():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
    _ = lambda x: x
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
    return [("datatype", _("Data Type")), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
            ("function", _("Function")), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
            ("functionBlock", _("Function Block")), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
            ("program", _("Program")), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
            ("configuration", _("Configuration"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
class SearchInProjectDialog(wx.Dialog):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
    def __init__(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
        wx.Dialog.__init__(self, parent, title=_('Search in Project'), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
              size=wx.Size(600, 350))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
        main_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
        main_sizer.AddGrowableRow(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
        pattern_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
        pattern_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
        main_sizer.AddSizer(pattern_sizer, border=20, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
        pattern_label = wx.StaticText(self, label=_('Pattern to search:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
        pattern_sizer.AddWindow(pattern_label, flag=wx.ALIGN_BOTTOM)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
        self.CaseSensitive = wx.CheckBox(self, label=_('Case sensitive'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
        pattern_sizer.AddWindow(self.CaseSensitive, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
        self.Pattern = wx.TextCtrl(self)
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
    63
        self.Bind(wx.EVT_TEXT, self.FindPatternChanged, self.Pattern)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
        pattern_sizer.AddWindow(self.Pattern, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
        self.RegularExpression = wx.CheckBox(self, label=_('Regular expression'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
        pattern_sizer.AddWindow(self.RegularExpression, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
        scope_staticbox = wx.StaticBox(self, label=_('Scope'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
        scope_sizer = wx.StaticBoxSizer(scope_staticbox, wx.HORIZONTAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
        main_sizer.AddSizer(scope_sizer, border=20, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
              flag=wx.GROW|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
        scope_selection_sizer = wx.BoxSizer(wx.VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
        scope_sizer.AddSizer(scope_selection_sizer, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.BOTTOM)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
        self.WholeProject = wx.RadioButton(self, label=_('Whole Project'), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
              size=wx.Size(0, 24), style=wx.RB_GROUP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
        self.WholeProject.SetValue(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, self.WholeProject)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
        scope_selection_sizer.AddWindow(self.WholeProject, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
              flag=wx.GROW|wx.BOTTOM)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
        self.OnlyElements = wx.RadioButton(self, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
              label=_('Only Elements'), size=wx.Size(0, 24))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, self.OnlyElements)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
        self.OnlyElements.SetValue(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        scope_selection_sizer.AddWindow(self.OnlyElements, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
        self.ElementsList = wx.CheckListBox(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        self.ElementsList.Enable(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        scope_sizer.AddWindow(self.ElementsList, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
              flag=wx.GROW|wx.TOP|wx.RIGHT|wx.BOTTOM)
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
    95
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
    96
        buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
    97
        main_sizer.AddSizer(buttons_sizer, border=20,
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
    98
                            flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_RIGHT)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
    99
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   100
        self.FindButton = wx.Button(self, label=_("Find"))
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   101
        self.FindButton.SetDefault()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   102
        self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   103
        buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   104
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   105
        self.CloseButton = wx.Button(self, label=_("Close"))
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   106
        self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   107
        buttons_sizer.AddWindow(self.CloseButton)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
        self.SetSizer(main_sizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
        for name, label in GetElementsChoices():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
            self.ElementsList.Append(_(label))
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   113
        self.infosPrev = {}
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   114
        self.criteria = {}
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
        self.Pattern.SetFocus()
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   116
        self.RefreshButtonsState()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   117
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   118
    def RefreshButtonsState(self):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   119
        find_pattern = self.Pattern.GetValue()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   120
        self.FindButton.Enable(find_pattern != "")
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
    def GetCriteria(self):
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   123
        return self.criteria
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   124
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   125
    def FindPatternChanged(self, event):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   126
        self.RefreshButtonsState()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   127
        event.Skip()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   128
    def OnScopeChanged(self, event):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   129
        self.ElementsList.Enable(self.OnlyElements.GetValue())
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   130
        event.Skip()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   131
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   132
    def OnCloseButton(self, event):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   133
        self.EndModal(wx.ID_CANCEL)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   134
    
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   135
    def OnFindButton(self, event):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   136
        message = None
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   137
        infos = {
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   138
            "find_pattern": self.Pattern.GetValue(),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   139
            "case_sensitive": self.CaseSensitive.GetValue(),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
            "regular_expression": self.RegularExpression.GetValue(),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
        }
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
        if self.WholeProject.GetValue():
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   143
            infos["filter"] = "all"
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
        elif self.OnlyElements.GetValue():
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   145
            infos["filter"] = []
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
            for index, (name, label) in enumerate(GetElementsChoices()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
                if self.ElementsList.IsChecked(index):
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   148
                    infos["filter"].append(name)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   149
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   150
        if self.infosPrev != infos:
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   151
            try:
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   152
                self.criteria = infos
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   153
                CompilePattern(self.criteria)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   154
                self.infosPrev = infos
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   155
            except:
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   156
                self.criteria.clear()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
                message = _("Syntax error in regular expression of pattern to search!")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
        if message is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
            dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
            dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
            self.EndModal(wx.ID_OK)