PySide methods signature in Eclipse/WingIDE/PyCharm? - python

Is there any way to have the signature of the methods of PySide classes in Eclipse, WingIDE, PyCharm or any Python IDE?
Currently, it auto-completes the classes and method names, but not the parameters of the methods.
All functions are detected as functions without parameters.
I know it's a Python binding of a C++ framework so it's not that easy but is there any way to have the method signatures directly in an IDE?

I use PyDev (Eclipse plugin) and it works like a charm, also with function signatures.
EDIT:
I'm not 100% sure with C++ extensions, but it should work well if there's a Python wrapper for it. With pure C++ extensions there might be problems, but actually I haven't tried it.

Try running help(some-qt-method) in a Python console, what do you see? Exactly.
As far as I know, the only IDE that handles PyQt / PySide in depth is Eric, and only because it explicitly compiles signatures in its own format for autocompletion.

Related

Is it possible to get jedi autocomplete for a C++ library binded to python?

I am using vim with jedi-vim to edit some python code. However, some libraries we use are C++ shared libraries for which we generated python bindings using pybindgen. When using jedi-vim, I do not get signature for any of the classes and methods, just a listing of them.
For example, in this library, https://github.com/jorisv/SpaceVecAlg if I install the library and import it:
import spacevecalg as sva
Then, sva. will correctly show all first-order functions and classes. However, if I select the first one, sva.ABInertia( jedi will not suggest me any of the class constructors.
I suppose I have to somehow export the class definitions to a kind of python documentation, and I figured I could use the doxygen annotations for that, but I have no idea how to feed that extra documentation to jedi (or any other completion engine, such as the one built in IPython).
Thanks a lot !
You cannot feed extra documentation to Jedi. However, you can set the __doc__ attribute in a way that Jedi understands it. If you define call signatures the same way as the standard library, I guess it should work.
As a side note, I have to mention that in Python 3.4+ there's an even better way of defining the docstrings. IMHO it's the proper way to define it. I'm not sure how exactly to do it (but there are ways to use it):
>>> inspect.signature(exit)
<inspect.Signature object at 0x7f2b5a05aa58>
>>> str(inspect.signature(exit))
'(code=None)'
Jedi doesn't understand it yet, but it definitely will in the future.

Eclipse does not autocomplete function arguments for PyQt4

Eclipse will not autocomplete the function parameters in the PyDev perspective for PyQt4. All other aspects of the auto complete are working.
I am able to type x = QDia and Eclipse lists of all classes/variables starting with QDia. However, I am in dire need for all having Eclipse show all of the constructors and function arguments.
I should mention that this feature does work for other Python modules. Something is different with PyQt4 and I can't figure it out.
System Details: RHEL5/RHEL6, Eclipse 4.3.1 (Kepler), PyDev 3.3 (I think), Qt 4.6
Unfortunately the way that PyQt is wrapped doesn't expose that information (PyDev mostly imports the module in a shell, does a dir() and interprets the docstring to get information to show on to the user, but PyQt4 doesn't have that info -- and I'm not sure there's any automated way to get it).
So, usually when coding on qt I use the Qt Assistant a lot to get that kind of info... (or sometimes browse it on the web)

How is Python interpreted with wxPython, PyQt, PySide or Tkinter?

I got curious and have been reading about GUI development using Python for the past hour. After reading documentation of wxPython, PyQt, Nokia's Python bindings for Qt along with Tkinter a question came to my mind.
When I create a console application with Python, it runs using the embedded Python interpreter (which I assume is usually if not always in my case cpython).
So I was wondering, what's the case with these "widget toolkits"?
How is the Python code executed and what interprets it (or executed it)?
Which part of my Python code is interpreted using the Python
interpreter?
Or does the Python code get lexically analysed and then parsed by the widget's
toolkit which then interpretes and executes (or compile during build)?
I am looking forward to understanding what goes on in the background in comparison with Python applications' (a bit simpler to understand) interpretation with the Python interpreter.
Thank you.
PS. To whichever genius thinks that this question deserves to be closed;
A lot of people wonder the internals of external libraries and systems. Especially those which are not as simple as they look. There currently is not any question explaining this on SE.
This is just a really generalized high-level explanation about "GUI toolkits"...
Lets say you decide to use the Qt framework. This framework is written in C++. There are two different python bindings that can be used, allowing one to write a GUI application in python against the same API as the C++ version.
The python bindings provide a wrapping around calls into the C++ code. PyQt4 for instance uses sip, while PySide uses shiboken. These are just language wrapping tools that take specifications for how to map between the C++ objects and their intended python interface.
Ok, so you start using PyQt... All of the code you write has to pass through the python interpreter. Some of it may be pure python. Some of it will call into C++ libs to create things like your widgets. In Qt, there will be a C++ pointer associated with the python instance counterpart.
It is the C++ layer that is then communicating with the window manager of your platform, to turn platform-independent API calls into something platform specific, like how to exactly draw a button or menu.
Whether you create a console only or GUI based python application, it all goes through the python interpreter to interpret your python code. Something must interpret the python language for you.

