コード例 #1
0
ファイル: survey.py プロジェクト: julien-noblet/malodos
 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()
コード例 #2
0
    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)
コード例 #3
0
ファイル: scanWindow.py プロジェクト: julien-noblet/malodos
	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)
コード例 #4
0
ファイル: imageData.py プロジェクト: julien-noblet/malodos
    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