def OnRemoveTrailingWhiteSpaces (self): eol = self.txtDocument.GetEndOfLineCharacter() lines = self.txtDocument.GetText().split(eol) new_lines = [] nr_lines = 0 nr_clines = 0 regex = re.compile('\s+' + eol, re.MULTILINE) for line in lines: nr_lines += 1 result = regex.search(line + eol) if result != None: end = result.start() nr_clines += 1 new_lines.append (line [:end]) else: new_lines.append(line) #file has trailing whitespaces if nr_clines > 0: d = wx.MessageDialog(self, "File %s has trailing Whitespaces\nCorrect?" % self.txtDocument.filename, "Remove trailing Whitespace", wx.OK | wx.CANCEL | wx.ICON_QUESTION) answer = d.ShowModal() d.Destroy() if (answer == wx.ID_OK): newtext = string.join(new_lines, eol) #save current line curline = self.txtDocument.GetCurrentLine() self.txtDocument.SetText(newtext) #jump to saved current line self.txtDocument.GotoLine(curline) return nr_clines > 0