Hi all,

I'm trying to implement Python script plugins in mBarcode [0] so that users can easily write functions to handle particular types of barcode payload. As such, little interaction is required between the main mBarcode application and the Python script plugins, other than the ability for the main app to pass the Python plugin two strings containing the barcode type and payload and for the Python code to be able to create a window (or draw to one) and generate and handle events created by the UI components. If I could directly link a Python script slot to a C++ signal that would be even better (in terms of clean code).

Each Python plugin will implement a pre-defined class so that the main C++ app can call methods to return information about the plugin (i.e. name) and pass it info (barcode type & data) and to tell it whether it has been invoked and to therefore display its UI, etc.

I have written some code using plain CPython to call each method of the Python plugin class as and when needed, but in this case, while I can pass data back and forth and create a UI using Python + PySide, no slot/signal pairs get called. E.g. after adding a QPushButton, one can click the button and it changes colour as expected, but the connected callback is never run. See [1] for this code.

Therefore I started looking at the possibility of "casting" my Python class to a C++ class using Shiboken::Converter<T*>::toCpp(wrapper) as seen in this thread [2]. I'm not sure whether this method will work - can anyone advise me one way or another? If it will work, I imagine that I will need to generate PySide wrappers for the base C++ class so that the converter knows what it's doing (I've seen something similar using SIP here [3])

Assuming this might work, the question is how should I go about generating wrappers for a single class (rather than a lib as seen in the examples/tutorials) and can I compile this code into my main C++ application so that it can be used from within to "cast" the Python class to C++? The tutorial and examples all seem to assume that the wrapped C++ class will be import'ed into the Python code, but this is not necessary for me as I don't want to use any objects in the main code from Python.

The other similar approach, which looks to be the one employed by the IDA plugin writers [4] is to wrap a base C++ class and have it import'able into the Python code. I could equally adopt this approach if it looks like it is more likely to work (my Python plugins will generally want to display a UI so I could pass them e.g. a wrapped window class). In this case what does one do to wrap everything? Have the base class reside in a library which is both loaded by the C++ app and also by the Python script code? Do the two not interfere with one another?

But then again perhaps these approaches simply won't work for code that wants to generate slot/signal events on the Python-side, which seems to be the conclusion here (unless you move the QApplication event loop to the Python code)?: [5,6]

Apologies for the long email,

I'd appreciate any help or ideas you can offer,

Cheers,


Simon


0. http://maemo.org/packages/view/mbarcode/
1. https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/mbarcode-qt-plugins/PythonQTPluginWrapper/?root=maemo-barcode
2. http://lists.openbossa.org/pipermail/pyside/2010-October/001150.html
3. https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/src/providers/python/?root=web2sms
4. http://www.hexblog.com/?p=229
5. http://lynxline.com/qt-python-superhybrids/
6. http://lynxline.com/superhybrids-part-2-now-qt-pyside/
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to