Exemple #1
0
 def actionLoad(self):
     self.cbAutoScan.Value = str_to_bool(database.theConfig.get_param('scanner', 'autoScan','False',True))
     self.cbAutoFileName.Value = str_to_bool(database.theConfig.get_param('scanner', 'autoFileName','False',True))
     self.lbFilenamePrefix.Value = database.theConfig.get_param('scanner', 'autoFileNamePrefix','file',True)
     self.cbUseLastDir.Value = str_to_bool(database.theConfig.get_param('scanner', 'useLastDir','False',True))
     self.dpDefaultDirectory.SetPath(database.theConfig.get_param('scanner', 'defaultDir',os.path.join(os.path.expanduser('~'),'MALODOS','Images'),True))
     self.cbAutoClose.Value = str_to_bool(database.theConfig.get_param('scanner', 'autoClose','True',True))
     self.cbClearFields.Value = str_to_bool(database.theConfig.get_param('scanner', 'clearFields','False',True))
     if os.name == 'posix' :
         self.scanner = saneAccess.SaneAccess(self.GetHandle())
     else:
         self.scanner = twainAccess.TwainAccess(self.GetHandle())
     currentScanner = database.theConfig.get_current_scanner()
     self.stScanner.Label = currentScanner
 def actionLoad(self):
     for i in range(self.clOcrProgs.Count) :
         opt = 'use' + self.clOcrProgs.GetItems()[i]
         chk = database.theConfig.get_param('OCR', opt,'0').lower()
         chk = str_to_bool(chk)
         self.clOcrProgs.Check(i,chk)
     lngs = database.theConfig.get_param('OCR', 'languages','').split(',')
     for i in range(self.clSpellProgs.Count):
         l = self.clSpellProgs.GetString(i)
         try:
             lngs.index(l)
             self.clSpellProgs.Check(i)
         except:
             self.clSpellProgs.Check(i,False)
     self.cbAutoOCR.Value = str_to_bool( database.theConfig.get_param('OCR', 'autoStart','1') )
Exemple #3
0
 def defaultNameDir(self):
     defDir = database.theConfig.get_param('scanner', 'defaultDir',os.path.join(os.path.expanduser('~'),'MALODOS','Images'),False)
     if str_to_bool(database.theConfig.get_param('scanner', 'useLastDir','False',True)) : 
         defNameDir = database.theConfig.get_param('scanner', 'lastDir',defDir,False)
     else:
         defNameDir = defDir
     return defNameDir
Exemple #4
0
	def actionPerformScan(self,event):
#		try:
#			auto_cont=str_to_bool(self.currentOptions['manual_multipage'])
#		except:
#			auto_cont=False
#		try:
#			self.scanner.useOptions(self.currentOptions)
#		except:
#			if not  utilities.ask(_('Unable to set the scanner options. Do you want to proceed to scan anyway ?')) : return
		
#		cont=True
		if event is not None and event.Id != 666 : data.theData.clear_all()
		data.theData.current_image=0
		self.do_scan()
#		while cont:
#			if auto_cont:
#				if not  utilities.ask(_('Do you want to add new page(s) ?')) : cont=False
#			else:
#				cont=False
#		self.docWin.showCurrentImage()
		if self.recordPart.lbFileName.GetPath() != '' : return
		if not str_to_bool(database.theConfig.get_param('scanner', 'autoFileName','False',True)) : return
		defNameDir = self.defaultNameDir()
		idx=1
		def generated_file_name():
			fnamePrefix = database.theConfig.get_param('scanner', 'autoFileNamePrefix','file',True)
			fname = '%s%.4d.pdf' % (fnamePrefix,idx)
			return os.path.join(defNameDir,fname)
		while os.path.exists(generated_file_name()) : idx+=1
		self.recordPart.lbFileName.SetPath(generated_file_name())
