summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/ocr/__init__.py0
-rw-r--r--plugins/ocr/ocr.py95
2 files changed, 95 insertions, 0 deletions
diff --git a/plugins/ocr/__init__.py b/plugins/ocr/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/plugins/ocr/__init__.py
diff --git a/plugins/ocr/ocr.py b/plugins/ocr/ocr.py
new file mode 100644
index 0000000..876f257
--- /dev/null
+++ b/plugins/ocr/ocr.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+#
+# Copyright 2011 Raul Gutierrez Segales
+#
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+from gettext import gettext as _
+import os
+from plugins.plugin import Plugin
+
+from TurtleArt.tapalette import make_palette
+from TurtleArt.talogo import primitive_dictionary
+from TurtleArt.taconstants import NO_IMPORT
+
+
+class Ocr(Plugin):
+
+ def __init__(self, parent):
+ self._tawindow = parent
+
+ if self._check_ocr_cmd():
+ self._enabled = True
+ else:
+ self._enabled = False
+
+ def _check_ocr_cmd(self):
+ ret = os.system("gocr > /dev/null 2>&1")
+ if ret == 0:
+ return True
+ return False
+
+ def setup(self):
+ if not self._enabled:
+ return
+
+ palette = make_palette('sensor',
+ colors=["#FF6060", "#A06060"],
+ help_string=_('Palette for Image Processing'))
+ primitive_dictionary['do_ocr'] = self.prim_do_ocr
+ palette.add_block('do_ocr',
+ style='box-style',
+ label=_('OCR'),
+ help_string=_('Run OCR on the current canvas'),
+ value_block=True,
+ prim_name='do_ocr')
+ self._tawindow.lc.def_prim('do_ocr', 0,
+ lambda self: primitive_dictionary['do_ocr']())
+ NO_IMPORT.append('ocr')
+
+ def start(self):
+ ''' Prepare stuff '''
+ pass
+
+ def quit(self):
+ ''' This gets called when the activity quits '''
+ # TODO: clean up pending ocr processes
+ pass
+
+ def stop(self):
+ ''' This gets called by the stop button '''
+ # TODO: clean up pending ocr processes
+ pass
+
+ def clear(self):
+ ''' This gets called by the clean button and erase button '''
+ # TODO: clean up pending ocr processes
+ pass
+
+ def prim_do_ocr(self):
+ """ Perform OCR on what is available on the canvas """
+ if not self._enabled:
+ return
+
+ temp_name = "ocrTMP"
+ self._tawindow.save_as_image(temp_name)
+
+ ocr_cmd = "gocr %s" % (temp_name + ".png")
+ fd = os.popen(ocr_cmd)
+ output = "".join(fd.readlines())
+
+ # TODO: Save this to the Journal or..
+ print output