dialogs/SearchInProjectDialog.py
changeset 1784 64beb9e9c749
parent 1782 5b6ad7a7fd9d
child 1847 6198190bc121
equal deleted inserted replaced
1729:31e63e25b4cc 1784:64beb9e9c749
    22 # You should have received a copy of the GNU General Public License
    22 # You should have received a copy of the GNU General Public License
    23 # along with this program; if not, write to the Free Software
    23 # along with this program; if not, write to the Free Software
    24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    25 
    25 
    26 import re
    26 import re
       
    27 import wx
    27 from plcopen.plcopen import *
    28 from plcopen.plcopen import *
    28 import wx
    29 from util.TranslationCatalogs import NoTranslate
    29 
    30 
    30 #-------------------------------------------------------------------------------
    31 # -------------------------------------------------------------------------------
    31 #                          Search In Project Dialog
    32 #                          Search In Project Dialog
    32 #-------------------------------------------------------------------------------
    33 # -------------------------------------------------------------------------------
       
    34 
    33 
    35 
    34 def GetElementsChoices():
    36 def GetElementsChoices():
    35     _ = lambda x: x
    37     _ = NoTranslate
    36     return [("datatype", _("Data Type")), 
    38     return [("datatype", _("Data Type")),
    37             ("function", _("Function")), 
    39             ("function", _("Function")),
    38             ("functionBlock", _("Function Block")), 
    40             ("functionBlock", _("Function Block")),
    39             ("program", _("Program")), 
    41             ("program", _("Program")),
    40             ("configuration", _("Configuration"))]
    42             ("configuration", _("Configuration"))]
    41 
    43 
       
    44 
    42 class SearchInProjectDialog(wx.Dialog):
    45 class SearchInProjectDialog(wx.Dialog):
    43     
    46 
    44     def __init__(self, parent):
    47     def __init__(self, parent):
    45         wx.Dialog.__init__(self, parent, title=_('Search in Project'))
    48         wx.Dialog.__init__(self, parent, title=_('Search in Project'))
    46         
    49 
    47         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
    50         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
    48         main_sizer.AddGrowableCol(0)
    51         main_sizer.AddGrowableCol(0)
    49         main_sizer.AddGrowableRow(1)
    52         main_sizer.AddGrowableRow(1)
    50         
    53 
    51         pattern_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=5)
    54         pattern_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=5)
    52         pattern_sizer.AddGrowableCol(0)
    55         pattern_sizer.AddGrowableCol(0)
    53         main_sizer.AddSizer(pattern_sizer, border=20, 
    56         main_sizer.AddSizer(pattern_sizer, border=20,
    54               flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
    57                             flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT)
    55         
    58 
    56         pattern_label = wx.StaticText(self, label=_('Pattern to search:'))
    59         pattern_label = wx.StaticText(self, label=_('Pattern to search:'))
    57         pattern_sizer.AddWindow(pattern_label, flag=wx.ALIGN_BOTTOM)
    60         pattern_sizer.AddWindow(pattern_label, flag=wx.ALIGN_BOTTOM)
    58         
    61 
    59         self.CaseSensitive = wx.CheckBox(self, label=_('Case sensitive'))
    62         self.CaseSensitive = wx.CheckBox(self, label=_('Case sensitive'))
    60         pattern_sizer.AddWindow(self.CaseSensitive, flag=wx.GROW)
    63         pattern_sizer.AddWindow(self.CaseSensitive, flag=wx.GROW)
    61         
    64 
    62         self.Pattern = wx.TextCtrl(self, size=wx.Size(250,-1))
    65         self.Pattern = wx.TextCtrl(self, size=wx.Size(250, -1))
    63         self.Bind(wx.EVT_TEXT, self.FindPatternChanged, self.Pattern)
    66         self.Bind(wx.EVT_TEXT, self.FindPatternChanged, self.Pattern)
    64         pattern_sizer.AddWindow(self.Pattern, flag=wx.GROW)
    67         pattern_sizer.AddWindow(self.Pattern, flag=wx.GROW)
    65         self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey)
    68         self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey)
    66         self.RegularExpression = wx.CheckBox(self, label=_('Regular expression'))
    69         self.RegularExpression = wx.CheckBox(self, label=_('Regular expression'))
    67         pattern_sizer.AddWindow(self.RegularExpression, flag=wx.GROW)
    70         pattern_sizer.AddWindow(self.RegularExpression, flag=wx.GROW)
    68         
    71 
    69         scope_staticbox = wx.StaticBox(self, label=_('Scope'))
    72         scope_staticbox = wx.StaticBox(self, label=_('Scope'))
    70         scope_sizer = wx.StaticBoxSizer(scope_staticbox, wx.HORIZONTAL)
    73         scope_sizer = wx.StaticBoxSizer(scope_staticbox, wx.HORIZONTAL)
    71         main_sizer.AddSizer(scope_sizer, border=20, 
    74         main_sizer.AddSizer(scope_sizer, border=20,
    72               flag=wx.GROW|wx.LEFT|wx.RIGHT)
    75                             flag=wx.GROW | wx.LEFT | wx.RIGHT)
    73         
    76 
    74         scope_selection_sizer = wx.BoxSizer(wx.VERTICAL)
    77         scope_selection_sizer = wx.BoxSizer(wx.VERTICAL)
    75         scope_sizer.AddSizer(scope_selection_sizer, 1, border=5, 
    78         scope_sizer.AddSizer(scope_selection_sizer, 1, border=5,
    76               flag=wx.GROW|wx.TOP|wx.LEFT|wx.BOTTOM)
    79                              flag=wx.GROW | wx.TOP | wx.LEFT | wx.BOTTOM)
    77         
    80 
    78         self.WholeProject = wx.RadioButton(self, label=_('Whole Project'), style=wx.RB_GROUP)
    81         self.WholeProject = wx.RadioButton(self, label=_('Whole Project'), style=wx.RB_GROUP)
    79         self.WholeProject.SetValue(True)
    82         self.WholeProject.SetValue(True)
    80         self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, self.WholeProject)
    83         self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, self.WholeProject)
    81         scope_selection_sizer.AddWindow(self.WholeProject, border=5, 
    84         scope_selection_sizer.AddWindow(self.WholeProject, border=5,
    82               flag=wx.GROW|wx.BOTTOM)
    85                                         flag=wx.GROW | wx.BOTTOM)
    83         
    86 
    84         self.OnlyElements = wx.RadioButton(self, label=_('Only Elements'))
    87         self.OnlyElements = wx.RadioButton(self, label=_('Only Elements'))
    85         self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, self.OnlyElements)
    88         self.Bind(wx.EVT_RADIOBUTTON, self.OnScopeChanged, self.OnlyElements)
    86         self.OnlyElements.SetValue(False)
    89         self.OnlyElements.SetValue(False)
    87         scope_selection_sizer.AddWindow(self.OnlyElements, flag=wx.GROW)
    90         scope_selection_sizer.AddWindow(self.OnlyElements, flag=wx.GROW)
    88         
    91 
    89         self.ElementsList = wx.CheckListBox(self)
    92         self.ElementsList = wx.CheckListBox(self)
    90         self.ElementsList.Enable(False)
    93         self.ElementsList.Enable(False)
    91         scope_sizer.AddWindow(self.ElementsList, 1, border=5, 
    94         scope_sizer.AddWindow(self.ElementsList, 1, border=5,
    92               flag=wx.GROW|wx.TOP|wx.RIGHT|wx.BOTTOM)
    95                               flag=wx.GROW | wx.TOP | wx.RIGHT | wx.BOTTOM)
    93 
    96 
    94         buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
    97         buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
    95         main_sizer.AddSizer(buttons_sizer, border=20,
    98         main_sizer.AddSizer(buttons_sizer, border=20,
    96                             flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_RIGHT)
    99                             flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_RIGHT)
    97 
   100 
   101         buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT)
   104         buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT)
   102 
   105 
   103         self.CloseButton = wx.Button(self, label=_("Close"))
   106         self.CloseButton = wx.Button(self, label=_("Close"))
   104         self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton)
   107         self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton)
   105         buttons_sizer.AddWindow(self.CloseButton)
   108         buttons_sizer.AddWindow(self.CloseButton)
   106         
   109 
   107         self.SetSizer(main_sizer)
   110         self.SetSizer(main_sizer)
   108         
   111 
   109         for name, label in GetElementsChoices():
   112         for name, label in GetElementsChoices():
   110             self.ElementsList.Append(_(label))
   113             self.ElementsList.Append(_(label))
   111 
   114 
   112         self.Fit()
   115         self.Fit()
   113         self.infosPrev = {}
   116         self.infosPrev = {}
   137         keycode = event.GetKeyCode()
   140         keycode = event.GetKeyCode()
   138         if keycode == wx.WXK_ESCAPE:
   141         if keycode == wx.WXK_ESCAPE:
   139             self.OnCloseButton(event)
   142             self.OnCloseButton(event)
   140         else:
   143         else:
   141             event.Skip()
   144             event.Skip()
   142     
   145 
   143     def OnFindButton(self, event):
   146     def OnFindButton(self, event):
   144         message = None
   147         message = None
   145         infos = {
   148         infos = {
   146             "find_pattern": self.Pattern.GetValue(),
   149             "find_pattern": self.Pattern.GetValue(),
   147             "case_sensitive": self.CaseSensitive.GetValue(),
   150             "case_sensitive": self.CaseSensitive.GetValue(),
   158         if self.infosPrev != infos:
   161         if self.infosPrev != infos:
   159             try:
   162             try:
   160                 self.criteria = infos
   163                 self.criteria = infos
   161                 CompilePattern(self.criteria)
   164                 CompilePattern(self.criteria)
   162                 self.infosPrev = infos
   165                 self.infosPrev = infos
   163             except:
   166             except Exception:
   164                 self.criteria.clear()
   167                 self.criteria.clear()
   165                 message = _("Syntax error in regular expression of pattern to search!")
   168                 message = _("Syntax error in regular expression of pattern to search!")
   166         
   169 
   167         if message is not None:
   170         if message is not None:
   168             dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
   171             dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR)
   169             dialog.ShowModal()
   172             dialog.ShowModal()
   170             dialog.Destroy()
   173             dialog.Destroy()
   171         else:
   174         else:
   172             self.EndModal(wx.ID_OK)
   175             self.EndModal(wx.ID_OK)