From 4548f92e73ea3bf98f48ae429a5281a734718695 Mon Sep 17 00:00:00 2001 From: Andrey Golovizin Date: Mon, 8 Sep 2014 21:15:55 +0200 Subject: [PATCH] Use backend-specific suffixes for output filenames. --- pixelocr/formatting.py | 3 +++ pixelocr/gui/ocrengine.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pixelocr/formatting.py b/pixelocr/formatting.py index 4429a3a..eb75757 100644 --- a/pixelocr/formatting.py +++ b/pixelocr/formatting.py @@ -21,6 +21,7 @@ from .glyphdb import WhitespaceData class OutputFormat(object): + suffix = '' last_tag = None def __call__(self, glyph_data_stream): @@ -65,6 +66,7 @@ class OutputFormat(object): class TextFormat(OutputFormat): + suffix = '.txt' def assign_tag(self, glyph_data): return None @@ -73,6 +75,7 @@ class TextFormat(OutputFormat): class HTMLFormat(OutputFormat): + suffix = '.html' def assign_glyph_tag(self, glyph_data): style = glyph_data.style if style.bold: diff --git a/pixelocr/gui/ocrengine.py b/pixelocr/gui/ocrengine.py index 7882627..5b3a16f 100644 --- a/pixelocr/gui/ocrengine.py +++ b/pixelocr/gui/ocrengine.py @@ -65,7 +65,7 @@ class OCREngine(QThread): self.pageChanged.emit(page) page_text = self.recognize_page(page) print(page_text) - with open(filename + '.txt', 'w') as page_text_file: + with open(filename + self.output_format.suffix, 'w') as page_text_file: page_text_file.write(page_text) def recognize_page(self, page):