Preview on Mac OS (at least the newer ones) has limited editing options that I find very useful (It's a waste to pay the premium on Adobe Acrobat Pro for the simple editing I need). One major task is to insert signatures on documents that are being passed around electronically (so much better than using mail and hardcopies).
Preview has a neat trick where you can create signatures without needing a scanner. You simply sign on a piece of paper and hold it up to the camera and some sophisticated software extracts the signature for you.
But like all things Mac, they got too clever. There is no option to load a signature from an existing file. This does not represent any kind of extra security. If you don't have pen and paper handy, or you need to insert some one else's signature (as I did) you would have to find a printer, print out the signature and hold it up to the camera.
So I had one of those rare 'smart' moments. I took the signature file, opened it up on my second monitor and then turned the laptop I was using to face the second monitor. This fooled Preview and it captured the signature. I got strange looks from my co-workers but whatever.
Here also I ran into another 'too clever' issue with Macs. Preview adds drop shadows to pdfs and images at the page borders. When I used preview to open the signature image the signature capture software detected the drop shadows and page margins and added black borders round the signature. I could not find a convenient way to get rid of the drop shadow and ended up opening the file in a web browser.
Python's context managers are a very neat way of handling code that needs a teardown once you are done. Python objects have do have a destructor method ( __del__ ) called right before the last instance of the object is about to be destroyed. You can do a teardown there. However there is a lot of fine print to the __del__ method. A cleaner way of doing tear-downs is through Python's context manager , manifested as the with keyword. class CrushMe: def __init__(self): self.f = open('test.txt', 'w') def foo(self, a, b): self.f.write(str(a - b)) def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): self.f.close() return True with CrushMe() as c: c.foo(2, 3) One thing that is important, and that got me just now, is error handling. I made the mistake of ignoring all those 'junk' arguments ( exc_type, exc_val, exc_tb ). I just skimmed the docs and what popped out is that you need to return True or...
Comments
Post a Comment