00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 import base64
00030 from Koo import Rpc
00031 from PyQt4.QtGui import *
00032 from PyQt4.QtCore import *
00033 from PyQt4.uic import *
00034 from Koo.Plugins import Plugins
00035
00036 try:
00037 from NanScan.Scanner import *
00038 from NanScan.ScanDialog import *
00039 isNanScanAvailable = True
00040 except:
00041 isNanScanAvailable = False
00042
00043
00044 if isNanScanAvailable:
00045 def scan(model, id, ids, context):
00046 saver = DocumentSaverFactory(context)
00047 dialog = ScanDialog()
00048 dialog.setImageSaverFactory( saver )
00049 dialog.exec_()
00050
00051 class DocumentSaverFactory(AbstractImageSaverFactory):
00052 def __init__(self, context):
00053 self.context = context
00054
00055 def create(self, parent):
00056 saver = DocumentSaver( parent )
00057 saver.context = self.context
00058 return saver
00059
00060 class DocumentSaver(AbstractImageSaver):
00061 def run(self):
00062 self.error = True
00063
00064 image = QBuffer()
00065 if not self.item.image.save( image, 'PNG' ):
00066 return
00067
00068 id = Rpc.session.execute('/object', 'execute', 'nan.document', 'create', {
00069 'name': unicode( self.item.name ),
00070 'datas': base64.encodestring( str(image.buffer()) ),
00071 'filename': _('document.png'),
00072 }, self.context )
00073 if not id:
00074 return
00075
00076 self.error = False
00077
00078 Plugins.register( 'scanner', 'nan.document', _('Scan Documents'), scan )