def recognizeDocument(self): pages = self.source_images_selector_widget.getAllPages() dialog = QueuedEventsProgressDialog(self.main_window.window) items = [] i = 1 total = len(pages) has_changes = False for page in pages: has_changes = has_changes or bool(page.data_boxes) item = AsyncItem(self.__performRecognitionForPage, (page, ), self.__performRecognitionForPageFinishedCb, (dialog, page, pages)) info = ( _('Recognizing Document'), _(u'Recognizing page %(page_number)s/%(total_pages)s. Please wait…' ) % { 'page_number': i, 'total_pages': total }) items.append((info, item)) i += 1 if has_changes and \ self.__confirmOveritePossibilityByRecognition() != gtk.RESPONSE_YES: return dialog.setItemsList(items) dialog.run()
def addImages(self, image_path_list): item_list = [] item_list_length = len(image_path_list) if not self.configuration_manager.deskew_images_after_addition and \ not self.configuration_manager.unpaper_images_after_addition: for index in range(0, len(image_path_list)): if not self.__addImage(image_path_list[index], index == 0): debug('Failed to load image "%s"' % image_path_list[index]) return dialog = QueuedEventsProgressDialog(self.main_window.window) for index in range(0, item_list_length): image_path = image_path_list[index] item = AsyncItem( self.__imagePreProcessing, (image_path, ), self.__imagePreProcessingFinishedCb, (dialog, index == item_list_length - 1, index == 0)) if item_list_length == 1: item_info = (_('Preparing image'), _(u'Please wait…')) else: item_info = (_('Preparing image %(current_index)s/%(total)s') % \ {'current_index': index + 1, 'total': item_list_length}, _(u'Please wait…')) item_list.append((item_info, item)) dialog.setItemsList(item_list) dialog.run()
def __obtainScannersFinishedCb(self, dialog, devices, error): dialog.destroy() device = None if len(devices) > 1: scanner_chooser_dialog = widgetPresenter.ScannerChooserDialog(\ self.main_window, devices) Gdk.threads_enter() response = scanner_chooser_dialog.run() Gdk.threads_leave() if response == Gtk.ResponseType.ACCEPT: device = scanner_chooser_dialog.getSelectedDevice() scanner_chooser_dialog.destroy() if response != Gtk.ResponseType.ACCEPT: return elif len(devices) == 1: device = devices[0][0] if device: dialog_scan = widgetPresenter.QueuedEventsProgressDialog(\ self.main_window) item_scan = AsyncItem(lib.scan, (device, ), self.__scanFinishedCb, (dialog_scan, )) info_scan = (_('Scanning'), _('Please wait…')) dialog_scan.setItemsList([(info_scan, item_scan)]) dialog_scan.run() else: error = widgetPresenter.SimpleDialog( self.main_window, _("No scanner devices were found"), _("Error"), 'warning') Gdk.threads_enter() error.run() Gdk.threads_leave()
def importFromScanner(self, widget): dialog = widgetPresenter.QueuedEventsProgressDialog(self.main_window) item_obtain = AsyncItem(lib.obtainScanners, (), self.__obtainScannersFinishedCb, (dialog, )) info_obtain = (_('Obtaining scanners'), _('Please wait…')) dialog.setItemsList([(info_obtain, item_obtain)]) dialog.run()
def deskewCurrentImage(self, widget): reviewer = self.__getCurrentReviewer() dialog = QueuedEventsProgressDialog(self.main_window.window) item = AsyncItem(self.__deskewImage, (reviewer.path_to_image, ), self.__deskewCurrentImageFinishedCb, (dialog, reviewer)) item_info = (_('Deskewing image'), _(u'Please wait…')) dialog.setItemsList([(item_info, item)]) dialog.run()
def recognizeCurrentPage(self): image_reviewer = self.__getCurrentReviewer() if image_reviewer.selectable_boxes_area.getAllAreas() and \ self.__confirmOveritePossibilityByRecognition() != gtk.RESPONSE_YES: return page = image_reviewer.page dialog = QueuedEventsProgressDialog(self.main_window.window) item = AsyncItem(self.__performRecognitionForPage, (page, ), self.__performRecognitionForPageFinishedCb, (dialog, page, [page])) info = (_('Recognizing Page'), _(u'Please wait…')) dialog.setItemsList([(info, item)]) dialog.run()
def importPdf(self, widget): file_open_dialog = widgetPresenter.FileDialog('open', file_filters = [(_('PDF'), ['application/pdf'], [])]) response = file_open_dialog.run() files = [] if response == gtk.RESPONSE_OK: files = file_open_dialog.get_filenames() file_open_dialog.destroy() for file_name in files: dialog = widgetPresenter.QueuedEventsProgressDialog( self.main_window.window) item = AsyncItem(lib.convertPdfToImages, (file_name, self.configuration_manager.TEMPORARY_FOLDER), self.__loadPdfFinishedCb, (dialog,)) info = (_('Loading PDF'), _(u'Please wait…')) dialog.setItemsList([(info, item)]) dialog.run()
def addImages(self, image_path_list): paths = [] for path in image_path_list: if os.path.exists(path): paths.append(path) else: warning('Could not load image "%s": does not exist' % path) if not paths: return image_path_list = paths item_list = [] temp_dir = self.configuration_manager.TEMPORARY_FOLDER image_path_list = graphics.convertMultiImagesInList(image_path_list, temp_dir) item_list_length = len(image_path_list) if not self.configuration_manager.deskew_images_after_addition and \ not self.configuration_manager.unpaper_images_after_addition: for index in range(0, len(image_path_list)): if not self.__addImage(image_path_list[index], index == 0): debug('Failed to load image "%s"' % image_path_list[index]) return dialog = QueuedEventsProgressDialog(self.main_window) for index in range(0, item_list_length): image_path = image_path_list[index] item = AsyncItem(self.__imagePreProcessing, (image_path,), self.__imagePreProcessingFinishedCb, (dialog, index == item_list_length - 1, index == 0)) if item_list_length == 1: item_info = (_('Preparing image'), _(u'Please wait…')) else: item_info = (_('Preparing image %(current_index)s/%(total)s') % \ {'current_index': index + 1, 'total': item_list_length}, _(u'Please wait…')) item_list.append((item_info,item)) dialog.setItemsList(item_list) dialog.run()