dialogs/FindInPouDialog.py
changeset 1730 64d8f52bc8c8
parent 1696 8043f32de7b8
child 1736 7e61baa047f0
equal deleted inserted replaced
1726:d51af006fa6b 1730:64d8f52bc8c8
    30 
    30 
    31     def _init_icon(self, parent):
    31     def _init_icon(self, parent):
    32         if parent and parent.icon:
    32         if parent and parent.icon:
    33                 self.SetIcon(parent.icon)
    33                 self.SetIcon(parent.icon)
    34 
    34 
    35     
    35 
    36     def __init__(self, parent):
    36     def __init__(self, parent):
    37         wx.Dialog.__init__(self, parent, title=_("Find"),         
    37         wx.Dialog.__init__(self, parent, title=_("Find"),
    38               style=wx.CAPTION|wx.CLOSE_BOX|wx.CLIP_CHILDREN|wx.RESIZE_BORDER)
    38               style=wx.CAPTION|wx.CLOSE_BOX|wx.CLIP_CHILDREN|wx.RESIZE_BORDER)
    39         
    39 
    40         self._init_icon(parent)
    40         self._init_icon(parent)
    41         panel = wx.Panel(self, style=wx.TAB_TRAVERSAL)
    41         panel = wx.Panel(self, style=wx.TAB_TRAVERSAL)
    42         
    42 
    43         main_sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5)
    43         main_sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5)
    44         main_sizer.AddGrowableCol(0)
    44         main_sizer.AddGrowableCol(0)
    45         main_sizer.AddGrowableRow(0)
    45         main_sizer.AddGrowableRow(0)
    46         
    46 
    47         controls_sizer = wx.BoxSizer(wx.VERTICAL)
    47         controls_sizer = wx.BoxSizer(wx.VERTICAL)
    48         main_sizer.AddSizer(controls_sizer, border=20, 
    48         main_sizer.AddSizer(controls_sizer, border=20,
    49               flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
    49               flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
    50         
    50 
    51         patterns_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5)
    51         patterns_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5)
    52         patterns_sizer.AddGrowableCol(1)
    52         patterns_sizer.AddGrowableCol(1)
    53         controls_sizer.AddSizer(patterns_sizer, border=5, flag=wx.GROW|wx.BOTTOM)
    53         controls_sizer.AddSizer(patterns_sizer, border=5, flag=wx.GROW|wx.BOTTOM)
    54         
    54 
    55         find_label = wx.StaticText(panel, label=_("Find:"))
    55         find_label = wx.StaticText(panel, label=_("Find:"))
    56         patterns_sizer.AddWindow(find_label, flag=wx.ALIGN_CENTER_VERTICAL)
    56         patterns_sizer.AddWindow(find_label, flag=wx.ALIGN_CENTER_VERTICAL)
    57         
    57 
    58         self.FindPattern = wx.TextCtrl(panel)
    58         self.FindPattern = wx.TextCtrl(panel)
    59         self.Bind(wx.EVT_TEXT, self.OnFindPatternChanged, self.FindPattern)
    59         self.Bind(wx.EVT_TEXT, self.OnFindPatternChanged, self.FindPattern)
    60         self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey)
    60         self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey)
    61         patterns_sizer.AddWindow(self.FindPattern, flag=wx.GROW)
    61         patterns_sizer.AddWindow(self.FindPattern, flag=wx.GROW)
    62         
    62 
    63         params_sizer = wx.BoxSizer(wx.HORIZONTAL)
    63         params_sizer = wx.BoxSizer(wx.HORIZONTAL)
    64         controls_sizer.AddSizer(params_sizer, border=5, flag=wx.GROW|wx.BOTTOM)
    64         controls_sizer.AddSizer(params_sizer, border=5, flag=wx.GROW|wx.BOTTOM)
    65         
    65 
    66         direction_staticbox = wx.StaticBox(panel, label=_("Direction"))
    66         direction_staticbox = wx.StaticBox(panel, label=_("Direction"))
    67         direction_staticboxsizer = wx.StaticBoxSizer(
    67         direction_staticboxsizer = wx.StaticBoxSizer(
    68               direction_staticbox, wx.VERTICAL)
    68               direction_staticbox, wx.VERTICAL)
    69         params_sizer.AddSizer(direction_staticboxsizer, 1, border=5, 
    69         params_sizer.AddSizer(direction_staticboxsizer, 1, border=5,
    70               flag=wx.GROW|wx.RIGHT)
    70               flag=wx.GROW|wx.RIGHT)
    71         
    71 
    72         self.Forward = wx.RadioButton(panel, label=_("Forward"), 
    72         self.Forward = wx.RadioButton(panel, label=_("Forward"),
    73               style=wx.RB_GROUP)
    73               style=wx.RB_GROUP)
    74         direction_staticboxsizer.AddWindow(self.Forward, border=5, 
    74         direction_staticboxsizer.AddWindow(self.Forward, border=5,
    75               flag=wx.ALL|wx.GROW)
    75               flag=wx.ALL|wx.GROW)
    76         
    76 
    77         self.Backward = wx.RadioButton(panel, label=_("Backward"))
    77         self.Backward = wx.RadioButton(panel, label=_("Backward"))
    78         direction_staticboxsizer.AddWindow(self.Backward, border=5, 
    78         direction_staticboxsizer.AddWindow(self.Backward, border=5,
    79               flag=wx.ALL|wx.GROW)
    79               flag=wx.ALL|wx.GROW)
    80         
    80 
    81         options_staticbox = wx.StaticBox(panel, label=_("Options"))
    81         options_staticbox = wx.StaticBox(panel, label=_("Options"))
    82         options_staticboxsizer = wx.StaticBoxSizer(
    82         options_staticboxsizer = wx.StaticBoxSizer(
    83               options_staticbox, wx.VERTICAL)
    83               options_staticbox, wx.VERTICAL)
    84         params_sizer.AddSizer(options_staticboxsizer, 1, flag=wx.GROW)
    84         params_sizer.AddSizer(options_staticboxsizer, 1, flag=wx.GROW)
    85         
    85 
    86         self.CaseSensitive = wx.CheckBox(panel, label=_("Case sensitive"))
    86         self.CaseSensitive = wx.CheckBox(panel, label=_("Case sensitive"))
    87         self.CaseSensitive.SetValue(True)
    87         self.CaseSensitive.SetValue(True)
    88         options_staticboxsizer.AddWindow(self.CaseSensitive, border=5, 
    88         options_staticboxsizer.AddWindow(self.CaseSensitive, border=5,
    89               flag=wx.ALL|wx.GROW)
    89               flag=wx.ALL|wx.GROW)
    90         
    90 
    91         self.WrapSearch = wx.CheckBox(panel, label=_("Wrap search"))
    91         self.WrapSearch = wx.CheckBox(panel, label=_("Wrap search"))
    92         self.WrapSearch.SetValue(True)
    92         self.WrapSearch.SetValue(True)
    93         options_staticboxsizer.AddWindow(self.WrapSearch, border=5, 
    93         options_staticboxsizer.AddWindow(self.WrapSearch, border=5,
    94               flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
    94               flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
    95         
    95 
    96         self.RegularExpressions = wx.CheckBox(panel, label=_("Regular expressions"))
    96         self.RegularExpressions = wx.CheckBox(panel, label=_("Regular expressions"))
    97         options_staticboxsizer.AddWindow(self.RegularExpressions, border=5, 
    97         options_staticboxsizer.AddWindow(self.RegularExpressions, border=5,
    98               flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
    98               flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
    99         
    99 
   100         buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
   100         buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
   101         main_sizer.AddSizer(buttons_sizer, border=20, 
   101         main_sizer.AddSizer(buttons_sizer, border=20,
   102               flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT)
   102               flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT)
   103         
   103 
   104         self.FindButton = wx.Button(panel, label=_("Find"))
   104         self.FindButton = wx.Button(panel, label=_("Find"))
   105         self.FindButton.SetDefault()
   105         self.FindButton.SetDefault()
   106         self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton)
   106         self.Bind(wx.EVT_BUTTON, self.OnFindButton, self.FindButton)
   107         buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT)
   107         buttons_sizer.AddWindow(self.FindButton, border=5, flag=wx.RIGHT)
   108         
   108 
   109         self.CloseButton = wx.Button(panel, label=_("Close"))
   109         self.CloseButton = wx.Button(panel, label=_("Close"))
   110         self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton)
   110         self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.CloseButton)
   111         buttons_sizer.AddWindow(self.CloseButton)
   111         buttons_sizer.AddWindow(self.CloseButton)
   112 
   112 
   113         # set the longest message here, to use it length to calculate
   113         # set the longest message here, to use it length to calculate
   114         # optimal size of dialog window
   114         # optimal size of dialog window
   115         self.RegExpSyntaxErrMsg = _("Syntax error in regular expression of pattern to search!")
   115         self.RegExpSyntaxErrMsg = _("Syntax error in regular expression of pattern to search!")
   116         self.StatusLabel = wx.StaticText(panel, label= self.RegExpSyntaxErrMsg)
   116         self.StatusLabel = wx.StaticText(panel, label= self.RegExpSyntaxErrMsg)
   117         controls_sizer.AddWindow(self.StatusLabel, flag=wx.ALIGN_CENTER_VERTICAL)
   117         controls_sizer.AddWindow(self.StatusLabel, flag=wx.ALIGN_CENTER_VERTICAL)
   118         
   118 
   119         panel.SetSizer(main_sizer)
   119         panel.SetSizer(main_sizer)
   120         main_sizer.Fit(self)
   120         main_sizer.Fit(self)
   121 
   121 
   122         # clear message after dialog size calculation
   122         # clear message after dialog size calculation
   123         self.SetStatusText("")
   123         self.SetStatusText("")
   124 
   124 
   125         
   125 
   126         self.ParentWindow = parent
   126         self.ParentWindow = parent
   127         
   127 
   128         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
   128         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
   129         self.infosPrev = {}
   129         self.infosPrev = {}
   130         self.criteria = {}
   130         self.criteria = {}
   131         self.FindPattern.SetFocus()
   131         self.FindPattern.SetFocus()
   132         self.RefreshButtonsState()
   132         self.RefreshButtonsState()
   133     
   133 
   134     def RefreshButtonsState(self):
   134     def RefreshButtonsState(self):
   135         find_pattern = self.FindPattern.GetValue()
   135         find_pattern = self.FindPattern.GetValue()
   136         self.FindButton.Enable(find_pattern != "")
   136         self.FindButton.Enable(find_pattern != "")
   137     
   137 
   138     def OnCloseFrame(self, event):
   138     def OnCloseFrame(self, event):
   139         self.Hide()
   139         self.Hide()
   140         event.Veto()
   140         event.Veto()
   141         
   141 
   142     def OnCloseButton(self, event):
   142     def OnCloseButton(self, event):
   143         self.Hide()
   143         self.Hide()
   144         event.Skip()
   144         event.Skip()
   145 
   145 
   146     def OnEscapeKey(self, event):
   146     def OnEscapeKey(self, event):
   155         event.Skip()
   155         event.Skip()
   156 
   156 
   157     def SetStatusText(self, msg):
   157     def SetStatusText(self, msg):
   158         self.StatusLabel.SetLabel(msg)
   158         self.StatusLabel.SetLabel(msg)
   159         self.Layout()
   159         self.Layout()
   160         
   160 
   161     def OnFindButton(self, event):
   161     def OnFindButton(self, event):
   162         infos = {
   162         infos = {
   163             "find_pattern": self.FindPattern.GetValue(),
   163             "find_pattern": self.FindPattern.GetValue(),
   164             "wrap": self.WrapSearch.GetValue(),
   164             "wrap": self.WrapSearch.GetValue(),
   165             "case_sensitive": self.CaseSensitive.GetValue(),
   165             "case_sensitive": self.CaseSensitive.GetValue(),