dialogs/SearchInProjectDialog.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Wed, 17 May 2023 23:59:45 +0200
changeset 3806 b57a38ce3f34
parent 3750 f62625418bff
permissions -rw-r--r--
IDE: Fix py_ext build with python3.10
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
1881
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
    26
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3303
diff changeset
    27
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    28
import wx
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
    29
from plcopen.plcopen import *
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    30
from util.TranslationCatalogs import NoTranslate
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
    32
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
#                          Search In Project Dialog
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
    34
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    36
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
def GetElementsChoices():
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    38
    _ = NoTranslate
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    39
    return [("datatype", _("Data Type")),
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    40
            ("function", _("Function")),
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    41
            ("functionBlock", _("Function Block")),
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    42
            ("program", _("Program")),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
            ("configuration", _("Configuration"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    45
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
class SearchInProjectDialog(wx.Dialog):
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    47
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
    def __init__(self, parent):
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    49
        wx.Dialog.__init__(self, parent, title=_('Search in Project'))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    50
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
        main_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
        main_sizer.AddGrowableRow(1)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    54
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
        pattern_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
        pattern_sizer.AddGrowableCol(0)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
    57
        main_sizer.Add(pattern_sizer, border=20,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
    58
                            flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    59
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
        pattern_label = wx.StaticText(self, label=_('Pattern to search:'))
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
    61
        pattern_sizer.Add(pattern_label, flag=wx.ALIGN_BOTTOM)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    62
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
        self.CaseSensitive = wx.CheckBox(self, label=_('Case sensitive'))
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
    64
        pattern_sizer.Add(self.CaseSensitive, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    65
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
    66
        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
    67
        self.Bind(wx.EVT_TEXT, self.FindPatternChanged, self.Pattern)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
    68
        pattern_sizer.Add(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
    69
        self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
        self.RegularExpression = wx.CheckBox(self, label=_('Regular expression'))
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
    71
        pattern_sizer.Add(self.RegularExpression, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    72
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
        scope_staticbox = wx.StaticBox(self, label=_('Scope'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
        scope_sizer = wx.StaticBoxSizer(scope_staticbox, wx.HORIZONTAL)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
    75
        main_sizer.Add(scope_sizer, border=20,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
    76
                            flag=wx.GROW | wx.LEFT | wx.RIGHT)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    77
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
        scope_selection_sizer = wx.BoxSizer(wx.VERTICAL)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
    79
        scope_sizer.Add(scope_selection_sizer, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
    80
                             flag=wx.GROW | wx.TOP | wx.LEFT | wx.BOTTOM)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    81
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    82
        self.WholeProject = wx.RadioButton(self, label=_('Whole Project'), style=wx.RB_GROUP)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
        self.WholeProject.SetValue(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
        self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, self.WholeProject)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
    85
        scope_selection_sizer.Add(self.WholeProject, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
    86
                                        flag=wx.GROW | wx.BOTTOM)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    87
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    88
        self.OnlyElements = wx.RadioButton(self, label=_('Only Elements'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, self.OnlyElements)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
        self.OnlyElements.SetValue(False)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
    91
        scope_selection_sizer.Add(self.OnlyElements, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    92
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        self.ElementsList = wx.CheckListBox(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        self.ElementsList.Enable(False)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
    95
        scope_sizer.Add(self.ElementsList, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
    96
                              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
    97
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
    98
        buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
    99
        main_sizer.Add(buttons_sizer, border=20,
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   100
                            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
   101
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   102
        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
   103
        self.FindButton.SetDefault()
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.OnFindButton, self.FindButton)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
   105
        buttons_sizer.Add(self.FindButton, border=5, flag=wx.RIGHT)
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   106
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   107
        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
   108
        self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1881
diff changeset
   109
        buttons_sizer.Add(self.CloseButton)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   110
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
        self.SetSizer(main_sizer)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   112
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   113
        for _name, label in GetElementsChoices():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
            self.ElementsList.Append(_(label))
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   115
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   116
        self.Fit()
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   117
        self.infosPrev = {}
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   118
        self.criteria = {}
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
        self.Pattern.SetFocus()
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   120
        self.RefreshButtonsState()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   121
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   122
    def RefreshButtonsState(self):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   123
        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
   124
        self.FindButton.Enable(find_pattern != "")
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
    def GetCriteria(self):
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   127
        return self.criteria
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   128
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   129
    def FindPatternChanged(self, event):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   130
        self.RefreshButtonsState()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   131
        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
   132
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   133
    def OnScopeChanged(self, event):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   134
        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
   135
        event.Skip()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   136
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   137
    def OnCloseButton(self, event):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   138
        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
   139
d75cc9ad328e now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents: 1556
diff changeset
   140
    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
   141
        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
   142
        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
   143
            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
   144
        else:
d75cc9ad328e now dialogs Find and Search in Project can be closed with ESC button
Sergey Surkov <surkovsv93@gmail.com>
parents: 1556
diff changeset
   145
            event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   146
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   147
    def OnFindButton(self, event):
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   148
        message = None
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   149
        infos = {
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   150
            "find_pattern": self.Pattern.GetValue(),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
            "case_sensitive": self.CaseSensitive.GetValue(),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
            "regular_expression": self.RegularExpression.GetValue(),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        }
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
        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
   155
            infos["filter"] = "all"
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
        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
   157
            infos["filter"] = []
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   158
            for index, (name, _label) in enumerate(GetElementsChoices()):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
                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
   160
                    infos["filter"].append(name)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   161
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   162
        if self.infosPrev != infos:
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   163
            try:
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   164
                self.criteria = infos
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   165
                CompilePattern(self.criteria)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   166
                self.infosPrev = infos
1780
c52d1460cea8 clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   167
            except Exception:
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 814
diff changeset
   168
                self.criteria.clear()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
                message = _("Syntax error in regular expression of pattern to search!")
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   170
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
        if message is not None:
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   172
            dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
            dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
            self.EndModal(wx.ID_OK)