pixelocr/pixelocr/gui/__init__.py

76 lines
2.2 KiB
Python

# Copyright (C) 2014 Andrey Golovizin
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import signal
from threading import Thread
from argparse import ArgumentParser
from pkg_resources import iter_entry_points
import sip
sip.setapi('QString', 2)
from PyQt4 import QtCore
QtCore.signal = QtCore.pyqtSignal
QtCore.slot = QtCore.pyqtSlot
from PyQt4.QtGui import (
QApplication,
)
from .window import MainWindow
from .ocrengine import OCREngine
parser = ArgumentParser(description='PixelOCR')
parser.add_argument('--skip', metavar='N', type=int, default=0)
parser.add_argument('--limit', metavar='N', type=int, default=None)
parser.add_argument('--quit', action='store_true')
parser.add_argument('-f', '--output-format', type=str, default='text')
parser.add_argument('filename')
def load_entry_point(group, name):
try:
return next(iter_entry_points(group, name))
except StopIteration:
raise ValueError('Entry point {} in group {} not found'.format(name, group))
def main():
app = QApplication(sys.argv)
QApplication.setOrganizationName("PixelOCR");
QApplication.setApplicationName("PixelOCR");
args = parser.parse_args()
ocr = OCREngine(
args.filename,
skip=args.skip,
limit=args.limit,
quit=args.quit,
output_format=load_entry_point('pixelocr.formatting', args.output_format).load()(),
)
app.aboutToQuit.connect(ocr.save_glyphdb)
win = MainWindow(ocr)
win.glyphEntered.connect(ocr.give_help)
win.show()
ocr.start()
signal.signal(signal.SIGINT, signal.SIG_DFL)
sys.exit(app.exec_())