PIL SANE interface: where can I find it? - python

Apparently PIL includes a SANE (Scanner Access Now Easy) interface - I'm looking at code right now that does
import sane
where sane is provided by PIL.
I've installed PIL under both OS X and Windows, but "import sane" doesn't work for me. I did a fair bit of googling to see if there's something extra I need to install but I'm not finding anything.
How do I get the SANE interface for PIL?
I'm happy with any SANE interface (doesn't have to be PIL), so if you know of an alternative that would help too.

Disclaimer: I never used SANE.
I don't think that sane is provided with the PIL library.
It seems, instead, that the package you're looking for is called pysane.

Related

UIA/MSAA in Python?

I'm still hacking away on my little Screen Reader project, and need to add support for MSAA/UIA/IAccessible/other Accessibility APIs, but I can't seem to find any good tutorials for doing so (in Python, that is). I can find a lot of ctypes/comtypes tutorials, but I need more functionality, I already know how to use those libraries. I have also found MSDN's UIA tutorials, but they're for C++ and hardly apply to Python anyways, as I have no idea what module they'd be in :D. Is pywin32 enough? Do I need ctypes? Comtypes? Or is there a hole other module for UIA? If so, I haven't been able to find any tutorials... :(.
Thanks in advance.

Utilizing the Dependency-Graph of pip

I want to write a visualization of the Dependency-Graph of all python-packages installed with pip. My problem is that the code is poorly documented, and im unable to find where the Graph is stored in the source Code.
I hope someone has enough knowledge about pip-sourcecode to help me out.
Also im new to python and am not sure if i should just make my adjustments in the existing source-code, or write a module for it, although im leaning more towards the latter.
// edit: I can get all installed modules via pip freeze, but that givbes me only one list without the dependencies. So i have to find a way to extract the dependencies from that list.
Yes, its code is quite unreadable if you're not used to it. I don't recall something like that and I would not use it. You may find yourself better suited with distlib, which has a module just for that: https://distlib.readthedocs.org/en/latest/depgraph.html
Heres what i found during my search:
Pip doesn't use a Dependency-graph at all internally. (As of version 1.3.X)
So one solution is to do the following:
You can install setuptools, if you havent allready. It brings a module named pkg_resources.
This module has all the tools, to see all installed modules (not only the ones installed with pip) in your desired dists-directory. You can then read out the metadata (including requirements/dependencies) with methods that are as well included in pkg_resources.

OpenCV 2.3.1 Python with Eclipse shows synatx errors but still runs

I followed this guide to setup OpenCV 2.3.1 in Python 2.7 with Eclipse.
I also copied the libraries into my python folder:
http://i.snag.gy/J9RrC.jpg
Here is my Hello World program which runs correctly (creates a named window and displays the image) but Eclipse still shows syntax errors
every error says "Undefined variable from import"
Here are my python settings for this project:
http://i.snag.gy/KBXiB.jpg
http://i.snag.gy/KfTpF.jpg
Have I setup my PythonPath incorrectly? How can i get Eclipse to work properly?
Thanks
I had the same problem, everything ran correctly even though there were undefined import errors all over the place. I eventually solved it by adding 'cv' to the list of Forced Builtins: Window > Preferences > Pydev > Interpreter - Python > Forced Builtins > New.
This is how I came across the solution:
How to use code completion into Eclipse with OpenCV
I hope that this may help you too.
EDIT: FYI, according to the top answer here, if you're just getting started (like me!) it's almost certainly better to use the cv2 interface instead of the older one provided in cv2.cv. The author of that answer, Abid Rahman, has some tutorials that look pretty good. (end EDIT)
I used Debian's tools to install the python-opencv package. There was no .../dist-packages/opencv directory to be found, and the cv.py file contained only:
from cv2.cv import *
I'm fairly inexperienced with Python and completely so with Python access to external libraries, so this looked like some sort of workaround related to that. Not so, apparently. I followed Casper's link above, and found the solution that he used (which worked for me,) but I wasn't happy using "forced builtins" when I wasn't entirely sure of the consequences.
However, the second, lower-rated answer there is my preferred solution. Instead of
import cv
I'm using
import cv2.cv as cv
From what I can tell, this just removes the cv.py middleman from the import chain, if that makes sense. A save/close/reload of my script had Eclipse recognizing cv.LoadImageM as defined and autocompleting other things from OpenCV.
I'm reproducing that answer here because it seems cleaner to me and I found this question first when I searched for the answer to the same problem.
It would be helpful to show the error you're getting and your code. However, I suspect that the problem is that the syntax errors which PyDev shows are based on its own parsing of the code, which is much more simplistic that the actual python interpreter. If your code runs, then the apparently undefined variables must be defined, but the PyDev parser just can't see them and reports them as "undefined".
The cause of this is that OpenCV doesn't explicitly define its variables in a way which can be read by PyDev. Unfortunately I don't have an easy solution. I usually deal with the problem by using from ... import ... so that the error only appears once. If you want you could write a wrapper module which explicitly imports the variables into its local namespace, then import that module instead.

CImg Python 3 bindings or something at least comparable?

i'm searching a Python lib with good image processing functionalities .
I was searching for CImg (which i've already used on C++ projects) bindings, but i wasn't lucky.
I found PIL, but it lacks a lot of features that CImg has so, is there any good alternative ?
Thanks
UPDATE
PIL is good, but i need Python 3 support on a Mac OS X system.
I would suggest you to enumerate the functionality that you find desirable which is there in Cimg and not in PIL.
Discussion on SO
Image Processing, In Python?
pypi also throws up a lot of modules on image processing. Try seeing, if some of them is suitable for you.
http://pypi.python.org/pypi?:action=search&term=image+processing&submit=search

How can I move file into Recycle Bin / trash on different platforms using PyQt4?

I would like to add the next feature to my cross-platform PyQt4 application: when user selects some file and select "remove" action on it that file will be moved to Recycle Bin folder instead of being permantly removed. I think I can find Windows-specific solution using Win32 API or something similar, but I'd like to know does similar operation could be executed on Ubuntu/Linux and MaxOSX as well via PyQt4 methods.
It's a good thing you're using Python, I created a library to do just that a while ago:
http://www.hardcoded.net/articles/send-files-to-trash-on-all-platforms.htm
On PyPI: Send2Trash
Installation
Using conda:
conda install Send2Trash
Using pip:
pip install Send2Trash
Usage
Delete file or folders
from send2trash import send2trash
send2trash("directory")
I guess there really is no cross-platform solution provided by Qt and it's not a totally trivial task to implement the trash concept in Linux since it's slightly different based on which file manager is in use.
Here's a site discussing the trash concept in Nautilus and another one for KDE.
Under Windows you can use the Win32 API like you said. Python solution available here.
Mac OS X puts the trashed files in ~/.Trash similar to other *NIX OSes, but I couldn't quickly Google any documentation for it. It seems that the OS X trash info file is some kind of binary format and not plain text like in Linux.
Symbian doesn't have a desktop concept and thus no trashcan concept either. It might be similar for other mobile platforms.
EDIT: Super User has some discussion revealing that .DS_Store does indeed store information about trashed files, but no specifics about the format.
The best OSX solution I know uses Applescript. I did not, however, invent it, so I shall simply link to it here.
It would be nice to have a module that packaged up the Win32/KDE/OSX solutions into one, i feel, and imported the correct one on demand. Is that how you solved your problem in the end?

Categories

Resources