Exemple #5
0
 def actionDocSelect(self,event):
     sel = self.docList.GetSelections()
     if len(sel)!=1 : return
     sel=sel[0]
     if sel is None : return
     row = self.docList.GetClientData(sel)
     
     docID = row[database.theBase.IDX_ROWID]
     filename = row[database.theBase.IDX_FILENAME]
     title = row[database.theBase.IDX_TITLE]
     description = row[database.theBase.IDX_DESCRIPTION]
     documentDate = row[database.theBase.IDX_DOCUMENT_DATE]
     tags = row[database.theBase.IDX_TAGS]
     folderID_list = database.theBase.folders_list_for(docID)
     md5_cs  = row[database.db.Base.IDX_CHECKSUM]
     if not os.path.exists(filename):
         filename = self.tryToFind(os.path.splitext(filename)[1],md5_cs)
     if filename is None : filename=''
     doOCR = str_to_bool(theConfig.get_param('OCR', 'autoStart','1'))
     self.baseWin.recordPart.SetFields(filename, title, description, documentDate,tags,doOCR,folderID_list)
     try:
         data.theData.load_file(filename)
         self.baseWin.docWin.resetView()
         self.baseWin.docWin.showCurrentImage()
         self.baseWin.SetModeUpdate(docID)
     except:
         data.theData.clear_all()
 def update_record(self,docID,redoOCR=None):
     filename = self.lbFileName.GetPath()
     title = self.lbTitle.Value
     tags = self.lbTags.Value
     description = self.lbDescription.Value
     documentDate = self.lbDate.Value
     documentDate=datetime.date(year=documentDate.GetYear(),month=documentDate.GetMonth()+1,day=documentDate.GetDay())
     folderIDList = self.vFold.getSelectedList()
     fullText=None
     if redoOCR is None : redoOCR = self.cbOCR.GetValue()
     if redoOCR:
         try:
             if theData.current_image == filename :
                 fullText = theData.get_content()
             else:  
                 imData = data.imageData.imageData()
                 imData.load_file(filename)
                 doOCR = str_to_bool( database.theConfig.get_param('OCR', 'autoStart','1') )
                 if doOCR :
                     fullText = imData.get_content()
                 else:
                     fullText = None
                 if fullText is None or len(fullText)==0 : fullText = {'NOTHING FOUND':1}
         except:
             pass
     # add the document to the database
     #keywordsGroups = database.theBase.get_keywordsGroups_from(title, description, filename , tags, fullText)
     if not database.theBase.update_doc(docID, title, description, documentDate, filename,tags,fullText,folderIDList):
         wx.MessageBox(_('Unable to update the database'))
         return False
     return True
Exemple #7
0
	def onNewScannerData(self):
		data.theData.current_image=len(data.theData.pil_images)-1
		self.docWin.showCurrentImage()
		try:
			auto_cont=str_to_bool(self.currentOptions['manual_multipage'])
		except:
			auto_cont=False
		if auto_cont and utilities.ask(_('Do you want to add new page(s) ?')) : self.do_scan()
