dialogs/SearchInProjectDialog.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 19 Jun 2017 18:49:43 +0300
changeset 1696 8043f32de7b8
parent 1571 486f94a8032c
child 1730 64d8f52bc8c8
permissions -rw-r--r--
make all dialog have non-fixed size

this fixes the problem, that some controls may be hidden in some cases, because
dialog size is too small. This can happen when system fonts are bigger
than expected, default system them controls are bigger or if localized
strings are bigger than in English.
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
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
     8
# Copyright (C) 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com>
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
    10
# See COPYING file for copyrights details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
    12
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
    13
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
    14
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
    15
# of the License, or (at your option) any later version.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
    17
# This program is distributed in the hope that it will be useful,
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
    18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
    19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
    20
# GNU General Public License for more details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
    22
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
    23
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1558
diff changeset
    24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
import re
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
    27
from plcopen.plcopen import *
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
#                          Search In Project Dialog
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
def GetElementsChoices():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
    _ = lambda x: x
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
    return [("datatype", _("Data Type")), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
            ("function", _("Function")), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
            ("functionBlock", _("Function Block")), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
            ("program", _("Program")), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
            ("configuration", _("Configuration"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
class SearchInProjectDialog(wx.Dialog):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
    def __init__(self, parent):
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    45
        wx.Dialog.__init__(self, parent, title=_('Search in Project'))
814
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
        
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    62
        self.Pattern = wx.TextCtrl(self, size=wx.Size(250,-1))
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)
1558
d75cc9ad328e now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents: 1556
diff changeset
    65
        self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey)
814
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
        
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    78
        self.WholeProject = wx.RadioButton(self, label=_('Whole Project'), style=wx.RB_GROUP)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
        self.WholeProject.SetValue(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
        self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, self.WholeProject)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        scope_selection_sizer.AddWindow(self.WholeProject, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
              flag=wx.GROW|wx.BOTTOM)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
        
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    84
        self.OnlyElements = wx.RadioButton(self, label=_('Only Elements'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
        self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, self.OnlyElements)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
        self.OnlyElements.SetValue(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        scope_selection_sizer.AddWindow(self.OnlyElements, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        self.ElementsList = wx.CheckListBox(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
        self.ElementsList.Enable(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
        scope_sizer.AddWindow(self.ElementsList, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
              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
    93
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
    94
        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
    95
        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
    96
                            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
    97
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
    98
        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
    99
        self.FindButton.SetDefault()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   100
        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
   101
        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
   102
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   103
        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
   104
        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
   105
        buttons_sizer.AddWindow(self.CloseButton)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
        self.SetSizer(main_sizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
        for name, label in GetElementsChoices():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
            self.ElementsList.Append(_(label))
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   111
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   112
        self.Fit()
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()
1558
d75cc9ad328e now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents: 1556
diff changeset
   128
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   129
    def OnScopeChanged(self, event):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   130
        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
   131
        event.Skip()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   132
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   133
    def OnCloseButton(self, event):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   134
        self.EndModal(wx.ID_CANCEL)
1558
d75cc9ad328e now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents: 1556
diff changeset
   135
d75cc9ad328e now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents: 1556
diff changeset
   136
    def OnEscapeKey(self, event):
d75cc9ad328e now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents: 1556
diff changeset
   137
        keycode = event.GetKeyCode()
d75cc9ad328e now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents: 1556
diff changeset
   138
        if keycode == wx.WXK_ESCAPE:
d75cc9ad328e now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents: 1556
diff changeset
   139
            self.OnCloseButton(event)
d75cc9ad328e now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents: 1556
diff changeset
   140
        else:
d75cc9ad328e now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents: 1556
diff changeset
   141
            event.Skip()
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   142
    
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   143
    def OnFindButton(self, event):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   144
        message = None
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   145
        infos = {
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   146
            "find_pattern": self.Pattern.GetValue(),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
            "case_sensitive": self.CaseSensitive.GetValue(),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
            "regular_expression": self.RegularExpression.GetValue(),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
        }
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
        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
   151
            infos["filter"] = "all"
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
        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
   153
            infos["filter"] = []
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
            for index, (name, label) in enumerate(GetElementsChoices()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
                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
   156
                    infos["filter"].append(name)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   157
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   158
        if self.infosPrev != infos:
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   159
            try:
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   160
                self.criteria = infos
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   161
                CompilePattern(self.criteria)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   162
                self.infosPrev = infos
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   163
            except:
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   164
                self.criteria.clear()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
                message = _("Syntax error in regular expression of pattern to search!")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
        if message is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
            dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
            dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
            self.EndModal(wx.ID_OK)