def InitCategoryCheckView(self): #if not Globals.MimeTypesSet: # Populate the Known MIME types list with what is in the database try: mtypes = wx.TheMimeTypesManager.EnumAllFileTypes() except wx.PyAssertionError: mtypes = [] # TODO: On wxMac, EnumAllFileTypes produces tons of dupes, which # causes quirky behavior because the list control doesn't expect # dupes, and simply wastes space. So remove the dupes for now, # then remove this hack when we fix EnumAllFileTypes on Mac. #mimes = set(mtypes) mimes = set() for mime in mtypes: if not mime.startswith('image') and not mime.startswith( 'audio') and not mime.startswith('video'): mimes.add(mime) """ mimes = {} for mt in mtypes: category = mt.lower().split("/") #print category if mimes.has_key(category[0]): if len(category) >= 2: if category[1] not in mimes[category[0]]: mimes[category[0]].append(category[1]) else: if len(category) >= 2: mimes[category[0]] = [category[1]] else: mimes[category[0]] = [] """ """ self.listCtrl1 = wx.ListCtrl(id=wxID_FRMEMAILPREPROCESSINGLISTCTRL1, name='listCtrl1', parent=self.panEmailPreProcessing, pos=wx.Point(152, 200), size=wx.Size(432, 368), style=wx.LC_ICON) """ self.treeCategoryCheckView = FileCategoryCheckView( self.panEmailPreProcessing, MimeTypeSet=mimes, id=wx.NewId(), pos=wx.Point(152, 200), size=wx.Size(432, 368), CheckedList=Globals.AttachmentsCheckedMimes) self.treeCategoryCheckView.SetConstraints( LayoutAnchors(self.treeCategoryCheckView, True, True, True, True))
def InitCategoryCheckView(self): #if not Globals.MimeTypeSet: # Populate the Known MIME types list with what is in the database try: mtypes = wx.TheMimeTypesManager.EnumAllFileTypes() except wx.PyAssertionError: mtypes = [] # TODO: On wxMac, EnumAllFileTypes produces tons of dupes, which # causes quirky behavior because the list control doesn't expect # dupes, and simply wastes space. So remove the dupes for now, # then remove this hack when we fix EnumAllFileTypes on Mac. mimes = set() for mime in mtypes: if not mime.startswith('image') and not mime.startswith( 'audio') and not mime.startswith('video'): mimes.add(mime) #else: # mimes = Globals.MimeTypeSet """ self.treeCategoryCheckView = FileCategoryCheckView(self.panTextPreProcessing, MimeTypeSet=mimes, id=wx.NewId(),pos=wx.Point(16, 200), size=wx.Size(440, 384), CheckedList=Globals.TextCatCategoryList) self.treeCategoryCheckView.SetConstraints(LayoutAnchors(self.treeCategoryCheckView, True, True, True, True)) """ self.treeCategoryCheckView = FileCategoryCheckView( self.panCategoryView, MimeTypeSet=mimes, id=wx.NewId(), pos=wx.Point(8, 32), size=wx.Size(624, 392), CheckedList=Globals.KeywordsSearchCategoryList) self.treeCategoryCheckView.SetConstraints( LayoutAnchors(self.treeCategoryCheckView, True, True, True, True)) """ self.treeDirCheckView = DirectoryCheckView(self.panDirView, id=wx.NewId(), pos=wx.Point(8, 32), size=wx.Size(624, 392), CheckedList=Globals.KeywordsSearchDirList) self.treeDirCheckView.SetConstraints(LayoutAnchors(self.treeDirCheckView, True, True, True, True)) """ """
def InitDirCheckView(self): self.treeDirCheckView = DirectoryCheckView( self.panDirView, id=wx.NewId(), pos=wx.Point(0, 0), size=wx.Size(352, 432), CheckedList=Globals.TextCatDirList) self.treeDirCheckView.SetConstraints( LayoutAnchors(self.treeDirCheckView, True, True, True, True)) self.treeCategoryCheckView = FileCategoryCheckView( self.panCategoryView, id=wx.NewId(), pos=wx.Point(8, 0), size=wx.Size(344, 432), CheckedList=Globals.TextCatCategoryList) self.treeCategoryCheckView.SetConstraints( LayoutAnchors(self.treeCategoryCheckView, True, True, True, True)) """
def InitCategoryCheckView(self): #if not Globals.MimeTypeSet: # Populate the Known MIME types list with what is in the database try: mtypes = wx.TheMimeTypesManager.EnumAllFileTypes() except wx.PyAssertionError: mtypes = [] # TODO: On wxMac, EnumAllFileTypes produces tons of dupes, which # causes quirky behavior because the list control doesn't expect # dupes, and simply wastes space. So remove the dupes for now, # then remove this hack when we fix EnumAllFileTypes on Mac. """ mimes = {} for mt in mtypes: category = mt.lower().split("/") #print category if mimes.has_key(category[0]): if len(category) >= 2: if category[1] not in mimes[category[0]]: mimes[category[0]].append(category[1]) else: if len(category) >= 2: mimes[category[0]] = [category[1]] else: mimes[category[0]] = [] """ mimes = set() for mime in mtypes: if not mime.startswith('image') and not mime.startswith('audio') and not mime.startswith('video'): mimes.add(mime) #else: # mimes = Globals.MimeTypeSet self.treeCategoryCheckView = FileCategoryCheckView(self.panTextPreProcessing, MimeTypeSet=mimes, id=wx.NewId(),pos=wx.Point(16, 200), size=wx.Size(440, 384), CheckedList=Globals.TextCatCategoryList) self.treeCategoryCheckView.SetConstraints(LayoutAnchors(self.treeCategoryCheckView, True, True, True, True))
class frmEmailPreprocessing(wx.Frame): def _init_ctrls(self, prnt): # generated method, don't edit wx.Frame.__init__(self, id=wxID_FRMEMAILPREPROCESSING, name='frmEmailPreprocessing', parent=prnt, pos=wx.Point(352, -17), size=wx.Size(699, 804), style=wx.DEFAULT_FRAME_STYLE, title='Email Preprocessing') self.SetClientSize(wx.Size(691, 770)) self.SetWindowVariant(wx.WINDOW_VARIANT_MINI) self.SetCursor(wx.STANDARD_CURSOR) self.Center(wx.BOTH) self.SetBackgroundColour(wx.Colour(125, 152, 221)) self.SetAutoLayout(True) self.panEmailPreProcessing = wx.Panel( id=wxID_FRMEMAILPREPROCESSINGPANEMAILPREPROCESSING, name='panEmailPreProcessing', parent=self, pos=wx.Point(16, 16), size=wx.Size(656, 700), style=wx.TAB_TRAVERSAL) self.panEmailPreProcessing.SetBackgroundColour(wx.Colour( 225, 236, 255)) self.panEmailPreProcessing.SetAutoLayout(False) self.panEmailPreProcessing.SetConstraints( LayoutAnchors(self.panEmailPreProcessing, True, True, True, True)) self.panEmailPreProcessing.SetFont( wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.btnClose = wx.Button(id=wxID_FRMEMAILPREPROCESSINGBTNCLOSE, label='&Cancel', name='btnClose', parent=self, pos=wx.Point(449, 730), size=wx.Size(96, 23), style=0) self.btnClose.SetFont( wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, 'Arial')) self.btnClose.SetConstraints( LayoutAnchors(self.btnClose, False, False, True, True)) self.btnClose.Bind(wx.EVT_BUTTON, self.OnBtnCloseButton, id=wxID_FRMEMAILPREPROCESSINGBTNCLOSE) self.btnSave = wx.Button(id=wxID_FRMEMAILPREPROCESSINGBTNSAVE, label='&Save And Close', name='btnSave', parent=self, pos=wx.Point(557, 732), size=wx.Size(120, 23), style=0) self.btnSave.SetFont( wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, 'Arial')) self.btnSave.SetConstraints( LayoutAnchors(self.btnSave, False, False, True, True)) self.btnSave.Bind(wx.EVT_BUTTON, self.OnBtnSaveButton, id=wxID_FRMEMAILPREPROCESSINGBTNSAVE) self.staticText1 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT1, label='Address Book Path:', name='staticText1', parent=self.panEmailPreProcessing, pos=wx.Point(48, 56), size=wx.Size(94, 13), style=0) self.staticText4 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT4, label='Preprocess Emails and Attachments:', name='staticText4', parent=self.panEmailPreProcessing, pos=wx.Point(16, 16), size=wx.Size(297, 19), style=0) self.staticText4.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText5 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT5, label=u'Select File Types To Index:', name='staticText5', parent=self.panEmailPreProcessing, pos=wx.Point(48, 200), size=wx.Size(80, 48), style=0) self.staticText6 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT6, label=u'1.', name='staticText6', parent=self.panEmailPreProcessing, pos=wx.Point(16, 52), size=wx.Size(15, 19), style=0) self.staticText6.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText9 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT9, label='5.', name='staticText9', parent=self.panEmailPreProcessing, pos=wx.Point(16, 588), size=wx.Size(15, 19), style=0) self.staticText9.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.btnBrowseAddressBook = wx.Button( id=wxID_FRMEMAILPREPROCESSINGBTNBROWSEADDRESSBOOK, label='...', name='btnBrowseAddressBook', parent=self.panEmailPreProcessing, pos=wx.Point(600, 48), size=wx.Size(43, 23), style=0) self.btnBrowseAddressBook.Bind( wx.EVT_BUTTON, self.OnBtnBrowseAddressBookButton, id=wxID_FRMEMAILPREPROCESSINGBTNBROWSEADDRESSBOOK) self.staticText2 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT2, label='4.', name='staticText2', parent=self.panEmailPreProcessing, pos=wx.Point(16, 196), size=wx.Size(15, 19), style=0) self.staticText2.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.btnBrowseEmailPath = wx.Button( id=wxID_FRMEMAILPREPROCESSINGBTNBROWSEEMAILPATH, label='...', name='btnBrowseEmailPath', parent=self.panEmailPreProcessing, pos=wx.Point(600, 80), size=wx.Size(43, 23), style=0) self.btnBrowseEmailPath.Bind( wx.EVT_BUTTON, self.OnBtnBrowseEmailPathButton, id=wxID_FRMEMAILPREPROCESSINGBTNBROWSEEMAILPATH) self.staticText7 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT7, label='6.', name='staticText7', parent=self.panEmailPreProcessing, pos=wx.Point(16, 620), size=wx.Size(15, 19), style=0) self.staticText7.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText3 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT3, label='Messages Path:', name='staticText3', parent=self.panEmailPreProcessing, pos=wx.Point(48, 88), size=wx.Size(76, 13), style=0) self.btnBrowseAttachmentsPath = wx.Button( id=wxID_FRMEMAILPREPROCESSINGBTNBROWSEATTACHMENTSPATH, label='...', name='btnBrowseAttachmentsPath', parent=self.panEmailPreProcessing, pos=wx.Point(600, 136), size=wx.Size(43, 23), style=0) self.btnBrowseAttachmentsPath.Bind( wx.EVT_BUTTON, self.OnBtnBrowseAttachmentsPathButton, id=wxID_FRMEMAILPREPROCESSINGBTNBROWSEATTACHMENTSPATH) self.staticText8 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT8, label='7.', name='staticText8', parent=self.panEmailPreProcessing, pos=wx.Point(16, 660), size=wx.Size(15, 19), style=0) self.staticText8.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText11 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT11, label='3.', name='staticText11', parent=self.panEmailPreProcessing, pos=wx.Point(16, 140), size=wx.Size(15, 19), style=0) self.staticText11.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText10 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT10, label='Attachments Path:', name='staticText10', parent=self.panEmailPreProcessing, pos=wx.Point(48, 144), size=wx.Size(90, 13), style=0) self.staticText12 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT12, label='Get Stopwords List:', name='staticText12', parent=self.panEmailPreProcessing, pos=wx.Point(40, 592), size=wx.Size(94, 13), style=0) self.staticText13 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT13, label=u'2.', name='staticText13', parent=self.panEmailPreProcessing, pos=wx.Point(16, 84), size=wx.Size(15, 19), style=0) self.staticText13.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.txtAddressBookPath = wx.TextCtrl( id=wxID_FRMEMAILPREPROCESSINGTXTADDRESSBOOKPATH, name='txtAddressBookPath', parent=self.panEmailPreProcessing, pos=wx.Point(152, 48), size=wx.Size(432, 21), style=0, value='') self.txtEmailsPath = wx.TextCtrl( id=wxID_FRMEMAILPREPROCESSINGTXTEMAILSPATH, name='txtEmailsPath', parent=self.panEmailPreProcessing, pos=wx.Point(152, 80), size=wx.Size(432, 21), style=0, value='') self.txtAttachmentsPath = wx.TextCtrl( id=wxID_FRMEMAILPREPROCESSINGTXTATTACHMENTSPATH, name='txtAttachmentsPath', parent=self.panEmailPreProcessing, pos=wx.Point(152, 136), size=wx.Size(432, 21), style=0, value='') self.btnStopwords = wx.Button( id=wxID_FRMEMAILPREPROCESSINGBTNSTOPWORDS, label='Stopwords List...', name='btnStopwords', parent=self.panEmailPreProcessing, pos=wx.Point(152, 584), size=wx.Size(208, 23), style=0) self.btnStopwords.Bind(wx.EVT_BUTTON, self.OnBtnStopwordsButton, id=wxID_FRMEMAILPREPROCESSINGBTNSTOPWORDS) self.choiceStemmers = wx.Choice( choices=[u'None - Do not Stem Words', u'Porter Stemmer'], id=wxID_FRMEMAILPREPROCESSINGCHOICESTEMMERS, name=u'choiceStemmers', parent=self.panEmailPreProcessing, pos=wx.Point(152, 616), size=wx.Size(208, 21), style=0) self.choiceStemmers.SetStringSelection(u'None') self.choiceStemmers.SetHelpText(u'') self.choiceStemmers.SetSelection(0) self.choiceStemmers.SetLabel('') self.btnStartScan = wx.Button( id=wxID_FRMEMAILPREPROCESSINGBTNSTARTSCAN, label='Start Preprocessing', name='btnStartScan', parent=self.panEmailPreProcessing, pos=wx.Point(152, 656), size=wx.Size(208, 23), style=0) self.btnStartScan.Bind(wx.EVT_BUTTON, self.OnBtnStartScanButton, id=wxID_FRMEMAILPREPROCESSINGBTNSTARTSCAN) self.staticText14 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT14, label=u'Finally:', name='staticText14', parent=self.panEmailPreProcessing, pos=wx.Point(40, 664), size=wx.Size(34, 13), style=0) self.staticText15 = wx.StaticText( id=wxID_FRMEMAILPREPROCESSINGSTATICTEXT15, label=u'Select a Stemmer:', name='staticText15', parent=self.panEmailPreProcessing, pos=wx.Point(40, 624), size=wx.Size(87, 13), style=0) self.chkIndexMessages = wx.CheckBox( id=wxID_FRMEMAILPREPROCESSINGCHKINDEXMESSAGES, label=u'Index Messages for quick searching', name=u'chkIndexMessages', parent=self.panEmailPreProcessing, pos=wx.Point(152, 112), size=wx.Size(216, 13), style=0) self.chkIndexMessages.SetValue(True) self.chkIndexMessages.Bind( wx.EVT_CHECKBOX, self.OnChkIndexMessagesCheckbox, id=wxID_FRMEMAILPREPROCESSINGCHKINDEXMESSAGES) self.chkIndexAttachments = wx.CheckBox( id=wxID_FRMEMAILPREPROCESSINGCHKINDEXATTACHMENTS, label=u'Index Attachments for quick searching', name=u'chkIndexAttachments', parent=self.panEmailPreProcessing, pos=wx.Point(152, 168), size=wx.Size(216, 13), style=0) self.chkIndexAttachments.SetValue(True) self.chkIndexAttachments.Bind( wx.EVT_CHECKBOX, self.OnChkIndexAttachmentsCheckbox, id=wxID_FRMEMAILPREPROCESSINGCHKINDEXATTACHMENTS) def __init__(self, parent): self._init_ctrls(parent) self.SetIcon(images.getMAKE2Icon()) self.InitCategoryCheckView() if len(Globals.EmailsStopwords) == 0: try: self.ReadStopwordsFromDB() except: pass def OnBtnCloseButton(self, event): self.Destroy() def OnBtnSaveButton(self, event): event.Skip() self.UpdateSettings() if not self.CheckSettingsError(): return self.Close() def ReadStopwordsFromDB(self): db = SqliteDatabase(Globals.EmailsFileName) if not db.OpenConnection(): return query = "SELECT Stopword FROM %s" % Constants.StopwordsTable rows = db.FetchAllRows(query) #print len(rows) for row in rows: #print row[0] Globals.EmailsStopwords.add(row[0]) #print Globals.KeyWords db.CloseConnection() def InitCategoryCheckView(self): #if not Globals.MimeTypesSet: # Populate the Known MIME types list with what is in the database try: mtypes = wx.TheMimeTypesManager.EnumAllFileTypes() except wx.PyAssertionError: mtypes = [] # TODO: On wxMac, EnumAllFileTypes produces tons of dupes, which # causes quirky behavior because the list control doesn't expect # dupes, and simply wastes space. So remove the dupes for now, # then remove this hack when we fix EnumAllFileTypes on Mac. #mimes = set(mtypes) mimes = set() for mime in mtypes: if not mime.startswith('image') and not mime.startswith( 'audio') and not mime.startswith('video'): mimes.add(mime) """ mimes = {} for mt in mtypes: category = mt.lower().split("/") #print category if mimes.has_key(category[0]): if len(category) >= 2: if category[1] not in mimes[category[0]]: mimes[category[0]].append(category[1]) else: if len(category) >= 2: mimes[category[0]] = [category[1]] else: mimes[category[0]] = [] """ """ self.listCtrl1 = wx.ListCtrl(id=wxID_FRMEMAILPREPROCESSINGLISTCTRL1, name='listCtrl1', parent=self.panEmailPreProcessing, pos=wx.Point(152, 200), size=wx.Size(432, 368), style=wx.LC_ICON) """ self.treeCategoryCheckView = FileCategoryCheckView( self.panEmailPreProcessing, MimeTypeSet=mimes, id=wx.NewId(), pos=wx.Point(152, 200), size=wx.Size(432, 368), CheckedList=Globals.AttachmentsCheckedMimes) self.treeCategoryCheckView.SetConstraints( LayoutAnchors(self.treeCategoryCheckView, True, True, True, True)) def CheckSettingsError(self): #Globals.TextCatDirList = [] #self.treeDirCheckView.UpdateCheckedList(Globals.TextCatDirList) #Globals.TextCatCategoryList = [] self.treeCategoryCheckView.UpdateCheckedList( Globals.AttachmentsCheckedMimes) errMsg = "" """ if len(Globals.Keywords) == 0: errMsg = "Please import keywords from a text file before start searching.\n File must have one keyword per line." """ #if len(self.txtAddressBookPath.GetValue()) == 0: # errMsg = "Please enter or browse to the directory path where address book is present." if len(self.txtEmailsPath.GetValue()) == 0: errMsg = "Please enter or browse to the directory path where email files are present." CommonFunctions.ShowErrorMessage(self, errMsg, True) return False else: return True """ def LoadSettingsTable(self): if len(Globals.TextCatDirList) == 0: db = SqliteDatabase(Globals.EmailsFileName) if not db.OpenConnection(): return query = "select Stemmer, DirList, CategoryList from " + Constants.TextCatSettingsTable rows = db.FetchAllRows(query) for row in rows: Globals.Stemmer = row[0] self.DirList = CommonFunctions.RemoveDoubleSlashes(row[1]) self.CategoryList = row[2] Globals.TextCatCategoryList = self.CategoryList.split(';') Globals.TextCatDirList = self.DirList.split(';') self.choiceStemmers.SetStringSelection(Globals.Stemmer) #print Globals.TextCatCategoryList #print Globals.TextCatDirList """ def UpdateSettings(self): Globals.TextCatCategoryList = [] Globals.TextCatDirList = [] self.DirList = "" self.CategoryList = "" self.treeCategoryCheckView.UpdateCheckedList( Globals.TextCatCategoryList) #self.treeDirCheckView.UpdateCheckedList(Globals.TextCatDirList) #UpdateTextCatDirList #if self.OneFolderSelected: if self.OneFolderSelected: for adir in self.OneFolderList: self.DirList += adir Globals.TextCatDirList.append(adir) """ if self.OneFolderPath: Globals.TextCatDirList.append(self.OneFolderPath) """ Globals.Stemmer = self.choiceStemmers.GetStringSelection() for adir in Globals.TextCatDirList: if not self.DirList == "": self.DirList += ";" self.DirList += adir for cat in Globals.TextCatCategoryList: if not self.CategoryList == "": self.CategoryList += ";" self.CategoryList += cat db = SqliteDatabase(Globals.EmailsFileName) if not db.OpenConnection(): return query = "delete from %s;" % Constants.TextCatSettingsTable db.ExecuteNonQuery(query) query = "insert into " + Constants.TextCatSettingsTable + " (Stemmer, DirList, CategoryList) values (?,?,?)" #query += db.SqlSQuote(Globals.Stemmer) + "," + db.SqlSQuote(self.DirList) + "," #query += db.SqlSQuote(self.CategoryList) + ")" db.ExecuteNonQuery( query, [(Globals.Stemmer, PlatformMethods.Encode( self.DirList), self.CategoryList)]) db.CloseConnection() def OnBtnStopwordsButton(self, event): import frmStopwords formStopwords = frmStopwords.create(self, IsEmail=True, Stopwords=Globals.EmailsStopwords) #formStopwords = frmStopwords.create(self, IsEmail=True) formStopwords.Show() event.Skip() def OnBtnSelectFolderButton(self, event): self.OneFolderList = [] dlg = wx.DirDialog(self) try: if dlg.ShowModal() == wx.ID_OK: dirPath = dlg.GetPath() self.OneFolderSelected = True #self.OneFolderPath = dir for root, dirs, files in os.walk(dirPath): for adir in dirs: self.OneFolderList.append(os.path.join(root, adir)) """ for dir in self.OneFolderList: print dir """ finally: dlg.Destroy() event.Skip() def OnBtnBrowseAddressBookButton(self, event): dlg = wx.DirDialog(self) try: if dlg.ShowModal() == wx.ID_OK: dirPath = dlg.GetPath() #self.OneFolderPath = dir self.txtAddressBookPath.SetValue(dirPath) finally: dlg.Destroy() event.Skip() def OnBtnStartScanButton(self, event): if not self.CheckSettingsError(): return import dlgEmailPreprocessingProgress emailProcess = dlgEmailPreprocessingProgress.create( self, self.txtAddressBookPath.GetValue(), self.txtEmailsPath.GetValue(), self.txtAttachmentsPath.GetValue(), Globals.AttachmentsCheckedMimes, self.chkIndexMessages.GetValue(), self.chkIndexAttachments.GetValue()) #scanMAC.StartScan(dir) emailProcess.ShowModal() #emailProcess.scanThread.Start() self.Close() event.Skip() def OnBtnBrowseEmailPathButton(self, event): dlg = wx.DirDialog(self) try: if dlg.ShowModal() == wx.ID_OK: dirPath = dlg.GetPath() #self.OneFolderPath = dir self.txtEmailsPath.SetValue(dirPath) finally: dlg.Destroy() event.Skip() def OnBtnBrowseAttachmentsPathButton(self, event): dlg = wx.DirDialog(self) try: if dlg.ShowModal() == wx.ID_OK: dirPath = dlg.GetPath() #self.OneFolderPath = dir self.txtAttachmentsPath.SetValue(dirPath) finally: dlg.Destroy() event.Skip() def OnChkIndexMessagesCheckbox(self, event): event.Skip() def OnChkIndexAttachmentsCheckbox(self, event): self.treeCategoryCheckView.Enable(self.chkIndexAttachments.GetValue()) event.Skip()
class frmCustomizeKeywordSearch(wx.Frame): def _init_coll_notebookCustomize_Pages(self, parent): # generated method, don't edit parent.AddPage(imageId=-1, page=self.panStringMatching, select=False, text=u'String Matching') parent.AddPage(imageId=-1, page=self.panKeywords, select=False, text=u'Keywords') parent.AddPage(imageId=-1, page=self.panDirView, select=True, text=u'Select Directory') parent.AddPage(imageId=-1, page=self.panCategoryView, select=False, text=u'Select File Types') def _init_ctrls(self, prnt): # generated method, don't edit wx.Frame.__init__(self, id=wxID_FRMCUSTOMIZEKEYWORDSEARCH, name=u'frmCustomizeKeywordSearch', parent=prnt, pos=wx.Point(428, 61), size=wx.Size(720, 665), style=wx.DEFAULT_FRAME_STYLE, title=u'Customized Keyword Search') self.SetClientSize(wx.Size(712, 631)) self.SetWindowVariant(wx.WINDOW_VARIANT_MINI) self.SetCursor(wx.STANDARD_CURSOR) self.Center(wx.BOTH) self.SetBackgroundColour(wx.Colour(125, 152, 221)) self.SetAutoLayout(True) self.SetFont( wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'MS Shell Dlg 2')) self.panCustomize = wx.Panel( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHPANCUSTOMIZE, name=u'panCustomize', parent=self, pos=wx.Point(16, 16), size=wx.Size(678, 559), style=wx.TAB_TRAVERSAL) self.panCustomize.SetBackgroundColour(wx.Colour(225, 236, 255)) self.panCustomize.SetAutoLayout(False) self.panCustomize.SetConstraints( LayoutAnchors(self.panCustomize, True, True, True, True)) self.panCustomize.SetFont( wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.staticText1 = wx.StaticText( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHSTATICTEXT1, label=u'Customized Keyword Search', name='staticText1', parent=self.panCustomize, pos=wx.Point(16, 16), size=wx.Size(231, 19), style=wx.ALIGN_CENTRE) self.staticText1.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, 'Tahoma')) self.staticText1.SetForegroundColour(wx.Colour(0, 0, 255)) self.btnClose = wx.Button(id=wxID_FRMCUSTOMIZEKEYWORDSEARCHBTNCLOSE, label='&Cancel', name='btnClose', parent=self, pos=wx.Point(454, 591), size=wx.Size(96, 23), style=0) self.btnClose.SetFont( wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, 'Arial')) self.btnClose.SetConstraints( LayoutAnchors(self.btnClose, False, False, True, True)) self.btnClose.Bind(wx.EVT_BUTTON, self.OnBtnCloseButton, id=wxID_FRMCUSTOMIZEKEYWORDSEARCHBTNCLOSE) self.btnSave = wx.Button(id=wxID_FRMCUSTOMIZEKEYWORDSEARCHBTNSAVE, label='&Save And Close', name='btnSave', parent=self, pos=wx.Point(570, 593), size=wx.Size(120, 23), style=0) self.btnSave.SetFont( wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, 'Arial')) self.btnSave.SetConstraints( LayoutAnchors(self.btnSave, False, False, True, True)) self.btnSave.Bind(wx.EVT_BUTTON, self.OnBtnSaveButton, id=wxID_FRMCUSTOMIZEKEYWORDSEARCHBTNSAVE) self.btnStartSearch = wx.Button( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHBTNSTARTSEARCH, label=u'Start Search...', name=u'btnStartSearch', parent=self.panCustomize, pos=wx.Point(16, 518), size=wx.Size(192, 24), style=0) self.btnStartSearch.SetConstraints( LayoutAnchors(self.btnStartSearch, True, False, False, True)) self.btnStartSearch.Bind( wx.EVT_BUTTON, self.OnBtnStartSearchButton, id=wxID_FRMCUSTOMIZEKEYWORDSEARCHBTNSTARTSEARCH) self.notebookCustomize = wx.Notebook( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHNOTEBOOKCUSTOMIZE, name=u'notebookCustomize', parent=self.panCustomize, pos=wx.Point(16, 48), size=wx.Size(646, 456), style=0) self.notebookCustomize.SetConstraints( LayoutAnchors(self.notebookCustomize, True, True, True, True)) self.panStringMatching = wx.Panel( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHPANSTRINGMATCHING, name=u'panStringMatching', parent=self.notebookCustomize, pos=wx.Point(0, 0), size=wx.Size(638, 430), style=wx.TAB_TRAVERSAL) self.panStringMatching.SetAutoLayout(True) self.chkCaseInsensitive = wx.CheckBox( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHCHKCASEINSENSITIVE, label=u'Case Insensitive', name=u'chkCaseInsensitive', parent=self.panStringMatching, pos=wx.Point(16, 24), size=wx.Size(128, 13), style=0) self.chkCaseInsensitive.SetValue(True) self.chkCaseInsensitive.Enable(False) self.chkCaseSensitive = wx.CheckBox( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHCHKCASESENSITIVE, label=u'Case Sensitive', name=u'chkCaseSensitive', parent=self.panStringMatching, pos=wx.Point(16, 56), size=wx.Size(120, 13), style=0) self.chkCaseSensitive.SetValue(False) self.chkCaseSensitive.Enable(False) self.chkCaseSensitive.SetToolTipString(u'chkCaseSensitive') self.panKeywords = wx.Panel( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHPANKEYWORDS, name=u'panKeywords', parent=self.notebookCustomize, pos=wx.Point(0, 0), size=wx.Size(638, 430), style=wx.TAB_TRAVERSAL) self.panKeywords.SetAutoLayout(True) self.panDirView = wx.Panel(id=wxID_FRMCUSTOMIZEKEYWORDSEARCHPANDIRVIEW, name=u'panDirView', parent=self.notebookCustomize, pos=wx.Point(0, 0), size=wx.Size(638, 430), style=wx.TAB_TRAVERSAL) self.panDirView.SetAutoLayout(True) self.panCategoryView = wx.Panel( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHPANCATEGORYVIEW, name=u'panCategoryView', parent=self.notebookCustomize, pos=wx.Point(0, 0), size=wx.Size(638, 430), style=wx.TAB_TRAVERSAL) self.panCategoryView.SetAutoLayout(True) self.staticText2 = wx.StaticText( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHSTATICTEXT2, label= u'Select the File Types/Categories in which you want to search for Keywords:', name='staticText2', parent=self.panCategoryView, pos=wx.Point(8, 8), size=wx.Size(363, 13), style=0) self.staticText3 = wx.StaticText( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHSTATICTEXT3, label=u'Select a Path to search recursivley:', name='staticText3', parent=self.panDirView, pos=wx.Point(8, 8), size=wx.Size(170, 13), style=0) self.txtKeywords = wx.TextCtrl( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHTXTKEYWORDS, name=u'txtKeywords', parent=self.panKeywords, pos=wx.Point(8, 96), size=wx.Size(624, 328), style=wx.TE_LINEWRAP | wx.TE_MULTILINE | wx.TE_READONLY | wx.VSCROLL, value=u'') self.txtKeywords.SetConstraints( LayoutAnchors(self.txtKeywords, True, True, True, True)) self.lblKeywords = wx.StaticText( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHLBLKEYWORDS, label='Keywords found in database:', name=u'lblKeywords', parent=self.panKeywords, pos=wx.Point(16, 72), size=wx.Size(190, 16), style=0) self.lblKeywords.SetFont( wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.lblKeywords.SetForegroundColour(wx.Colour(0, 0, 255)) self.txtFileName = wx.TextCtrl( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHTXTFILENAME, name=u'txtFileName', parent=self.panKeywords, pos=wx.Point(112, 32), size=wx.Size(440, 21), style=wx.TE_READONLY, value=u'') self.txtFileName.SetConstraints( LayoutAnchors(self.txtFileName, True, True, True, False)) self.staticText4 = wx.StaticText( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHSTATICTEXT4, label='Keywords Text File:', name='staticText4', parent=self.panKeywords, pos=wx.Point(8, 32), size=wx.Size(95, 13), style=0) self.staticText4.SetFont( wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.btnBrowse = wx.Button(id=wxID_FRMCUSTOMIZEKEYWORDSEARCHBTNBROWSE, label=u'Browse...', name=u'btnBrowse', parent=self.panKeywords, pos=wx.Point(568, 32), size=wx.Size(59, 23), style=0) self.btnBrowse.SetConstraints( LayoutAnchors(self.btnBrowse, False, True, True, False)) self.btnBrowse.Bind(wx.EVT_BUTTON, self.OnBtnBrowseButton, id=wxID_FRMCUSTOMIZEKEYWORDSEARCHBTNBROWSE) self.staticText5 = wx.StaticText( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHSTATICTEXT5, label=u'Keywords List:', name='staticText5', parent=self.panKeywords, pos=wx.Point(8, 8), size=wx.Size(70, 13), style=0) self.btnSelectFolder = wx.Button( id=wxID_FRMCUSTOMIZEKEYWORDSEARCHBTNSELECTFOLDER, label='...', name=u'btnSelectFolder', parent=self.panDirView, pos=wx.Point(392, 32), size=wx.Size(32, 23), style=0) self.btnSelectFolder.Enable(False) self.btnSelectFolder.Bind( wx.EVT_BUTTON, self.OnBtnSelectFolderButton, id=wxID_FRMCUSTOMIZEKEYWORDSEARCHBTNSELECTFOLDER) self.txtPath = wx.TextCtrl(id=wxID_FRMCUSTOMIZEKEYWORDSEARCHTXTPATH, name='txtPath', parent=self.panDirView, pos=wx.Point(8, 32), size=wx.Size(368, 21), style=0, value='') self.txtPath.Enable(False) self._init_coll_notebookCustomize_Pages(self.notebookCustomize) def __init__(self, parent): self._init_ctrls(parent) self.SetIcon(images.getMAKE2Icon()) self.FileName = "" self.Keywords = set([]) self.KeywordsValue = "" self.DirPath = "" self.CategoryList = "" #self.KeywordsFromDB = True self.LoadSettingsTable() #DBFunctions.CreateKeywordsFrequencyTable(Globals.KeywordsFileName, False) """ if len(Globals.Keywords) == 0: self.ReadKeyWordsFromDatabase() else: self.MakeKeywordsList() if self.KeywordsFromDB: self.lblKeywords.SetLabel("Keywords found in Project database:") else: self.lblKeywords.SetLabel("No keyword is found:") self.txtKeywords.SetValue(self.KeywordsValue) """ self.InitCategoryCheckView() def InitCategoryCheckView(self): #if not Globals.MimeTypeSet: # Populate the Known MIME types list with what is in the database try: mtypes = wx.TheMimeTypesManager.EnumAllFileTypes() except wx.PyAssertionError: mtypes = [] # TODO: On wxMac, EnumAllFileTypes produces tons of dupes, which # causes quirky behavior because the list control doesn't expect # dupes, and simply wastes space. So remove the dupes for now, # then remove this hack when we fix EnumAllFileTypes on Mac. mimes = set() for mime in mtypes: if not mime.startswith('image') and not mime.startswith( 'audio') and not mime.startswith('video'): mimes.add(mime) #else: # mimes = Globals.MimeTypeSet """ self.treeCategoryCheckView = FileCategoryCheckView(self.panTextPreProcessing, MimeTypeSet=mimes, id=wx.NewId(),pos=wx.Point(16, 200), size=wx.Size(440, 384), CheckedList=Globals.TextCatCategoryList) self.treeCategoryCheckView.SetConstraints(LayoutAnchors(self.treeCategoryCheckView, True, True, True, True)) """ self.treeCategoryCheckView = FileCategoryCheckView( self.panCategoryView, MimeTypeSet=mimes, id=wx.NewId(), pos=wx.Point(8, 32), size=wx.Size(624, 392), CheckedList=Globals.KeywordsSearchCategoryList) self.treeCategoryCheckView.SetConstraints( LayoutAnchors(self.treeCategoryCheckView, True, True, True, True)) """ self.treeDirCheckView = DirectoryCheckView(self.panDirView, id=wx.NewId(), pos=wx.Point(8, 32), size=wx.Size(624, 392), CheckedList=Globals.KeywordsSearchDirList) self.treeDirCheckView.SetConstraints(LayoutAnchors(self.treeDirCheckView, True, True, True, True)) """ """ self.treeCtrl1 = wx.TreeCtrl(id=wxID_FRMCUSTOMIZESEARCHTREECTRL1, name='treeCtrl1', parent=self.panCategoryView, pos=wx.Point(8, 32), size=wx.Size(624, 392), style=wx.TR_HAS_BUTTONS) self.treeCtrl1 = wx.TreeCtrl(id=wxID_FRMCUSTOMIZESEARCHTREECTRL1, name='treeCtrl1', parent=self.panDirView, pos=wx.Point(8, 8), size=wx.Size(344, 432), style=wx.TR_HAS_BUTTONS) self.treeCtrl2 = wx.TreeCtrl(id=wxID_FRMCUSTOMIZESEARCHTREECTRL2, name='treeCtrl2', parent=self.panCategoryView, pos=wx.Point(8, 8), size=wx.Size(344, 432), style=wx.TR_HAS_BUTTONS) self.treeDirCheckView.SetConstraints(LayoutAnchors(self.treeDirCheckView, True, True, True, True)) """ #self.treeDirCheckView.Show(True) #self.keywordsRoot = self.treeDirCheckView.AddDirectoryTreeNodes() #self.catRoot = self.treeCategoryCheckView.AddCategoryTreeNodes() def OnBtnCloseButton(self, event): self.Close() def OnBtnSaveButton(self, event): if not self.CheckSettingsError(): return self.UpdateSettingss() self.Close() def UpdateSearchDirectoriesAndCategories(self): Globals.KeywordsSearchCategoryList = [] self.treeCategoryCheckView.UpdateCheckedList( Globals.KeywordsSearchCategoryList) #UpdateKeywordsSearchDirList #Globals.KeywordsSearchDirList = [] #self.treeDirCheckView.UpdateKeywordsSearchDirList(Globals.KeywordsSearchDirList) #print Globals.KeywordsSearchDirList def CheckSettingsError(self): #Globals.KeywordsSearchDirList = [] #self.treeDirCheckView.UpdateCheckedList(Globals.KeywordsSearchDirList) Globals.KeywordsSearchCategoryList = [] self.treeCategoryCheckView.UpdateCheckedList( Globals.KeywordsSearchCategoryList) errMsg = "" #Globals.Keywords = self.KeywordsValue.split(";") if len(Globals.KeywordsDict) == 0: errMsg = "Please import keywords from a text file before start searching.\n File must have one keyword per line." #elif len(Globals.KeywordsSearchDirList) == 0: # errMsg = "Please select directories where to search for Keywords." elif len(Globals.KeywordsSearchCategoryList) == 0: errMsg = "Please select file types / categories to search for Keywords." if not errMsg == "": dlg = wx.MessageDialog(self, errMsg, 'Error', wx.OK | wx.ICON_ERROR) try: dlg.ShowModal() finally: dlg.Destroy() return False else: self.UpdateSettings() return True def UpdateSettings(self): #UpdateKeywordsSearchDirList #Globals.Stemmer = self.choiceStemmers.GetStringSelection() #if self.chkCaseSensitive.GetValue(): # Globals.KeywordsSearchCaseSensitive = 1 #else: # Globals.KeywordsSearchCaseSensitive = 0 self.DirPath = "" #self.CategoryList = "" """ for dir in Globals.KeywordsSearchDirList: if not self.DirPath == "": self.DirPath += ";" self.DirPath += dir """ #for cat in Globals.KeywordsSearchCategoryList: self.CategoryList = ";".join(Globals.KeywordsSearchCategoryList) """ if not self.CategoryList == "": self.CategoryList += ";" self.CategoryList += cat """ db = SqliteDatabase(Globals.KeywordsFileName) if not db.OpenConnection(): return query = "delete from " + Constants.KeywordsSettingsTable + ";" db.ExecuteNonQuery(query) query = "insert into %s (CategoryList) values (?)" % Constants.KeywordsSettingsTable values = [ (self.CategoryList), ] db.ExecuteNonQuery(query, values) db.CloseConnection() def OnChkCaseInsensitiveCheckbox(self, event): event.Skip() def OnChkPrefixCheckbox(self, event): event.Skip() def OnChkSuffixCheckbox(self, event): event.Skip() def OnChkMiddleCheckbox(self, event): event.Skip() """ def OnBtnKeywordsButton(self, event): import frmKeywords frmKey = frmKeywords.create(self) frmKey.ShowModal() event.Skip() """ def OnBtnStartSearchButton(self, event): if not self.CheckSettingsError(): return import dlgKeywordsSearchProgress search = dlgKeywordsSearchProgress.create(self) #scanMAC.StartScan(dir) search.ShowModal() event.Skip() def OnBtnBrowseButton(self, event): dlg = wx.FileDialog(self, "Open Line Separated Keyword Text File", ".", "", "*.*", wx.OPEN) try: if dlg.ShowModal() == wx.ID_OK: self.FileName = dlg.GetPath() self.txtFileName.SetValue(self.FileName) self.ReadKeywordsFromFile(self.FileName) self.txtKeywords.SetValue(self.KeywordsValue.replace( ';', '; ')) self.lblKeywords.SetLabel("Keywords read from File:") else: return None finally: dlg.Destroy() def ReadKeywordsFromFile(self, fileName): fin = open(fileName, "rb") self.KeywordsValue = "" while True: lines = fin.readlines() if not lines: break for word in lines: self.Keywords.add(word.strip().lower()) if self.KeywordsValue == "": self.KeywordsValue += word.strip() else: self.KeywordsValue += ";" + word.strip() fin.close() #delete existing keywords from database print self.KeywordsValue db = SqliteDatabase(Globals.KeywordsFileName) if not db.OpenConnection(): return db.ExecuteNonQuery('delete from %s' % Constants.KeywordsTable) query = "insert into %s (Keyword) values (?)" % Constants.KeywordsTable for word in self.Keywords: print word db.ExecuteMany(query, [(word, )]) #load keywords with their ids self.LoadKeywordsFromDB() def MakeKeywordsList(self): i = 0 for word in Globals.Keywords: if i == 0: self.KeywordsValue += word else: self.KeywordsValue += ";" + word i += 1 def LoadSettingsTable(self): #if len(Globals.KeywordsSearchDirList) == 0: db = SqliteDatabase(Globals.KeywordsFileName) if not db.OpenConnection(): return query = "select CategoryList from " + Constants.KeywordsSettingsTable rows = db.FetchAllRows(query) for row in rows: #Globals.KeywordsSearchCaseInsensitive = int(row[0]) #Globals.KeywordsSearchCaseSensitive = int(row[1]) #self.KeywordsValue = row[2] #self.DirPath = CommonFunctions.RemoveDoubleSlashes(row[3]) #self.DirPath = row[0] self.CategoryList = row[0] db.CloseConnection() db = None #Globals.Keywords = set(self.KeywordsValue.split(';')) Globals.KeywordsSearchCategoryList = self.CategoryList.split(';') self.txtPath.SetValue(self.DirPath) #Globals.KeywordsSearchDirList = self.DirPath.split(';') self.LoadKeywordsFromDB() #self.MakeKeywordsList() self.txtKeywords.SetValue(self.KeywordsValue) #if Globals.CurrentProject.CaseSensitive: self.chkCaseInsensitive.SetValue(Globals.KeywordsSearchCaseSensitive) #self.chkCaseSensitive.SetValue(Globals.KeywordsSearchCaseSensitive) def LoadKeywordsFromDB(self): db = SqliteDatabase(Globals.KeywordsFileName) if not db.OpenConnection(): return #load keywords with their ids rows = db.FetchAllRows('select rowid, Keyword from %s' % Constants.KeywordsTable) Globals.KeywordsDict = {} self.KeywordsValue = "" for row in rows: self.KeywordsValue += row[1] + "; " Globals.KeywordsDict[row[0]] = { 'word': row[1], 're': re.compile("\\b" + row[1] + "\\b", re.I | re.S) } db.CloseConnection() def OnBtnSelectFolderButton(self, event): #self.OneFolderList = [] dlg = wx.DirDialog(self) try: if dlg.ShowModal() == wx.ID_OK: self.txtPath.SetValue(dlg.GetPath()) finally: dlg.Destroy() event.Skip()
class frmTextPreprocessing(wx.Frame): def _init_ctrls(self, prnt): # generated method, don't edit wx.Frame.__init__(self, id=wxID_FRMTEXTPREPROCESSING, name=u'frmTextPreprocessing', parent=prnt, pos=wx.Point(511, 24), size=wx.Size(512, 734), style=wx.DEFAULT_FRAME_STYLE, title=u'Text Preprocessing') self.SetClientSize(wx.Size(504, 700)) self.SetWindowVariant(wx.WINDOW_VARIANT_MINI) self.SetCursor(wx.STANDARD_CURSOR) self.Center(wx.BOTH) self.SetBackgroundColour(wx.Colour(125, 152, 221)) self.SetAutoLayout(True) self.panTextPreProcessing = wx.Panel(id=wxID_FRMTEXTPREPROCESSINGPANTEXTPREPROCESSING, name=u'panTextPreProcessing', parent=self, pos=wx.Point(16, 16), size=wx.Size(469, 628), style=wx.TAB_TRAVERSAL) self.panTextPreProcessing.SetBackgroundColour(wx.Colour(225, 236, 255)) self.panTextPreProcessing.SetAutoLayout(False) self.panTextPreProcessing.SetConstraints(LayoutAnchors(self.panTextPreProcessing, True, True, True, True)) self.panTextPreProcessing.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.btnClose = wx.Button(id=wxID_FRMTEXTPREPROCESSINGBTNCLOSE, label='&Cancel', name='btnClose', parent=self, pos=wx.Point(262, 660), size=wx.Size(96, 23), style=0) self.btnClose.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, 'Arial')) self.btnClose.SetConstraints(LayoutAnchors(self.btnClose, False, False, True, True)) self.btnClose.Bind(wx.EVT_BUTTON, self.OnBtnCloseButton, id=wxID_FRMTEXTPREPROCESSINGBTNCLOSE) self.btnSave = wx.Button(id=wxID_FRMTEXTPREPROCESSINGBTNSAVE, label='&Save And Close', name='btnSave', parent=self, pos=wx.Point(370, 662), size=wx.Size(120, 23), style=0) self.btnSave.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, 'Arial')) self.btnSave.SetConstraints(LayoutAnchors(self.btnSave, False, False, True, True)) self.btnSave.Bind(wx.EVT_BUTTON, self.OnBtnSaveButton, id=wxID_FRMTEXTPREPROCESSINGBTNSAVE) self.btnStopwords = wx.Button(id=wxID_FRMTEXTPREPROCESSINGBTNSTOPWORDS, label=u'Stopwords List...', name=u'btnStopwords', parent=self.panTextPreProcessing, pos=wx.Point(168, 48), size=wx.Size(208, 23), style=0) self.btnStopwords.Bind(wx.EVT_BUTTON, self.OnBtnStopwordsButton, id=wxID_FRMTEXTPREPROCESSINGBTNSTOPWORDS) self.choiceStemmers = wx.Choice(choices=[u'None - Do not Stem Words', u'Porter Stemmer'], id=wxID_FRMTEXTPREPROCESSINGCHOICESTEMMERS, name=u'choiceStemmers', parent=self.panTextPreProcessing, pos=wx.Point(168, 80), size=wx.Size(208, 21), style=0) self.choiceStemmers.SetStringSelection(u'None') self.choiceStemmers.SetHelpText(u'') self.choiceStemmers.SetSelection(0) self.choiceStemmers.SetLabel('') self.btnPreprocess = wx.Button(id=wxID_FRMTEXTPREPROCESSINGBTNPREPROCESS, label=u'Start Indexing', name=u'btnPreprocess', parent=self.panTextPreProcessing, pos=wx.Point(48, 591), size=wx.Size(128, 23), style=0) self.btnPreprocess.SetConstraints(LayoutAnchors(self.btnPreprocess, True, False, False, True)) self.btnPreprocess.Bind(wx.EVT_BUTTON, self.OnBtnPreprocessButton, id=wxID_FRMTEXTPREPROCESSINGBTNPREPROCESS) self.staticText3 = wx.StaticText(id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT3, label=u'3.', name='staticText3', parent=self.panTextPreProcessing, pos=wx.Point(16, 116), size=wx.Size(15, 19), style=0) self.staticText3.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText1 = wx.StaticText(id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT1, label=u'Get Stopwords List:', name='staticText1', parent=self.panTextPreProcessing, pos=wx.Point(48, 56), size=wx.Size(94, 13), style=0) self.staticText4 = wx.StaticText(id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT4, label=u'Text Preprocessing Steps:', name='staticText4', parent=self.panTextPreProcessing, pos=wx.Point(16, 16), size=wx.Size(213, 19), style=0) self.staticText4.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText5 = wx.StaticText(id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT5, label=u'Select a Stemmer:', name='staticText5', parent=self.panTextPreProcessing, pos=wx.Point(48, 88), size=wx.Size(87, 13), style=0) self.staticText6 = wx.StaticText(id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT6, label=u'1.', name='staticText6', parent=self.panTextPreProcessing, pos=wx.Point(16, 52), size=wx.Size(15, 19), style=0) self.staticText6.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText7 = wx.StaticText(id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT7, label='Select A Path to Index Files Recursively:', name='staticText7', parent=self.panTextPreProcessing, pos=wx.Point(48, 120), size=wx.Size(194, 13), style=0) self.staticText8 = wx.StaticText(id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT8, label='5.', name='staticText8', parent=self.panTextPreProcessing, pos=wx.Point(16, 596), size=wx.Size(15, 19), style=0) self.staticText8.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText8.SetConstraints(LayoutAnchors(self.staticText8, True, False, False, True)) self.staticText9 = wx.StaticText(id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT9, label=u'2.', name='staticText9', parent=self.panTextPreProcessing, pos=wx.Point(16, 84), size=wx.Size(15, 19), style=0) self.staticText9.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.btnSelectFolder = wx.Button(id=wxID_FRMTEXTPREPROCESSINGBTNSELECTFOLDER, label='...', name=u'btnSelectFolder', parent=self.panTextPreProcessing, pos=wx.Point(424, 144), size=wx.Size(32, 23), style=0) self.btnSelectFolder.Bind(wx.EVT_BUTTON, self.OnBtnSelectFolderButton, id=wxID_FRMTEXTPREPROCESSINGBTNSELECTFOLDER) self.staticText2 = wx.StaticText(id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT2, label='4.', name='staticText2', parent=self.panTextPreProcessing, pos=wx.Point(16, 172), size=wx.Size(15, 19), style=0) self.staticText2.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.txtPath = wx.TextCtrl(id=wxID_FRMTEXTPREPROCESSINGTXTPATH, name='txtPath', parent=self.panTextPreProcessing, pos=wx.Point(48, 144), size=wx.Size(368, 21), style=0, value='') self.staticText10 = wx.StaticText(id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT10, label='Select the Known Mime Types to Index:', name='staticText10', parent=self.panTextPreProcessing, pos=wx.Point(48, 176), size=wx.Size(190, 13), style=0) def __init__(self, parent): self._init_ctrls(parent) self.SetIcon(images.getMAKE2Icon()) self.DirList = "" self.CategoryList = "" self.LoadSettingsTable() #self.InitDirCheckView() self.InitCategoryCheckView() self.OneFolderList = [] self.OneFolderSelected = False self.OneFolderPath = "" if len(Globals.Stopwords) == 0: try: self.ReadStopwordsFromDB() except: pass def InitCategoryCheckView(self): #if not Globals.MimeTypeSet: # Populate the Known MIME types list with what is in the database try: mtypes = wx.TheMimeTypesManager.EnumAllFileTypes() except wx.PyAssertionError: mtypes = [] # TODO: On wxMac, EnumAllFileTypes produces tons of dupes, which # causes quirky behavior because the list control doesn't expect # dupes, and simply wastes space. So remove the dupes for now, # then remove this hack when we fix EnumAllFileTypes on Mac. """ mimes = {} for mt in mtypes: category = mt.lower().split("/") #print category if mimes.has_key(category[0]): if len(category) >= 2: if category[1] not in mimes[category[0]]: mimes[category[0]].append(category[1]) else: if len(category) >= 2: mimes[category[0]] = [category[1]] else: mimes[category[0]] = [] """ mimes = set() for mime in mtypes: if not mime.startswith('image') and not mime.startswith('audio') and not mime.startswith('video'): mimes.add(mime) #else: # mimes = Globals.MimeTypeSet self.treeCategoryCheckView = FileCategoryCheckView(self.panTextPreProcessing, MimeTypeSet=mimes, id=wx.NewId(),pos=wx.Point(16, 200), size=wx.Size(440, 384), CheckedList=Globals.TextCatCategoryList) self.treeCategoryCheckView.SetConstraints(LayoutAnchors(self.treeCategoryCheckView, True, True, True, True)) def InitDirCheckView(self): self.treeDirCheckView = DirectoryCheckView(self.panDirView, id=wx.NewId(), pos=wx.Point(0, 0), size=wx.Size(352, 432), CheckedList=Globals.TextCatDirList) self.treeDirCheckView.SetConstraints(LayoutAnchors(self.treeDirCheckView, True, True, True, True)) #self.keywordsRoot = self.treeDirCheckView.AddDirectoryTreeNodes() def OnBtnCloseButton(self, event): self.Destroy() def OnBtnSaveButton(self, event): self.UpdateSettings() if not self.CheckSettingsError(): return self.Close() def ReadStopwordsFromDB(self): db = SqliteDatabase(Globals.TextCatFileName) if not db.OpenConnection(): return query = "SELECT Stopword FROM " + Constants.StopwordsTable rows = db.FetchAllRows(query) #print len(rows) #self.StopwordsValue = "" #i = 0 for row in rows: #print row[0] Globals.Stopwords.add(row[0]) #if i == 0: # self.StopwordsValue += row[0] #else: # self.StopwordsValue += "; " + row[0] #i += 1 #print Globals.KeyWords db.CloseConnection() def CheckSettingsError(self): #Globals.TextCatDirList = [] #self.treeDirCheckView.UpdateCheckedList(Globals.TextCatDirList) #Globals.TextCatCategoryList = [] #self.treeCategoryCheckView.UpdateCheckedList(Globals.TextCatCategoryList) errMsg = "" """ if len(Globals.Keywords) == 0: errMsg = "Please import keywords from a text file before start searching.\n File must have one keyword per line." """ if not os.path.isdir(self.txtPath.GetValue()): errMsg = "Not a valid Path. Please Enter a valid path for Text Preprocessing!" elif len(Globals.TextCatDirList) == 0: errMsg = "Please select directories to get text for Text Preprocessing." #elif len(Globals.TextCatCategoryList) == 0: #if self.OneFolderSelected: #errMsg = "Please select file types / categories to be scanned for Text Clustering." if not errMsg == "" : dlg = wx.MessageDialog(self, errMsg, 'Error', wx.OK | wx.ICON_ERROR) try: dlg.ShowModal() finally: dlg.Destroy() return False else: return True def LoadSettingsTable(self): if len(Globals.TextCatDirList) == 0: db = SqliteDatabase(Globals.TextCatFileName) if not db.OpenConnection(): return query = "select Stemmer, DirList, CategoryList from " + Constants.TextCatSettingsTable rows = db.FetchAllRows(query) for row in rows: Globals.Stemmer = row[0] self.DirList = CommonFunctions.RemoveDoubleSlashes(row[1]) self.CategoryList = row[2] Globals.TextCatCategoryList = self.CategoryList.split(';') #Globals.TextCatDirList = self.DirList.split(';') self.choiceStemmers.SetStringSelection(Globals.Stemmer) self.txtPath.SetValue(self.DirList) #print Globals.TextCatCategoryList #print Globals.TextCatDirList def UpdateSettings(self): if not os.path.isdir(self.txtPath.GetValue()): return Globals.TextCatCategoryList = [] Globals.TextCatDirList = [] #self.OneFolderList = [] Globals.TextCatDirList.append(self.txtPath.GetValue()) self.DirList = self.txtPath.GetValue() self.CategoryList = "" self.treeCategoryCheckView.UpdateCheckedList(Globals.TextCatCategoryList) #self.treeDirCheckView.UpdateCheckedList(Globals.TextCatDirList) #UpdateTextCatDirList #if self.OneFolderSelected: #if self.OneFolderSelected: #Globals.TextCatCategoryList.append("text/plain") #for adir in self.OneFolderList: # Globals.TextCatDirList.append(adir) """ if self.OneFolderPath: Globals.TextCatDirList.append(self.OneFolderPath) """ Globals.Stemmer = self.choiceStemmers.GetStringSelection() """ for adir in Globals.TextCatDirList: if not self.DirList == "": self.DirList += ";" self.DirList += adir """ for cat in Globals.TextCatCategoryList: if not self.CategoryList == "": self.CategoryList += ";" self.CategoryList += cat db = SqliteDatabase(Globals.TextCatFileName) if not db.OpenConnection(): return query = "delete from " + Constants.TextCatSettingsTable + ";" db.ExecuteNonQuery(query) query = "insert into " + Constants.TextCatSettingsTable + " (Stemmer, DirList, CategoryList) values (?,?,?)" db.ExecuteNonQuery(query, (Globals.Stemmer, self.DirList, self.CategoryList,)) db.CloseConnection() def OnBtnStopwordsButton(self, event): import frmStopwords formStopwords = frmStopwords.create(self, IsEmail=False, Stopwords=Globals.Stopwords) formStopwords.Show() event.Skip() def OnBtnPreprocessButton(self, event): self.UpdateSettings() if not self.CheckSettingsError(): return import dlgTextPreprocessingProgress textCat = dlgTextPreprocessingProgress.create(self, self.DirList) #scanMAC.StartScan(dir) #textCat.scanThread.Start() textCat.ShowModal() #textCat.scanThread.Start() self.Close() event.Skip() def OnBtnSelectFolderButton(self, event): #self.OneFolderList = [] dlg = wx.DirDialog(self) try: if dlg.ShowModal() == wx.ID_OK: #dirPath = dlg.GetPath() #self.OneFolderSelected = True #self.OneFolderPath = dir self.txtPath.SetValue(dlg.GetPath()) """ for dir in self.OneFolderList: print dir """ finally: dlg.Destroy() event.Skip()
class frmTextPreprocessing(wx.Frame): def _init_ctrls(self, prnt): # generated method, don't edit wx.Frame.__init__(self, id=wxID_FRMTEXTPREPROCESSING, name=u'frmTextPreprocessing', parent=prnt, pos=wx.Point(622, 176), size=wx.Size(795, 731), style=wx.DEFAULT_FRAME_STYLE, title=u'Text Preprocessing') self.SetClientSize(wx.Size(787, 700)) self.SetWindowVariant(wx.WINDOW_VARIANT_MINI) self.SetCursor(wx.STANDARD_CURSOR) self.Center(wx.BOTH) self.SetIcon(wx.Icon('./Images/FNSFIcon.ico', wx.BITMAP_TYPE_ICO)) self.SetBackgroundColour(wx.Colour(125, 152, 221)) self.SetAutoLayout(True) self.panTextPreProcessing = wx.Panel( id=wxID_FRMTEXTPREPROCESSINGPANTEXTPREPROCESSING, name=u'panTextPreProcessing', parent=self, pos=wx.Point(16, 16), size=wx.Size(756, 628), style=wx.TAB_TRAVERSAL) self.panTextPreProcessing.SetBackgroundColour(wx.Colour(225, 236, 255)) self.panTextPreProcessing.SetAutoLayout(False) self.panTextPreProcessing.SetConstraints( LayoutAnchors(self.panTextPreProcessing, True, True, True, True)) self.panTextPreProcessing.SetFont( wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.btnClose = wx.Button(id=wxID_FRMTEXTPREPROCESSINGBTNCLOSE, label='&Cancel', name='btnClose', parent=self, pos=wx.Point(545, 660), size=wx.Size(96, 23), style=0) self.btnClose.SetFont( wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, 'Arial')) self.btnClose.SetConstraints( LayoutAnchors(self.btnClose, False, False, True, True)) self.btnClose.Bind(wx.EVT_BUTTON, self.OnBtnCloseButton, id=wxID_FRMTEXTPREPROCESSINGBTNCLOSE) self.btnSave = wx.Button(id=wxID_FRMTEXTPREPROCESSINGBTNSAVE, label='&Save And Close', name='btnSave', parent=self, pos=wx.Point(653, 662), size=wx.Size(120, 23), style=0) self.btnSave.SetFont( wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, 'Arial')) self.btnSave.SetConstraints( LayoutAnchors(self.btnSave, False, False, True, True)) self.btnSave.Bind(wx.EVT_BUTTON, self.OnBtnSaveButton, id=wxID_FRMTEXTPREPROCESSINGBTNSAVE) self.btnStopwords = wx.Button(id=wxID_FRMTEXTPREPROCESSINGBTNSTOPWORDS, label=u'Stopwords List...', name=u'btnStopwords', parent=self.panTextPreProcessing, pos=wx.Point(168, 48), size=wx.Size(120, 23), style=0) self.btnStopwords.Bind(wx.EVT_BUTTON, self.OnBtnStopwordsButton, id=wxID_FRMTEXTPREPROCESSINGBTNSTOPWORDS) self.choiceStemmers = wx.Choice( choices=[u'Porter Stemmer'], id=wxID_FRMTEXTPREPROCESSINGCHOICESTEMMERS, name=u'choiceStemmers', parent=self.panTextPreProcessing, pos=wx.Point(168, 80), size=wx.Size(120, 21), style=0) self.choiceStemmers.SetStringSelection(u'None') self.choiceStemmers.SetHelpText(u'') self.choiceStemmers.SetSelection(0) self.btnPreprocess = wx.Button( id=wxID_FRMTEXTPREPROCESSINGBTNPREPROCESS, label=u'Start Indexing', name=u'btnPreprocess', parent=self.panTextPreProcessing, pos=wx.Point(48, 591), size=wx.Size(128, 23), style=0) self.btnPreprocess.SetConstraints( LayoutAnchors(self.btnPreprocess, True, False, False, True)) self.btnPreprocess.Bind(wx.EVT_BUTTON, self.OnBtnPreprocessButton, id=wxID_FRMTEXTPREPROCESSINGBTNPREPROCESS) self.staticText3 = wx.StaticText( id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT3, label=u'3.', name='staticText3', parent=self.panTextPreProcessing, pos=wx.Point(16, 116), size=wx.Size(15, 19), style=0) self.staticText3.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText1 = wx.StaticText( id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT1, label=u'Get Stopwords List:', name='staticText1', parent=self.panTextPreProcessing, pos=wx.Point(48, 56), size=wx.Size(94, 13), style=0) self.staticText4 = wx.StaticText( id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT4, label=u'Text Preprocessing Steps:', name='staticText4', parent=self.panTextPreProcessing, pos=wx.Point(16, 16), size=wx.Size(213, 19), style=0) self.staticText4.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText5 = wx.StaticText( id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT5, label=u'Select a Stemmer:', name='staticText5', parent=self.panTextPreProcessing, pos=wx.Point(48, 88), size=wx.Size(87, 13), style=0) self.staticText6 = wx.StaticText( id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT6, label=u'1.', name='staticText6', parent=self.panTextPreProcessing, pos=wx.Point(16, 52), size=wx.Size(15, 19), style=0) self.staticText6.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText7 = wx.StaticText( id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT7, label=u'Select Folders and File Types to Index:', name='staticText7', parent=self.panTextPreProcessing, pos=wx.Point(48, 120), size=wx.Size(190, 13), style=0) self.staticText8 = wx.StaticText( id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT8, label=u'4.', name='staticText8', parent=self.panTextPreProcessing, pos=wx.Point(16, 596), size=wx.Size(15, 19), style=0) self.staticText8.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.staticText8.SetConstraints( LayoutAnchors(self.staticText8, True, False, False, True)) self.staticText9 = wx.StaticText( id=wxID_FRMTEXTPREPROCESSINGSTATICTEXT9, label=u'2.', name='staticText9', parent=self.panTextPreProcessing, pos=wx.Point(16, 84), size=wx.Size(15, 19), style=0) self.staticText9.SetFont( wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Tahoma')) self.splitterWindow1 = wx.SplitterWindow( id=wxID_FRMTEXTPREPROCESSINGSPLITTERWINDOW1, name='splitterWindow1', parent=self.panTextPreProcessing, pos=wx.Point(16, 144), size=wx.Size(720, 432), style=wx.SP_3D) self.splitterWindow1.SetMinimumPaneSize(20) self.splitterWindow1.SetConstraints( LayoutAnchors(self.splitterWindow1, True, True, True, True)) self.splitterWindow1.SetBorderSize(2) self.panCategoryView = wx.Panel( id=wxID_FRMTEXTPREPROCESSINGPANCATEGORYVIEW, name=u'panCategoryView', parent=self.splitterWindow1, pos=wx.Point(368, 0), size=wx.Size(352, 432), style=wx.TAB_TRAVERSAL) self.panCategoryView.SetAutoLayout(True) self.panDirView = wx.Panel(id=wxID_FRMTEXTPREPROCESSINGPANDIRVIEW, name=u'panDirView', parent=self.splitterWindow1, pos=wx.Point(0, 0), size=wx.Size(364, 432), style=wx.TAB_TRAVERSAL) self.panDirView.SetAutoLayout(True) self.splitterWindow1.SplitVertically(self.panDirView, self.panCategoryView, 364) self.btnSelectFolder = wx.Button( id=wxID_FRMTEXTPREPROCESSINGBTNSELECTFOLDER, label=u'Select A Folder', name=u'btnSelectFolder', parent=self.panTextPreProcessing, pos=wx.Point(256, 112), size=wx.Size(112, 23), style=0) self.btnSelectFolder.Bind(wx.EVT_BUTTON, self.OnBtnSelectFolderButton, id=wxID_FRMTEXTPREPROCESSINGBTNSELECTFOLDER) def __init__(self, parent): self._init_ctrls(parent) self.DirList = "" self.CategoryList = "" self.LoadSettingsTable() self.InitDirCheckView() self.OneFolderList = [] self.OneFolderSelected = False self.OneFolderPath = "" if len(Globals.Stopwords) == 0: self.ReadStopwordsFromDB() def InitDirCheckView(self): self.treeDirCheckView = DirectoryCheckView( self.panDirView, id=wx.NewId(), pos=wx.Point(0, 0), size=wx.Size(352, 432), CheckedList=Globals.TextCatDirList) self.treeDirCheckView.SetConstraints( LayoutAnchors(self.treeDirCheckView, True, True, True, True)) self.treeCategoryCheckView = FileCategoryCheckView( self.panCategoryView, id=wx.NewId(), pos=wx.Point(8, 0), size=wx.Size(344, 432), CheckedList=Globals.TextCatCategoryList) self.treeCategoryCheckView.SetConstraints( LayoutAnchors(self.treeCategoryCheckView, True, True, True, True)) """ self.treeCtrl1 = wx.TreeCtrl(id=wxID_FRMTEXTPREPROCESSINGTREECTRL1, name='treeCtrl1', parent=self.panDirView, pos=wx.Point(0, 0), size=wx.Size(352, 432), style=wx.TR_HAS_BUTTONS) self.treeCtrl2 = wx.TreeCtrl(id=wxID_FRMTEXTPREPROCESSINGTREECTRL2, name='treeCtrl2', parent=self.panCategoryView, pos=wx.Point(8, 0), size=wx.Size(344, 432), style=wx.TR_HAS_BUTTONS) """ #self.keywordsRoot = self.treeDirCheckView.AddDirectoryTreeNodes() def OnBtnCloseButton(self, event): self.Destroy() def OnBtnSaveButton(self, event): self.UpdateSettings() if not self.CheckSettingsError(): return self.Close() def ReadStopwordsFromDB(self): db = SqliteDatabase(Globals.TextCatFileName) if not db.OpenConnection(): return query = "SELECT Stopword FROM " + Constants.StopwordsTable rows = db.FetchAllRows(query) #print len(rows) self.StopwordsValue = "" i = 0 for row in rows: #print row[0] Globals.Stopwords.add(row[0]) if i == 0: self.StopwordsValue += row[0] else: self.StopwordsValue += "; " + row[0] i += 1 #print Globals.KeyWords db.CloseConnection() def CheckSettingsError(self): #Globals.TextCatDirList = [] #self.treeDirCheckView.UpdateCheckedList(Globals.TextCatDirList) #Globals.TextCatCategoryList = [] #self.treeCategoryCheckView.UpdateCheckedList(Globals.TextCatCategoryList) errMsg = "" """ if len(Globals.Keywords) == 0: errMsg = "Please import keywords from a text file before start searching.\n File must have one keyword per line." """ if len(Globals.TextCatDirList) == 0: errMsg = "Please select directories to get text for categorization." elif len(Globals.TextCatCategoryList) == 0: errMsg = "Please select file types / categories to read for text categorization." if not errMsg == "": dlg = wx.MessageDialog(self, errMsg, 'Error', wx.OK | wx.ICON_ERROR) try: dlg.ShowModal() finally: dlg.Destroy() return False else: return True def LoadSettingsTable(self): if len(Globals.TextCatDirList) == 0: db = SqliteDatabase(Globals.TextCatFileName) if not db.OpenConnection(): return query = "select Stemmer, DirList, CategoryList from " + Constants.TextCatSettingsTable rows = db.FetchAllRows(query) for row in rows: Globals.Stemmer = row[0] self.DirList = CommonFunctions.RemoveDoubleSlashes(row[1]) self.CategoryList = row[2] Globals.TextCatCategoryList = self.CategoryList.split(';') Globals.TextCatDirList = self.DirList.split(';') self.choiceStemmers.SetStringSelection(Globals.Stemmer) #print Globals.TextCatCategoryList #print Globals.TextCatDirList def UpdateSettings(self): Globals.TextCatCategoryList = [] Globals.TextCatDirList = [] self.DirList = "" self.CategoryList = "" self.treeCategoryCheckView.UpdateCheckedList( Globals.TextCatCategoryList) self.treeDirCheckView.UpdateCheckedList(Globals.TextCatDirList) #UpdateTextCatDirList #if self.OneFolderSelected: if self.OneFolderSelected: for adir in self.OneFolderList: self.DirList += adir Globals.TextCatDirList.append(adir) """ if self.OneFolderPath: Globals.TextCatDirList.append(self.OneFolderPath) """ Globals.Stemmer = self.choiceStemmers.GetStringSelection() for adir in Globals.TextCatDirList: if not self.DirList == "": self.DirList += ";" self.DirList += adir for cat in Globals.TextCatCategoryList: if not self.CategoryList == "": self.CategoryList += ";" self.CategoryList += cat db = SqliteDatabase(Globals.TextCatFileName) if not db.OpenConnection(): return query = "delete from " + Constants.TextCatSettingsTable + ";" db.ExecuteNonQuery(query) query = "insert into " + Constants.TextCatSettingsTable + " (Stemmer, DirList, CategoryList) values ( + " query += db.SqlSQuote(Globals.Stemmer) + "," + db.SqlSQuote( self.DirList) + "," query += db.SqlSQuote(self.CategoryList) + ")" db.ExecuteNonQuery(query) db.CloseConnection() def OnBtnStopwordsButton(self, event): import frmStopwords formStopwords = frmStopwords.create(self) formStopwords.Show() event.Skip() def OnBtnPreprocessButton(self, event): self.UpdateSettings() if not self.CheckSettingsError(): return import dlgTextPreprocessingProgress textCat = dlgTextPreprocessingProgress.create(self) #scanMAC.StartScan(dir) textCat.ShowModal() self.Close() event.Skip() def OnBtnSelectFolderButton(self, event): self.OneFolderList = [] dlg = wx.DirDialog(self) try: if dlg.ShowModal() == wx.ID_OK: dirPath = dlg.GetPath() self.OneFolderSelected = True #self.OneFolderPath = dir for root, dirs, files in os.walk(dirPath): for adir in dirs: self.OneFolderList.append(os.path.join(root, adir)) """ for dir in self.OneFolderList: print dir """ finally: dlg.Destroy() event.Skip()