Exemple #8
0
 def actionDocSelect(self,event):
     sel = self.docList.GetSelection()
     if sel :
         fname = self.docList.GetPyData(sel)
         if fname[0]=='*' :
             fname=fname[1:]
         else:
             return
     else:
         return
     #fname = self.docList.GetClientData(sel)
     #if not fname : return
     self.baseWin.recordPart.clear_all()
     self.baseWin.recordPart.SetFields(filename = fname,doOCR=str_to_bool( database.theConfig.get_param('OCR', 'autoStart','1') ),selectedList=[],title='',description='',tags='')
     try:
         data.theData.load_file(fname)
         self.baseWin.docWin.resetView()
         self.baseWin.docWin.showCurrentImage()
         self.baseWin.SetModeAdd()
     except:
         data.theData.clear_all()
    def __init__(self,parent, title,filename=None):
        '''
        Constructor
        '''
        wx.Dialog.__init__(self, parent, -1, _('Adding a documents to the database'),style=wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.RESIZE_BORDER | 0 | 0 | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX)
        self.panel = wx.Panel(self, -1)
        if not filename:
            dlg = wx.FileDialog(self,style=wx.FD_OPEN,message=_('filename of the document to add'))
            
            if dlg.ShowModal():
                filename = os.path.join(dlg.Directory,dlg.Filename)
        if not filename : return
        try:
            data.theData.load_file(filename, do_clear=False)
        except:
            pass
        
        self.totSizer = wx.BoxSizer(wx.VERTICAL)
        self.horSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.docWin = docWindow.docWindow(self.panel,-1)
        self.recordPart = RecordWidget.RecordWidget(self.panel,filename)
        self.recordPart.cbOCR.SetValue(str_to_bool(theConfig.get_param('OCR', 'autoStart','1')))
        self.btSizer = wx.BoxSizer(wx.HORIZONTAL)
        
        self.btOk = wx.Button(self.panel,-1,_('Ok'))
        self.btCancel = wx.Button(self.panel,-1,_('Cancel'))

        self.btSizer.Add(self.btOk,1,wx.EXPAND)
        self.btSizer.Add(self.btCancel,1,wx.EXPAND)
        
        self.horSizer.Add(self.recordPart,1,wx.EXPAND)
        self.horSizer.Add(self.docWin,1,wx.EXPAND)
        self.totSizer.Add(self.horSizer,1,wx.EXPAND)
        self.totSizer.Add(self.btSizer,0,wx.EXPAND)

        self.panel.SetSizerAndFit(self.totSizer)
        self.totSizer.Fit(self)
        
        self.Bind(wx.EVT_BUTTON, self.actionDoAdd, self.btOk)
        self.Bind(wx.EVT_BUTTON, self.actionClose, self.btCancel)
