mirror of https://github.com/NaN-tic/nanscan.git
Renamed some files to fit with naming conventions (capitalization).
Use new Koo API. OpenTemplateDialog not working yet but it could be Koo's fault so I just commit and I'll try to find the problem later. Added Deskew action too.
This commit is contained in:
parent
a4b8ccf707
commit
69e0e78d4e
|
@ -34,11 +34,11 @@ from NaNScaN.recognizer import *
|
|||
|
||||
|
||||
from TemplateStorageManager import *
|
||||
from opentemplatedialog import *
|
||||
from commands import *
|
||||
from OpenTemplateDialog import *
|
||||
from Commands import *
|
||||
|
||||
from modules.gui.login import LoginDialog
|
||||
import rpc
|
||||
from Koo.Dialogs.LoginDialog import LoginDialog
|
||||
from Koo import Rpc
|
||||
|
||||
class ToolWidget(QWidget):
|
||||
|
||||
|
@ -453,6 +453,12 @@ class MainWindow(QMainWindow):
|
|||
self.updateTitle()
|
||||
self.updateActions()
|
||||
|
||||
# Login defaults
|
||||
LoginDialog.defaultHost = 'localhost'
|
||||
LoginDialog.defaultPort = 8070
|
||||
LoginDialog.defaultProtocol = 'socket://'
|
||||
LoginDialog.defaultUserName = 'admin'
|
||||
|
||||
self.recognizer = Recognizer()
|
||||
self.connect( self.recognizer, SIGNAL('finished()'), self.recognized )
|
||||
|
||||
|
@ -464,7 +470,7 @@ class MainWindow(QMainWindow):
|
|||
self.uiTool.show()
|
||||
self.uiToolDock.setWidget( self.uiTool )
|
||||
|
||||
#rpc.session.login( 'http://admin:admin@127.0.0.1:8069', 'g1' )
|
||||
#Rpc.session.login( 'http://admin:admin@127.0.0.1:8069', 'g1' )
|
||||
def sceneMouseMoved(self, pos):
|
||||
self.updatePosition( pos )
|
||||
|
||||
|
@ -484,7 +490,7 @@ class MainWindow(QMainWindow):
|
|||
QMessageBox.information( self, title, _('No image opened. Please open an image to find a matching template.') )
|
||||
return
|
||||
|
||||
if not rpc.session.logged():
|
||||
if not Rpc.session.logged():
|
||||
if not self.login():
|
||||
return
|
||||
templates = TemplateStorageManager.loadAll()
|
||||
|
@ -565,14 +571,10 @@ class MainWindow(QMainWindow):
|
|||
self.uiView.scale( 0.8, 0.8 )
|
||||
|
||||
def login(self):
|
||||
LoginDialog.defaultHost = 'localhost'
|
||||
LoginDialog.defaultPort = 8070
|
||||
LoginDialog.defaultProtocol = 'socket://'
|
||||
LoginDialog.defaultUserName = 'admin'
|
||||
dialog = LoginDialog( self )
|
||||
if dialog.exec_() == QDialog.Rejected:
|
||||
return False
|
||||
if rpc.session.login( dialog.url, dialog.databaseName ) > 0:
|
||||
if Rpc.session.login( dialog.url, dialog.databaseName ) > 0:
|
||||
self.updateTitle()
|
||||
return True
|
||||
else:
|
||||
|
@ -592,7 +594,7 @@ class MainWindow(QMainWindow):
|
|||
|
||||
def saveTemplate(self):
|
||||
self.uiTool.store()
|
||||
if not rpc.session.logged():
|
||||
if not Rpc.session.logged():
|
||||
if not self.login():
|
||||
return False
|
||||
|
||||
|
@ -604,11 +606,11 @@ class MainWindow(QMainWindow):
|
|||
|
||||
|
||||
if self._template.id:
|
||||
rpc.session.call( '/object', 'execute', 'nan.template', 'write', [self._template.id], {'name': self._template.name } )
|
||||
ids = rpc.session.call( '/object', 'execute', 'nan.template.box', 'search', [('template_id','=',self._template.id)] )
|
||||
rpc.session.call( '/object', 'execute', 'nan.template.box', 'unlink', ids )
|
||||
Rpc.session.call( '/object', 'execute', 'nan.template', 'write', [self._template.id], {'name': self._template.name } )
|
||||
ids = Rpc.session.call( '/object', 'execute', 'nan.template.box', 'search', [('template_id','=',self._template.id)] )
|
||||
Rpc.session.call( '/object', 'execute', 'nan.template.box', 'unlink', ids )
|
||||
else:
|
||||
self._template.id = rpc.session.call( '/object', 'execute', 'nan.template', 'create', {'name': self._template.name } )
|
||||
self._template.id = Rpc.session.call( '/object', 'execute', 'nan.template', 'create', {'name': self._template.name } )
|
||||
for x in self._template.boxes:
|
||||
values = {
|
||||
'x': x.rect.x(),
|
||||
|
@ -626,7 +628,7 @@ class MainWindow(QMainWindow):
|
|||
'type': x.type,
|
||||
'filter': x.filter
|
||||
}
|
||||
rpc.session.call( '/object', 'execute', 'nan.template.box', 'create', values )
|
||||
Rpc.session.call( '/object', 'execute', 'nan.template.box', 'create', values )
|
||||
self.updateTitle()
|
||||
return True
|
||||
|
||||
|
@ -638,10 +640,11 @@ class MainWindow(QMainWindow):
|
|||
self.updateTitle()
|
||||
|
||||
def openTemplate(self):
|
||||
if not rpc.session.logged():
|
||||
if not Rpc.session.logged():
|
||||
if not self.login():
|
||||
return
|
||||
|
||||
print "DDDDD: ", Rpc.session
|
||||
dialog = OpenTemplateDialog(self)
|
||||
if dialog.exec_() == QDialog.Rejected:
|
||||
return
|
||||
|
@ -649,7 +652,7 @@ class MainWindow(QMainWindow):
|
|||
self._template = Template( model.value('name') )
|
||||
self._template.id = model.id
|
||||
|
||||
fields = rpc.session.execute('/object', 'execute', 'nan.template.box', 'fields_get')
|
||||
fields = Rpc.session.execute('/object', 'execute', 'nan.template.box', 'fields_get')
|
||||
model.value('boxes').addFields( fields )
|
||||
for x in model.value('boxes'):
|
||||
box = TemplateBox()
|
||||
|
@ -669,8 +672,8 @@ class MainWindow(QMainWindow):
|
|||
def updateTitle(self):
|
||||
self.setWindowTitle( "Planta - [%s]" % self._template.name )
|
||||
|
||||
if rpc.session.logged():
|
||||
server = '%s [%s]' % (rpc.session.url, rpc.session.databaseName)
|
||||
if Rpc.session.logged():
|
||||
server = '%s [%s]' % (Rpc.session.url, Rpc.session.databaseName)
|
||||
else:
|
||||
shortcut = unicode( self.actionLogin.shortcut().toString() )
|
||||
if shortcut:
|
|
@ -28,9 +28,9 @@
|
|||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
from PyQt4.uic import *
|
||||
import rpc
|
||||
from widget.model.group import *
|
||||
from widget.model.treemodel import *
|
||||
from Koo import Rpc
|
||||
from Koo.Model.Group import ModelRecordGroup
|
||||
from Koo.Model.KooModel import KooModel
|
||||
|
||||
class OpenTemplateDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
|
@ -38,14 +38,16 @@ class OpenTemplateDialog(QDialog):
|
|||
loadUi( 'opentemplate.ui', self )
|
||||
|
||||
visible = ['name', 'boxes']
|
||||
self.fields = rpc.session.execute('/object', 'execute', 'nan.template', 'fields_get', visible)
|
||||
ids = rpc.session.execute('/object', 'execute', 'nan.template', 'search', [])
|
||||
print Rpc.session.url
|
||||
print 'open: ', Rpc.session
|
||||
self.fields = Rpc.session.execute('/object', 'execute', 'nan.template', 'fields_get', visible)
|
||||
ids = Rpc.session.execute('/object', 'execute', 'nan.template', 'search', [])
|
||||
self.group = ModelRecordGroup( 'nan.template', self.fields, ids )
|
||||
self.treeModel = TreeModel( self )
|
||||
self.treeModel = KooModel( self )
|
||||
self.treeModel.setModelGroup( self.group )
|
||||
self.treeModel.setFields( self.fields )
|
||||
self.treeModel.setShowBackgroundColor( False )
|
||||
self.treeModel.setMode( TreeModel.ListMode )
|
||||
self.treeModel.setMode( KooModel.ListMode )
|
||||
self.treeModel.setFieldsOrder( ['name', 'boxes'] )
|
||||
|
||||
self.treeView.setModel( self.treeModel )
|
|
@ -26,18 +26,18 @@
|
|||
##############################################################################
|
||||
|
||||
from NaNScaN.template import *
|
||||
import rpc
|
||||
from widget.model.group import *
|
||||
from Koo import Rpc
|
||||
from Koo.Model.Group import *
|
||||
|
||||
class TemplateStorageManager:
|
||||
@staticmethod
|
||||
def save(template):
|
||||
if template.id:
|
||||
rpc.session.call( '/object', 'execute', 'nan.template', 'write', [template.id], {'name': template.name } )
|
||||
ids = rpc.session.call( '/object', 'execute', 'nan.template.box', 'search', [('template_id','=',template.id)] )
|
||||
rpc.session.call( '/object', 'execute', 'nan.template.box', 'unlink', ids )
|
||||
Rpc.session.call( '/object', 'execute', 'nan.template', 'write', [template.id], {'name': template.name } )
|
||||
ids = Rpc.session.call( '/object', 'execute', 'nan.template.box', 'search', [('template_id','=',template.id)] )
|
||||
Rpc.session.call( '/object', 'execute', 'nan.template.box', 'unlink', ids )
|
||||
else:
|
||||
template.id = rpc.session.call( '/object', 'execute', 'nan.template', 'create', {'name': template.name } )
|
||||
template.id = Rpc.session.call( '/object', 'execute', 'nan.template', 'create', {'name': template.name } )
|
||||
for x in template.boxes:
|
||||
values = {
|
||||
'x': x.rect.x(),
|
||||
|
@ -55,12 +55,12 @@ class TemplateStorageManager:
|
|||
'type': x.type,
|
||||
'filter': x.filter
|
||||
}
|
||||
rpc.session.call( '/object', 'execute', 'nan.template.box', 'create', values )
|
||||
Rpc.session.call( '/object', 'execute', 'nan.template.box', 'create', values )
|
||||
|
||||
@staticmethod
|
||||
def load(id):
|
||||
|
||||
fields = rpc.session.execute('/object', 'execute', 'nan.template.box', 'fields_get')
|
||||
fields = Rpc.session.execute('/object', 'execute', 'nan.template.box', 'fields_get')
|
||||
|
||||
model.value('boxes').addFields( fields )
|
||||
for x in model.value('boxes'):
|
||||
|
@ -78,11 +78,11 @@ class TemplateStorageManager:
|
|||
@staticmethod
|
||||
def loadAll():
|
||||
fields = ['name', 'boxes']
|
||||
templateFields = rpc.session.execute('/object', 'execute', 'nan.template', 'fields_get', fields)
|
||||
templateFields = Rpc.session.execute('/object', 'execute', 'nan.template', 'fields_get', fields)
|
||||
fields = ['x', 'y', 'width', 'height', 'feature_x', 'feature_y', 'feature_width',
|
||||
'feature_height', 'name', 'text', 'recognizer', 'type', 'filter' ]
|
||||
boxFields = rpc.session.execute('/object', 'execute', 'nan.template.box', 'fields_get', fields)
|
||||
ids = rpc.session.execute('/object', 'execute', 'nan.template', 'search', [])
|
||||
boxFields = Rpc.session.execute('/object', 'execute', 'nan.template.box', 'fields_get', fields)
|
||||
ids = Rpc.session.execute('/object', 'execute', 'nan.template', 'search', [])
|
||||
group = ModelRecordGroup( 'nan.template', templateFields, ids )
|
||||
templates = []
|
||||
for record in group:
|
||||
|
|
|
@ -31,13 +31,13 @@ import os
|
|||
import sys
|
||||
import glob
|
||||
import base64
|
||||
import rpc
|
||||
from Koo import Rpc
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print 'loader.py database directory'
|
||||
sys.exit(1)
|
||||
|
||||
rpc.session.login( 'http://admin:admin@127.0.0.1:8069', sys.argv[1] )
|
||||
Rpc.session.login( 'http://admin:admin@127.0.0.1:8069', sys.argv[1] )
|
||||
|
||||
files = glob.glob(sys.argv[2] + "/*.png")
|
||||
print "F: ", files
|
||||
|
@ -46,5 +46,5 @@ for x in files:
|
|||
fields = {}
|
||||
fields['name'] = os.path.split(x)[1]
|
||||
fields['datas'] = base64.encodestring(open(x, 'rb').read())
|
||||
rpc.session.execute('/object', 'execute', 'nan.document', 'create', fields )
|
||||
|
||||
Rpc.session.execute('/object', 'execute', 'nan.document', 'create', fields )
|
||||
|
||||
|
|
|
@ -149,6 +149,7 @@
|
|||
</property>
|
||||
<addaction name="actionFindMatchingTemplateByOffset" />
|
||||
<addaction name="actionFindMatchingTemplateByText" />
|
||||
<addaction name="actionDeskew" />
|
||||
</widget>
|
||||
<addaction name="menuFile" />
|
||||
<addaction name="menuEdit" />
|
||||
|
@ -291,6 +292,11 @@
|
|||
<string>Find Matching Template by &Text</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionDeskew" >
|
||||
<property name="text" >
|
||||
<string>Deskew</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
@ -28,26 +28,27 @@
|
|||
##############################################################################
|
||||
|
||||
|
||||
from common import localization
|
||||
localization.initializeTranslations()
|
||||
from Koo.Common import Localization
|
||||
Localization.initializeTranslations()
|
||||
|
||||
# Load this after localization as these modules depend on it
|
||||
from common import notifier, common
|
||||
from Koo.Common import Notifier, Common
|
||||
|
||||
# Declare notifier handlers for the whole application
|
||||
notifier.errorHandler = common.error
|
||||
notifier.warningHandler = common.warning
|
||||
Notifier.errorHandler = Common.error
|
||||
Notifier.warningHandler = Common.warning
|
||||
Notifier.concurrencyErrorHandler = Common.concurrencyError
|
||||
|
||||
|
||||
from PyQt4.QtGui import *
|
||||
from PyQt4.QtCore import *
|
||||
import sys
|
||||
from mainwindow import *
|
||||
from MainWindow import *
|
||||
|
||||
|
||||
app = QApplication( sys.argv )
|
||||
|
||||
localization.initializeQtTranslations()
|
||||
Localization.initializeQtTranslations()
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
app.exec_()
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
# Gamera, KTiny and NaNScaN
|
||||
#export PYTHONPATH=/home/albert/python/lib/python:../../bin:../../..
|
||||
# NaNScaN
|
||||
export PYTHONPATH=..:../../ktiny/bin
|
||||
export PYTHONPATH=..:/home/albert/d/koo
|
||||
./planta.py $1
|
||||
|
|
Loading…
Reference in New Issue