Ejemplo n.º 1
0
 def on_save(self, event):
     """Save button saves current stoplist to file"""
     dialog = wx.FileDialog(
         self, message="", defaultDir=self.parent.dirname, defaultFile="", wildcard="*", style=wx.SAVE
     )
     response = dialog.ShowModal()
     path = dialog.GetPath()
     dialog.Destroy()
     if response == wx.ID_OK:
         if os.path.isfile(path):
             msg = wx.MessageDialog(
                 self,
                 message="The file {0} already exists. Overwrite?".format(path),
                 style=wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION,
             )
             confirm = msg.ShowModal()
             msg.Destroy()
             if confirm != wx.ID_YES:
                 return
         content = RE_WORD.findall(self.textctrl.GetValue())
         content = ["{0}\r\n".format(s.encode("utf-8")) for s in content]
         try:
             with open(path, "w") as savfile:
                 savfile.writelines(content)
         except Exception as error:
             wx.MessageBox(str(error), "", wx.OK | wx.ICON_ERROR)
Ejemplo n.º 2
0
 def on_save(self, event):
     '''Save button saves current stoplist to file'''
     dialog = wx.FileDialog(self,
                            message='',
                            defaultDir=self.parent.dirname,
                            defaultFile='',
                            wildcard='*',
                            style=wx.SAVE)
     response = dialog.ShowModal()
     path = dialog.GetPath()
     dialog.Destroy()
     if response == wx.ID_OK:
         if os.path.isfile(path):
             msg = wx.MessageDialog(self,
                                    message='The file {0} already exists. Overwrite?'.format(path),
                                    style=wx.YES_NO | wx.NO_DEFAULT |
                                            wx.ICON_QUESTION)
             confirm = msg.ShowModal()
             msg.Destroy()
             if confirm != wx.ID_YES:
                 return
         content = RE_WORD.findall(self.textctrl.GetValue())
         content = ['{0}\r\n'.format(s.encode('utf-8')) for s in content]
         try:
             with open(path, 'w') as savfile:
                 savfile.writelines(content)
         except Exception as error:
             wx.MessageBox(str(error), '', wx.OK | wx.ICON_ERROR)
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 def on_open(self, event):
     """Open button reads stoplist from file"""
     dialog = wx.FileDialog(
         self, message="", defaultDir=self.parent.dirname, defaultFile="", wildcard="*", style=wx.OPEN
     )
     response = dialog.ShowModal()
     path = dialog.GetPath()
     dialog.Destroy()
     if response == wx.ID_OK:
         try:
             with open(path, "r") as inputfile:
                 content = unicode(inputfile.read(), "utf-8")
                 content = RE_WORD.findall(content)
                 if self.textctrl.GetValue():
                     self.textctrl.WriteText("\n")
                 self.textctrl.WriteText("\n".join(content))
         except Exception as error:
             wx.MessageBox(str(error), "", wx.OK | wx.ICON_ERROR)
     dialog.Destroy()
Ejemplo n.º 6
0
 def on_open(self, event):
     '''Open button reads stoplist from file'''
     dialog = wx.FileDialog(self,
                            message='',
                            defaultDir=self.parent.dirname,
                            defaultFile='',
                            wildcard='*',
                            style=wx.OPEN)
     response = dialog.ShowModal()
     path = dialog.GetPath()
     dialog.Destroy()
     if response == wx.ID_OK:
         try:
             with open(path, 'r') as inputfile:
                 content = unicode(inputfile.read(), 'utf-8')
                 content = RE_WORD.findall(content)
                 if self.textctrl.GetValue():
                     self.textctrl.WriteText('\n')
                 self.textctrl.WriteText('\n'.join(content))
         except Exception as error:
             wx.MessageBox(str(error), '', wx.OK | wx.ICON_ERROR)
     dialog.Destroy()
Ejemplo n.º 7
0
 def on_ok(self, event):
     """OK button applies stoplist changes and closes dialogue"""
     self.stoplist = RE_WORD.findall(self.textctrl.GetValue())
     self.stoplist = [s.lower() for s in self.stoplist]
     self.EndModal(wx.ID_OK)
Ejemplo n.º 8
0
 def on_ok(self, event):
     '''OK button applies stoplist changes and closes dialogue'''
     self.stoplist = RE_WORD.findall(self.textctrl.GetValue())
     self.stoplist = [s.lower() for s in self.stoplist]
     self.EndModal(wx.ID_OK)