[Pycodeocr-main] SF.net SVN: pycodeocr:[19] PyCodeOCR.py
Status: Beta
Brought to you by:
drtrigon
From: <la...@us...> - 2010-09-06 16:33:36
|
Revision: 19 http://pycodeocr.svn.sourceforge.net/pycodeocr/?rev=19&view=rev Author: laserb Date: 2010-09-06 16:33:29 +0000 (Mon, 06 Sep 2010) Log Message: ----------- Simple fix to support orientation where it is needed. Modified Paths: -------------- PyCodeOCR.py Modified: PyCodeOCR.py =================================================================== --- PyCodeOCR.py 2010-09-06 16:28:39 UTC (rev 18) +++ PyCodeOCR.py 2010-09-06 16:33:29 UTC (rev 19) @@ -2,13 +2,13 @@ # -*- coding: utf-8 -*- -# python standard modules +# python standard modules import os, re, sys, subprocess, time -# GTK, PyGTK, GLADE (GNOME) modules +# GTK, PyGTK, GLADE (GNOME) modules import pygtk pygtk.require('2.0') -import gtk, gtk.glade +import gtk, gtk.glade import gobject # PIL image library and it's SANE bindings @@ -57,12 +57,12 @@ # MainWindow # The GUI was created/designed using GLADE # -class MainWindowGTK: +class MainWindowGTK: """ PyCodeOCR main GUI window and application class. """ - # initialization + # initialization # (variables) max_retry = 3 # max. scan attempts valid_code_len = [ 53, 42, 32 ] # valid code lenghts @@ -91,13 +91,13 @@ """ ... """ # retrieve widgets self.gladefile = raw_path + ".glade" - self.xml = gtk.glade.XML(self.gladefile) - self.window1 = self.xml.get_widget('window1') + self.xml = gtk.glade.XML(self.gladefile) + self.window1 = self.xml.get_widget('window1') self.togglebutton1 = self.xml.get_widget('togglebutton1') self.button2 = self.xml.get_widget('button2') self.image1 = self.xml.get_widget('image1') self.entry1 = self.xml.get_widget('entry1') - self.progressbar1 = self.xml.get_widget('progressbar1') + self.progressbar1 = self.xml.get_widget('progressbar1') self.combobox1 = self.xml.get_widget('combobox1') self.combobox2 = self.xml.get_widget('combobox2') self.spinbutton1 = self.xml.get_widget('spinbutton1') @@ -151,7 +151,6 @@ def on_combobox1_changed(self, source=None, event=None): """ Combobox changed signal handler. """ - #orient = self.combobox1.get_active() orient = self.combobox1.get_model()[self.combobox1.get_active()][0] self.spinbutton1.set_value(std_scan_koords[orient][0][0]) @@ -224,8 +223,9 @@ 'valid_code_len': self.valid_code_len, 'resolution': 600, } elif (op_mode == self.MDE['barcode']): # 1: barcode (gocr) + self.on_combobox1_changed() # orientation mode self.scan_koords = std_scan_koords["A4"][0] - self.mode = std_scan_koords["A4"][1] + #self.mode = std_scan_koords["A4"][1] opt = { 'tmp_file': "02.pnm", 'recog_class': RunExternal, 'recog_cmd': self.cmd_gocr % (self.temp+"02",), @@ -233,6 +233,7 @@ 'valid_code_len': [ 13, 10, 9 ], 'resolution': 300, } elif (op_mode == self.MDE['DataMatrix']): # 2: DataMatrix (libdmtx) + #self.on_combobox1_changed() # orientation mode self.scan_koords = std_scan_koords["A4"][0] self.mode = std_scan_koords["A4"][1] opt = { 'tmp_file': "02.jpg", # some issues with recogition @@ -282,7 +283,6 @@ # Adjust and rotate the retrieved data # (2/?) self.progress(2./max_steps, "Adjusting image/picture data...") - #mode = 90 * self.combobox1.get_active() mode = self.mode self.run_convert = RunExternal(self.cmd_convert % (inp_file, mode, self.temp+opt['tmp_file']), error_msg=[ "convert: unable to open image" ]) # self.run_convert = RunMagickWand(inp_file, mode*90, self.temp+opt['tmp_file']) @@ -312,12 +312,18 @@ return None if (op_mode == self.MDE['invoices']): # 0: invoices - df = file(self.temp+"03.txt", "r") - data = df.read(-1) - df.close() - origdata = data - - os.remove(self.temp+"03.txt") # clean-up + # Simple workaround: The program simply continuous if no text is found at all + # and therefore no txt-file is generated. + if not os.path.exists(self.temp+"03.txt"): + origdata = "$" + data = "$" + else: + df = file(self.temp+"03.txt", "r") + data = df.read(-1) + df.close() + origdata = data + os.remove(self.temp+"03.txt") # clean-up + elif (op_mode == self.MDE['barcode']): # 1: barcode # (cheap'n'ugly but working...) raw_data = self.regex_gocr.search(self.run_recognition.stdout).groups() @@ -527,9 +533,9 @@ """ Execute external shell command. """ if piped: run = subprocess.Popen( self.cmd, - stdin =subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + stdin =subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, shell=True ) (stdoutdata, stderrdata) = run.communicate() return ((max(map(stderrdata.find, self.error_msg)) != -1), stdoutdata, stderrdata) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |