# 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 . 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.QtCore import ( QThread, ) from PyQt4.QtGui import ( qApp, QApplication, ) from ..document import Document from .guiproxy import GUIProxy from .window import MainWindow 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)) class WorkerThread(QThread): def __init__(self, document, quit=False): super().__init__() self.document = document self._quit = quit def run(self): self.document.recognize() if self._quit: qApp.quit() def main(): app = QApplication(sys.argv) QApplication.setOrganizationName("PixelOCR"); QApplication.setApplicationName("PixelOCR"); args = parser.parse_args() gui_proxy = GUIProxy() document = Document( args.filename, ui=gui_proxy, skip=args.skip, limit=args.limit, output_format=load_entry_point('pixelocr.formatting', args.output_format).load()(), ) app.aboutToQuit.connect(document.save_glyphdb) worker_thread = WorkerThread(document, quit=args.quit) win = MainWindow(document) win.glyphEntered.connect(gui_proxy.give_help) win.show() worker_thread.start() signal.signal(signal.SIGINT, signal.SIG_DFL) sys.exit(app.exec_())