Intellisense for Ruby, Ruby on Rails, Python

Are there any intellisense options for languages like Ruby, Ruby on Rails, Python, etc?
This could include an IDE, if necessary. I'm looking for something like Visual Studio's c# or Eclipse's java intellisense.
Sure are!!
jetbrains has full line of ide's.
PyCharm and RubyMine
http://www.jetbrains.com/ruby/
Because of the dynamic nature of these languages, implementing things like auto-completion is quite difficult, and only works for some cases.
Examples for Python: pydev (eclipse plug-in), rope (this is a refactoring library that can easily be used into emacs),anyting with ipython (again, an emacs mode).
Anyways, don't expect them to be as powerful as the tools you have for Java or C#.
Rope for example, does a bit of type inference to figure out parameter types in order to give you completion suggestions. This might take an awfully long amount of time for big codebases, thus making the feature useless on such codebases.
anyting with ipython on the other hand actually spawns a background python process that imports your current module and any modules it references, and does runtime checking on entities (classes, functions, global variables...) in those modules. Because it doesn't do type inference, it can't give you any auto-completion suggestions for variables passed as parameters or local variables.
My vim setup uses the supertabcomplete, snipmate, and python-mode plugins for mostly intellisense completion.
It's windows centric, because that is what I develop on, but just change the paths in the vimrc file after cloning and you should be up and functional.
Sublime Text 2 also supports this to a limited extent. Auto-completion is very difficult for dynamic languages, so this will display recently use variables/methods, and anything else that is nearby that matches the fuzzy text filter.
Use vim with dot files which includes syntax highlight, smart indentation, auto-complete for Ruby among other features. Although it had been worked for MacOS, but you can easily adapt to your OS if you're using other.
Another option includes Aptana for Eclipse or Jetbrains RubyMine. So try all the solutions and decide what best fits your needs.

Call from Objective-C into Python

bbum posted an outline of how to do this, but I'm unable to complete the details. Where does the Python code go, and how will my Objective-C code know about it? How would I do it compiling on the command line?
Source here:
Calling Python From Objective-C
I have posted a full explanation of how to do this to my weblog as it is quite a bit longer than something I would post here.
The abstract summary remains the same: use an abstract class to provide the type information necessary to make the C compiler happy and the metadata necessary to make the bridge happy.
Unfortunately the story for using Python via PyObjC from within an Objective-C app is not very good at the moment. py2app which ships with PyObjC can compile loadable bundles (i.e. can be loaded via NSBundle), which seems like the best approach: define an NSObject subclass in python that implements a protocol (obtained via objc.protocolNamed) that you define in Objective-C, then compile this python file into a loadable bundle via py2app (which uses a standard setup.py). Unfortunately, py2app hasn't had much love, especially the plugin (loadable bundle) target, and a serious memory leak was introduced sometime around 10.5 such that any data passed from python to Objective-C from a py2app-compiled bundle leaks. Yuck.
PyObjC manipulates the Objective-C runtime in accordance with the ObjC-related code executed in Python, thus to be able to call python code from Objective-C, the general outline goes like
Write PyObjC wrapper around python code
Execute code declaring PyObjC wrapper to add these definitions to the ObjC runtime
Call PyObjC wrapper from Objective-C. Because it's declared at runtime, the symbols aren't available at compile time, so you'll have to use NSClassFromString et al. to instantiate the class. It's helpful to declare a #protocol with the appropriate methods so that the Objective-C compiler doesn't complain about missing methods.
If you have flexibility, the best option is to use the Cocoa-Python app templates (i.e. create a Python app), and then load your Objective-C code as a loadable bundle from within Python. This takes care of managing the Python interpreter for you.
Otherwise, with the code in main.m of the Cocoa-Python app template, you should be able to create a Python interpreter, execute your PyObjC code and then continue on. Obviously, the interpreter needs to be kept running so that your python code can execute, so you'll likely have to do this from a separate thread. As you can see this can get a little hairy. Better to go with the Python app, as described above.
Keep in mind that PyObjC is not guaranteed to play well with the Objective-C garbage collector, so all of these options require that your Objective-C code not use GC.
Google is your friend. Performing a search on the string "Cocoa Python" quickly turned up PyObjc.

Categories

Resources