def next_word(self): """Set the next word, or stop the program if we're done.""" try: self.word = self.word_iter.next() except StopIteration: try: self.cur_line = self.line_iter.next() self.new_lines.append([]) except StopIteration: self.save_quit() self.word_iter = iter(self.cur_line) self.word = self.word_iter.next() self.cropped = croplib.crop(self.img, self.word.left, self.word.top, self.word.right, self.word.bottom) self.make_pixbuf(self.cropped) self.set_drawing_size(self.cropped) self.entry.set_text(self.word.text)
import sys # import C++ libraries import pamImage, croplib # check commandline parameters if len(sys.argv) != 3: print "Example program. Crops the image to a smaller region." print "Usage: python %s image.ppm outfile.ppm" % sys.argv[0] sys.exit(1) in_file_name = sys.argv[1] out_file_name = sys.argv[2] # open image im = pamImage.PamImage(in_file_name) width, height = im.getWidth(), im.getHeight() print "Image width:", width print "Image height:", height # crop image print "Cropping image..." left, right = width / 3, (width * 2) / 3 # integer calculations top, bottom = 0, height - 1 cropped_im = croplib.crop(im, left, top, right, bottom) cropped_im.thisown = True # to make Python cleanup the new C++ object afterwards cropped_im.save(out_file_name) print "%s saved." % out_file_name