Exemple #10
0
	def __init__(self, parent, title,clear_data=True):
		wx.Dialog.__init__(self, parent, -1, _('Scanning a new document'), wx.DefaultPosition, (372, 700), style=wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.RESIZE_BORDER  | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX)
		self.panel = wx.Panel(self, -1)

		self.totalWin = wx.BoxSizer(wx.VERTICAL)
		self.upPart = wx.GridBagSizer(3,2)

		self.stSource = wx.StaticText(self.panel,-1,_("Source :"))
		#self.btSource = wx.Button(self.panel, -1, _('Select Scanner'))

		self.buttonPart = wx.BoxSizer(wx.HORIZONTAL)

		self.btScan = wx.BitmapButton(self.panel,-1, wx.Bitmap(Resources.get_icon_filename('PERFORM_SCAN')))
		self.btScan.SetToolTipString(_('Scan'))
		self.buttonPart.Add(self.btScan ,0)

		self.btAddScan = wx.BitmapButton(self.panel, 666, wx.Bitmap(Resources.get_icon_filename('ADD_PERFORM_SCAN')))
		self.btAddScan.SetToolTipString(_('Add scan'))
		self.buttonPart.Add(self.btAddScan ,0)

		self.btSave = wx.BitmapButton(self.panel, -1, wx.Bitmap(Resources.get_icon_filename('RECORD_SCANNED')))
		self.btSave.SetToolTipString(_('Record'))
		self.buttonPart.Add(self.btSave ,0)

		self.btSource = wx.BitmapButton(self.panel, -1, wx.Bitmap(Resources.get_icon_filename('CHOOSE_SCANNER')))
		self.btSource.SetToolTipString(_('Select Scanner'))
		self.buttonPart.Add(self.btSource ,0)

		self.btOptions = wx.BitmapButton(self.panel,-1,wx.Bitmap(Resources.get_icon_filename('SCANNER_PREFERENCES')))
		self.btOptions.SetToolTipString(_('Options'))
		self.buttonPart.Add(self.btOptions ,0)


		#self.btScan = wx.Button(self.panel, -1, _('Scan'))
		#self.cbMultiplePage = wx.CheckBox(self.panel, -1, _('Manual MultiPage'))
		#self.btSave = wx.Button(self.panel, -1, _('Record'))
		#self.btOptions = wx.Button(self.panel,-1,_('Options'))
		
		self.docWin = docWindow.docWindow(self.panel,-1)
		self.recordPart = RecordWidget.RecordWidget(self.panel,file_style=wx.FLP_SAVE | wx.FLP_OVERWRITE_PROMPT | wx.FLP_USE_TEXTCTRL)
		self.recordPart.cbOCR.SetValue(str_to_bool(theConfig.get_param('OCR', 'autoStart','1')))

		self.upPart.Add(wx.StaticText(self.panel,-1,_("Source :")),(0,0),flag=wx.ALL | wx.ALIGN_CENTRE_VERTICAL)
		self.upPart.Add(self.stSource,(0,1),flag=wx.ALL| wx.ALIGN_CENTRE_VERTICAL)
		#self.upPart.Add(self.btSource,0,wx.EXPAND | wx.CENTER)
		#self.upPart.Add(self.btScan,0,wx.EXPAND | wx.CENTER)
		#self.upPart.Add(self.btSave,0,wx.EXPAND | wx.CENTER)
		#self.upPart.Add(self.btOptions,0,wx.EXPAND | wx.CENTER)
		#self.upPart.Add(self.cbMultiplePage,0,wx.EXPAND | wx.CENTER)
		self.upPart.Add(self.buttonPart,(1,0),span=(1,2),flag=wx.ALIGN_TOP|wx.EXPAND)
	
		self.totalWin.Add(self.upPart,0,wx.ALIGN_TOP|wx.EXPAND)
		self.totalWin.Add(self.recordPart,0,wx.EXPAND)
		self.totalWin.Add(self.docWin,1,wx.ALIGN_BOTTOM|wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL)
		# BINDING EVENTS
		self.Bind(wx.EVT_BUTTON, self.actionChooseSource, self.btSource)
		self.Bind(wx.EVT_BUTTON, self.actionPerformScan, self.btScan)
		self.Bind(wx.EVT_BUTTON, self.actionPerformScan, self.btAddScan)
		self.Bind(wx.EVT_BUTTON, self.actionSaveRecord, self.btSave)
		self.Bind(wx.EVT_BUTTON, self.actionOpenOptions, self.btOptions)
		self.Bind(wx.EVT_CLOSE,self.onClose)
		# OTHER INITIALISATIIONS
		if os.name == 'posix' :
			self.scanner = saneAccess.SaneAccess(self.GetHandle(),self.onNewScannerData)
		else:
			self.scanner = twainAccess.TwainAccess(self.GetHandle(),self.onNewScannerData)
		self.panel.SetSizerAndFit(self.totalWin)
		self.SetSize(self.GetSize())
		self.stSource.Label = self.scanner.chooseSource(database.theConfig.get_current_scanner())
		self.SetSizeWH(550,800)
		
		self.currentOptions=dict()
		op_ini  =  database.theConfig.get_all_params_in('scanner_options')
		op_scan = self.scanner.get_options()
		for op in op_scan :
			if op.name in op_ini.keys() :
				self.currentOptions[op.name] = str(op_ini[op.name])
			else:
				self.currentOptions[op.name] = op.value
		for name,val in op_ini.items() :
			if not name in self.currentOptions.keys() : self.currentOptions[name]=val
		#self.recordPart.lbFileName.SetPath(self.defaultNameDir())
		#data.theData.clear_all()
		if str_to_bool(database.theConfig.get_param('scanner', 'autoScan','False',True)) :
#			event.Id = 0 if clear_data else 666 
			self.actionPerformScan(None)
Exemple #11
0
    def save_file(self,filename,title=None,description=None,keywords=None,allowEncryption=True):
        "save the image data to a file"
        if len(self.pil_images)<1 : return False
        (__,ext) = os.path.splitext(filename)
        
        if allowEncryption and str_to_bool(theConfig.get_param('encryption', 'encryptData','False',True)):
            try:
                fle = tempfile.mkstemp(ext)
                if not self.save_file(fle[1], title, description, keywords,allowEncryption=False) : return False
                #salt = bcrypt.gensalt()
                #salted_key = bcrypt.hashpw(data.get_current_password(),salt)
                with open(fle[1],'rb') as ff: txt = ff.read()
                algorithms.stringFunctions.save_encrypted_data(txt, filename)
                return True
            except Exception as E:
                logging.exception('Encryping file ' + filename + ':' + str(E))
            finally:
                os.close(fle[0])
                os.remove(fle[1])
        self.is_modified=False
        
        ext=ext.lower()
        if ext in ['.jpg'  , '.jpeg'  ,  '.png',  '.bmp' , '.gif']:
            if len(self.pil_images)>1 :
                gui.utilities.show_message(_('Unable to save multi-page document with the asked extension'))
                return False
            try:
                self.pil_images[0].save(filename)
                return True
            except Exception as E:
                logging.exception('Saving file ' + filename + ':' + str(E))
                return False
        if ext in ['.tif' , '.tiff'] :
            if len(self.pil_images)>1 :
#                try:
#                    import tifffile
#                    tifffile.imsave(filename, self.pil_images[0])
#                try:
#                    import pytiff
#                    tiff_writer = pytiff.TiffWriter(filename)
#                    for i in range(len(self.pil_images)):
#                        img = pytiff.MemoryImage(self.pil_images[i])
#                        tiff_writer.append(img)
#                    return True
                try:
                    import FreeImagePy.FreeImagePy as FIPY
                    fip = FIPY.freeimage()
                    imgList=[]
                    for i in range(len(self.pil_images)):
                        fle = tempfile.mkstemp('.png')
                        imgList.append(fle[1])
                        self.pil_images[i].save(fle[1])
                        os.close(fle[0])
                    fip.convertToMultiPage((x for x in imgList), filename,deleteOld=True)
                    return True
                    
                except Exception as E:
                    print str(E)
                    gui.utilities.show_message(_('Unable to save multipage tiff document for the time being'))
                    return False
            try:
                self.pil_images[0].save(filename)
                return True
            except Exception as E:
                logging.exception('Saving file ' + filename + ':' + str(E))
                return False
        if ext!='.pdf' :
            gui.utilities.show_message(_('Unknown file extension'))
            return False
        wD=0
        hD=0
        for i in range(len(self.pil_images)):
            (ww,hh) = self.pil_images[i].size
            w=min(ww,hh)
            h=max(ww,hh)
            wD=max(wD,w)
            hD=max(hD,h)
        try:
            doc = FPDF(unit='pt',format=(wD,hD))
            doc.SetAuthor('Generated by MALODOS')
            if title is not None : doc.SetTitle(title.encode('utf-8'))
            if description is not None : doc.SetSubject(description.encode('utf-8'))
            if keywords is not None : doc.SetKeywords(keywords.replace(',',' ').encode('utf-8'))
            list_files=[]
            for i in range(len(self.pil_images)):
                fle_tmp_tuple = tempfile.mkstemp(suffix='.png')
                fle_tmp = fle_tmp_tuple[1];
                os.close(fle_tmp_tuple[0]);
                fle_tmp=os.path.abspath(os.path.normpath(fle_tmp))
                list_files.append(fle_tmp)
                IIm=self.pil_images[i]
                (w,h) = IIm.size
                if w<h :
                    orient='P'
                else:
                    orient='L'
                IIm.save(fle_tmp)
                doc.AddPage(orient)
                doc.Image(fle_tmp, 0, 0 )
            doc.Output(filename)
            for f in list_files : os.remove(f)
            return True
        except Exception,E:
            logging.debug('Saving file ' + str(E))
            return False
Exemple #12
0
 def actionLoad(self):
     self.cbEncryptData.Value = str_to_bool(database.theConfig.get_param('encryption', 'encryptData','False',True))
     self.cbEncryptDatabase.Value = str_to_bool(database.theConfig.get_param('encryption', 'encryptDatabase','False',True))