def on_stoplist(self, event): '''open 'edit stoplist' dialogue''' dialog = StoplistDlg(self.wordlist.stoplist, self) response = dialog.ShowModal() if response == wx.ID_OK: self.wordlist = Wordlist(self.wordlist.text, dialog.stoplist) self.table.update(self.wordlist) dialog.Destroy()
def load_wordlist(self, filename): '''load wordlist from file''' filename = os.path.abspath(filename) self.SetStatusText('Reading data from file...') try: with open(filename, 'r') as inputfile: text = unicode(inputfile.read(), 'utf-8') except Exception as error: wx.MessageBox(str(error), '', wx.OK | wx.ICON_ERROR) self.SetStatusText('Could not read data.') else: self.wordlist = Wordlist(text) self.SetStatusText('Data read.') self.SetTitle(os.path.basename(filename)) self.dirname = os.path.dirname(filename) self.filename = os.path.basename(filename) self.enable_controls()
def __init__(self, filename, stoplists=None, freqsort=False, endsort=False): '''command line interface constructor''' self.stoplists = list() if stoplists: for stopfile in stoplists: with open(stopfile, 'r') as inputfile: stoplist = unicode(inputfile.read(), 'utf-8') stoplist = RE_WORD.findall(stoplist.lower()) self.stoplists.extend(stoplist) with open(filename, 'r') as inputfile: self.wordlist = Wordlist(unicode(inputfile.read(), 'utf-8'), self.stoplists) self.endsort = endsort self.freqsort = freqsort