def on_finished(self,event): sel = self.page_chooser.rbContent.GetSelection() sel = self.page_chooser.choice_list.keys()[sel] what = self.page_chooser.rbDocToSave.GetSelection() what = self.page_chooser.sel_list.keys()[what] if what==self.page_chooser.ALL_DOCUMENTS: cur = database.theBase.find_sql() if cur is None : rowL=[] else: rowL = [row for row in cur] elif what == self.page_chooser.SELECTED_DOCS: rowL = self.row_list elif what == self.page_chooser.FILTER_RESULT: rowL = self.doc_list elif what == self.page_chooser.BASKET_DOCS: rowL = self.GetParent().basket if sel == self.page_chooser.EXPORT_DATABASE: filename = self.page_database_export.fcFileChooser.GetPath() if os.path.splitext(filename)[1]=='': filename=filename+'.zip' if filename=='' : utilities.show_message(_("The filename can't be empty")) event.Veto() elif os.path.exists(filename): if utilities.ask(_('The filename already exists. Overwrite it ?')): os.remove(filename) database.theBase.export_database(filename, rowL) else: event.Veto() else: database.theBase.export_database(filename, rowL) elif sel==self.page_chooser.EXPORT_ARCHIVE: filename = self.page_archive_export.fcFileChooser.GetPath() if os.path.splitext(filename)[1]=='': filename=filename+'.zip' if filename=='' : utilities.show_message(_("The filename can't be empty")) event.Veto() elif os.path.exists(filename): if utilities.ask(_('The filename already exists. Overwrite it ?')): os.remove(filename) database.theBase.export_archive(filename, rowL) else: event.Veto() else: database.theBase.export_archive(filename, rowL) elif sel==self.page_chooser.IMPORT_ARCHIVE : filename = self.page_archive_import.fcFileChooser.GetPath() dirname = self.page_archive_import.dcDirChooser.GetPath() if filename=='' or dirname=='': utilities.show_message(_("The filename and dirname can't be empty")) event.Veto() else: database.theBase.import_archive(filename, dirname) dbname=os.path.join(dirname,'database.db') database.theConfig.set_database_name(dbname) database.theBase.use_base(dbname) database.theConfig.commit_config()
def action_del_subfolder(self,item): folderID = self.treeView.GetPyData(item) folderName = self.treeView.GetItemText(item) if utilities.ask(_('Are you sure that you want to delete the folder {0}'.format(folderName))): if database.theBase.folders_remove(folderID): self.fillDirectories() self.notify_selection() else: utilities.show_message(_('unable to remove the sub-folder {0}').format(folderName))
def action_ren_subfolder(self,item): folderID = self.treeView.GetPyData(item) folderName = self.treeView.GetItemText(item) name = utilities.ask_string(_('name :'),_('Give a sub-folder name'),folderName) if name=='' : return if utilities.ask(_('Are you sure that you want to rename folder "{iniName}" to "{newName}"'.format(iniName=folderName,newName=name))): if database.theBase.folders_rename(folderID,name): self.fillDirectories() self.notify_selection() else: utilities.show_message(_('unable to remove the subfolder {0}').format(folderName))
def action_drag_drop_end(self,event): if self.dragedItem == event.GetItem() : return oldItem = self.treeView.GetItemText(self.dragedItem) newItem = self.treeView.GetItemText(event.GetItem()) if not utilities.ask(_('Do you really want to move the folder {src} and all its content under the folder {dst} ?').format(src=oldItem,dst=newItem)) : return iniFolderID = self.treeView.GetPyData(self.dragedItem) dstFolderID = self.treeView.GetPyData(event.GetItem()) if not database.theBase.folders_change_parent(iniFolderID,dstFolderID): utilities.show_message(_('Unable to move the folder {src} under {dst}').format(src=oldItem,dst=newItem)) else: self.fillDirectories() self.notify_selection()
def action_save(self,event): data.theData.clear_all() for idx in self.docOrder: row = self.rowList[idx] data.theData.load_file(row[database.theBase.IDX_FILENAME], None, False) data.theData.rescale_all() fname = self.recordPart.lbFileName.GetPath() if fname == '' : wx.MessageBox(_('You must give a valid filename to record the document')) return direct = os.path.dirname(fname) if not os.path.exists(direct) : if utilities.ask(_('The directory {dname} does not exists. Should it be created ?'.format(dname=direct))) : try: os.makedirs(direct) except Exception as E: logging.exception('Unable to create directory '+direct + ':' + str(E)) #raise Exception('Unable to add the file to the disk') return else: #raise Exception('Unable to add the file to the disk') return try: #if not data.theData.save_file(fname,self.recordPart.lbTitle.Value,self.recordPart.lbDescription.Value,self.recordPart.lbTags.Value) : raise _('Unable to add the file to the disk') if not data.theData.save_file(fname,self.recordPart.lbTitle.Value,self.recordPart.lbDescription.Value,self.recordPart.lbTags.Value) : logging.exception('Unable to save '+fname + ':' + str(E)) return except Exception as E: logging.debug('Saving file ' + str(E)) wx.MessageBox(_('Unable to add the file to the disk')) return if not self.recordPart.do_save_record(): wx.MessageBox(_('Unable to add the file to the database')) return # test if one should remove / delete old documents if self.rbSuppressOlds.Selection == 1 : # just remove from the database database.theBase.delete_documents(self.rowList,database.theBase.ID_DEL_DB) elif self.rbSuppressOlds.Selection == 2 : # remove from the database and delete the files database.theBase.delete_documents(self.rowList,database.theBase.ID_DEL_DB_AND_FS,exclusion=[fname]) # close the dialog database.theConfig.set_param('scanner', 'lastDir',os.path.dirname(fname),True) database.theConfig.commit_config() self.Destroy()
def on_cancel(self,event): if not utilities.ask(_('Are you sure you want to cancel the document to go wizard ?')) : event.Veto()