def __init__(self, parent, filename="", details=None): title = "Go To Line" if filename: title += " [%s]" % filename wx.Dialog.__init__(self, parent, title=title) self.text = wx.TextCtrl(self, size=(100, -1)) self.text.SetFocus() flags = wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTRE_VERTICAL sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.text, 0, flags | wx.LEFT, 5) btn_ok = wx.Button(self, wx.ID_OK) btn_ok.SetDefault() sizer.Add(btn_ok, 0, flags, 5) self.SetSizer(sizer) self.Fit() # Position in bottom-right corner pos = parent.Parent.ClientToScreen(parent.Position) self.SetPosition(( pos.x + (parent.Size.width - self.Size.width) - 20, pos.y + (parent.Size.height - self.Size.height) - 20)) self.Bind(wx.EVT_BUTTON, self.OnOK, id=wx.ID_OK) self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateOK, id=wx.ID_OK) self.text.Bind(wx.EVT_CHAR, self.OnTextChar) bind_escape_key(self)
def __init__(self, editor, filename="", details=None): title = "Find and Replace" if filename: title += " [%s]" % filename wx.Dialog.__init__(self, editor, title=title, style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) self.editor = editor combo_style = wx.TE_PROCESS_ENTER if wx.Platform == "__WXMAC__" else 0 self.combo_find = wx.ComboBox(self, size=(300, -1), style=combo_style) self.combo_replace = wx.ComboBox(self, size=(300, -1), style=combo_style) grid = wx.FlexGridSizer(cols=2, vgap=5, hgap=5) grid.AddGrowableCol(1, 1) grid.Add(wx.StaticText(self, label="Find"), 0, wx.ALIGN_CENTRE_VERTICAL) grid.Add(self.combo_find, 0, wx.EXPAND) grid.Add(wx.StaticText(self, label="Replace"), 0, wx.ALIGN_CENTRE_VERTICAL) grid.Add(self.combo_replace, 0, wx.EXPAND) grid.AddSpacer(0) self.check_case = wx.CheckBox(self, wx.ID_ANY, "&Case sensitive") self.check_regexp = wx.CheckBox(self, wx.ID_ANY, "Regular e&xpression") self.check_reverse = wx.CheckBox(self, wx.ID_ANY, "Re&verse") chksizer = wx.BoxSizer(wx.VERTICAL) chksizer.Add(self.check_case, 0, wx.ALL, 2) chksizer.Add(self.check_regexp, 0, wx.ALL, 2) chksizer.Add(self.check_reverse, 0, wx.ALL, 2) grid.Add(chksizer) spacer = 10 if wx.Platform == "__WXMAC__" else 5 btnsizer = wx.BoxSizer(wx.HORIZONTAL) btn_goto_start = wx.Button(self, label="&Go to Start") btnsizer.Add(btn_goto_start) btnsizer.AddSpacer(spacer) btnsizer.AddStretchSpacer() btn_find = wx.Button(self, wx.ID_FIND, "&Find") btn_find.SetDefault() btnsizer.Add(btn_find) btnsizer.AddSpacer(spacer) btnsizer.Add(wx.Button(self, wx.ID_REPLACE, "&Replace")) btnsizer.AddSpacer(spacer) btnsizer.Add(wx.Button(self, wx.ID_REPLACE_ALL, "Replace &All")) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(grid, 0, wx.EXPAND | wx.ALL, 5) sizer.Add(btnsizer, 0, wx.EXPAND | wx.ALL, spacer) self.SetSizer(sizer) self.Fit() self.SetMinSize(self.Size) self.SetMaxSize((-1, self.Size.height)) # Position in bottom-right corner pos = editor.Parent.ClientToScreen(editor.Position) self.SetPosition(( pos.x + (editor.Size.width - self.Size.width) - 20, pos.y + (editor.Size.height - self.Size.height) - 20)) if details is not None: self.combo_find.SetItems(details.find_history) self.combo_find.SetValue(details.find) self.combo_replace.SetItems(details.replace_history) self.combo_replace.SetValue(details.replace) self.check_case.SetValue(details.case) self.check_regexp.SetValue(details.regexp) self.check_reverse.SetValue(details.reverse) self.combo_find.SetFocus() self.combo_find.SetMark(0, len(self.combo_find.GetValue())) self.combo_find.Bind(wx.EVT_KEY_DOWN, self.OnComboKeyDown) self.combo_replace.Bind(wx.EVT_KEY_DOWN, self.OnComboKeyDown) self.Bind(wx.EVT_TEXT_ENTER, self.OnFind) self.Bind(wx.EVT_BUTTON, self.OnGoToStart, btn_goto_start) self.Bind(wx.EVT_BUTTON, self.OnFind, id=wx.ID_FIND) self.Bind(wx.EVT_BUTTON, self.OnReplace, id=wx.ID_REPLACE) self.Bind(wx.EVT_BUTTON, self.OnReplaceAll, id=wx.ID_REPLACE_ALL) self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateFind, id=wx.ID_FIND) self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateFind, id=wx.ID_REPLACE) self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateFind, id=wx.ID_REPLACE_ALL) bind_escape_key(self)