any simple example about pyqt and crossbar.io client (or server)

205 views
Skip to first unread message

Gelonida Gel

unread,
Oct 25, 2015, 5:53:28 PM10/25/15
to Crossbar
Hi,


I have a small PyQt application and would like to combine it with Wamp / crossbar.io.

How would I do this?
Does anybody have a very simple example?

The 'simple example I imagine would be a QT widget with:
a) one button: if pressed sending a publish event
b) one button if pressed sending a call
c) one label being updated via i subscribed signal
d) one piece of code, that updates a label and returns a value to crossbar (registered RPC call)


My ideas so far:

Up to my understanding i MUST start the PyQT event loop in the main thread, so I had to start the twisted loop of a crossbar client in a secondary thread.

a) not sure how to do this from a qt thread which is NOT the twisted thread. in the worst case I could add a web service publish url to the crossbar and use crossbarconnect

b) same as a)?

c) subscribe from the twisted thread and send a signal to the QT thread *or would there be better)

d) not sure how to do this
Can this cause any problems?


Any ideas suggestions?
Any pitfalls / special considerations?
Did anybody combine already PYQt and a crossbar client (or even the crossbar server?)

thanks in advance for your comments.

Alexander Gödde

unread,
Oct 29, 2015, 7:49:52 AM10/29/15
to Crossbar
Hi Gelonida!

Just one remark (I'm not big on Python and entirely unfamiliar with PyQT): When using AutobahnPython, there is no requirement for Twisted. You can also do things using asyncio.

Regards,

Alex 

Gelonida Gel

unread,
Oct 29, 2015, 6:31:39 PM10/29/15
to Crossbar
Thanks for your reply Alexander,




On Thursday, October 29, 2015 at 12:49:52 PM UTC+1, Alexander Gödde wrote:
Hi Gelonida!

Just one remark (I'm not big on Python and entirely unfamiliar with PyQT): When using AutobahnPython, there is no requirement for Twisted. You can also do things using asyncio.


True though it doesn't change a lot the basic question, which I did not express very clearly.
How to combine an existing application PyQT or another non asynchronously programmed app with a crossbar client, which follows
an asynchronous programming paradigm?


How can messages be passed between an asyncronous event loop and other (potentially blocking) threads.


Elvis Stansvik

unread,
Oct 31, 2015, 10:26:37 AM10/31/15
to cross...@googlegroups.com
Hi Gelonida,
We have several PyQt + Autobahn/Twisted clients at work. Threading is
not necessary. What we do is make use of qt4reactor [1], a bridge that
makes it possible to run the event loops of Qt and Twisted in tandem.

I don't have minimal example like you describe ready, and I can't
really share the code of the clients we have at work. But if I find
time I'll try to make such an example.

In the meantime, this is a very rough recipe:

1) Create your QApplication object.
2) Create your Autobahn Application object.
3) Install the Qt Twisted reactor with qt4reactor.install().
4) Run your application with app.run(url="your router URL", realm=u"your realm")

You should not call QApplication.exec(..), it will be done for you by
when the reactor starts.

It should be possible to use with the ApplicationSession API as well,
but the simplified Application API is what we're using at the moment.

Here's an example snippet of how we make an async RPC call inside a
slot connected to a Qt button click:

@pyqtSlot()
@inlineCallbacks
def on_startButton_clicked(self):
self.statusBar().showMessage('Preparing for acquisition')

yield self.wapp.session.call(u'com.example.x1.prepare_for_acquisition',
num_frames=500, frame_rate=5, binning=1)

self.statusBar().showMessage('Acquiring...')

yield self.wapp.session.call(
u'com.orexplore.x1.start_acquisition',
options=CallOptions(on_progress=self.onFrame))

self.statusBar().showMessage('Acquisition done')

Hope you have enough info to get going. But I'll see if I can make a
minimal working example when I have time.

Cheers,
Elvis

[1] https://pypi.python.org/pypi/qt4reactor/1.6

>
> thanks in advance for your comments.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Crossbar" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to crossbario+...@googlegroups.com.
> To post to this group, send email to cross...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/crossbario/77abbe47-2c32-4ffc-9015-2621e675cf1f%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Elvis Stansvik

unread,
Oct 31, 2015, 10:30:31 AM10/31/15
to cross...@googlegroups.com
I forgot to say: The above method is taken from our QMainWindow
subclass, and self.wapp is a reference to the Autobahn Application
object which was passed in and saved as a member when the window was
constructed.

Elvis

Gelonida Gel

unread,
Nov 1, 2015, 9:31:56 AM11/1/15
to Crossbar
Hi Elvis,


Thanks a lot this sounds lke a good solution fro XB + QT.
Will try it out

Elvis Stansvik

unread,
Nov 1, 2015, 12:39:13 PM11/1/15
to cross...@googlegroups.com
2015-11-01 15:31 GMT+01:00 Gelonida Gel <gelo...@gmail.com>:
> Hi Elvis,
>
>
> Thanks a lot this sounds lke a good solution fro XB + QT.
> Will try it out

I have a PyQt5 + Autobahn/Twisted port of the Crossbar Gauges demo
ready. It just needs a little polishing. I'll post to this list when
it's up on GitHub.

Elvis
> https://groups.google.com/d/msgid/crossbario/1e2ac060-e19d-4fa0-96b7-37d6d2440046%40googlegroups.com.

Elvis Stansvik

unread,
Nov 1, 2015, 3:06:02 PM11/1/15
to cross...@googlegroups.com
2015-11-01 18:39 GMT+01:00 Elvis Stansvik <elvs...@gmail.com>:
> 2015-11-01 15:31 GMT+01:00 Gelonida Gel <gelo...@gmail.com>:
>> Hi Elvis,
>>
>>
>> Thanks a lot this sounds lke a good solution fro XB + QT.
>> Will try it out
>
> I have a PyQt5 + Autobahn/Twisted port of the Crossbar Gauges demo
> ready. It just needs a little polishing. I'll post to this list when
> it's up on GitHub.

It's now up at https://github.com/estan/gauges

Elvis

Alexander Gödde

unread,
Nov 5, 2015, 6:49:25 AM11/5/15
to Crossbar
Hi Elvis!

Thanks for the demo! Could I add this to the crossbarexamples repository? I think this would make it easier to find for people.

Regards,

Alex

Elvis Stansvik

unread,
Nov 5, 2015, 7:09:16 AM11/5/15
to cross...@googlegroups.com

Den 5 nov 2015 12:49 em skrev "Alexander Gödde" <alexande...@googlemail.com>:
>
> Hi Elvis!
>
> Thanks for the demo! Could I add this to the crossbarexamples repository? I think this would make it easier to find for people.

I'll make a pull request as soon as possible. A bit busy with a school deadline atm.

I guess I'll follow the general format for examples there then, and not include a setup.py. Maybe I'll keep my repo as an "upstream" version.

Elvis

> --
> You received this message because you are subscribed to the Google Groups "Crossbar" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to crossbario+...@googlegroups.com.
> To post to this group, send email to cross...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/crossbario/402020cf-4874-4ecf-8a66-98fe07fd2a88%40googlegroups.com.

Elvis Stansvik

unread,
Nov 5, 2015, 7:11:06 AM11/5/15
to cross...@googlegroups.com


Den 5 nov 2015 1:09 em skrev "Elvis Stansvik" <elvs...@gmail.com>:
>
> Den 5 nov 2015 12:49 em skrev "Alexander Gödde" <alexande...@googlemail.com>:
> >
> > Hi Elvis!
> >
> > Thanks for the demo! Could I add this to the crossbarexamples repository? I think this would make it easier to find for people.

Oh wait, you said "can I". Yes by all means go ahead. You have my permission to use any license you want BTW.

Elvis

Alexander Gödde

unread,
Nov 5, 2015, 7:59:39 AM11/5/15
to Crossbar
Damn your reading skills ;)


Am Donnerstag, 5. November 2015 13:11:06 UTC+1 schrieb Elvis Stansvik:


Den 5 nov 2015 1:09 em skrev "Elvis Stansvik" <elvs...@gmail.com>:
>

> >> >> To post to this group, send email to cross...@googlegroups.com.
> >> >> To view this discussion on the web visit
> >> >> https://groups.google.com/d/msgid/crossbario/1e2ac060-e19d-4fa0-96b7-37d6d2440046%40googlegroups.com.
> >> >>
> >> >> For more options, visit https://groups.google.com/d/optout.
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Crossbar" group.

> > To unsubscribe from this group and stop receiving emails from it, send an email to crossbario+unsubscribe@googlegroups.com.

Elvis Stansvik

unread,
Nov 5, 2015, 8:05:40 AM11/5/15
to cross...@googlegroups.com

Den 5 nov 2015 1:59 em skrev "Alexander Gödde" <alexande...@googlemail.com>:
>
> Damn your reading skills ;)

:) No but really, it's no bother, I can make a pull request, it's just that if I do, it won't be right now as I have that deadline at 17 tomorrow.

Elvis

>> > >> >> https://groups.google.com/d/msgid/crossbario/1e2ac060-e19d-4fa0-96b7-37d6d2440046%40googlegroups.com.
>> > >> >>
>> > >> >> For more options, visit https://groups.google.com/d/optout.
>> > >
>> > > --
>> > > You received this message because you are subscribed to the Google Groups "Crossbar" group.

>> > > To unsubscribe from this group and stop receiving emails from it, send an email to crossbario+...@googlegroups.com.
>> > > To post to this group, send email to cross...@googlegroups.com.

>> > > To view this discussion on the web visit https://groups.google.com/d/msgid/crossbario/402020cf-4874-4ecf-8a66-98fe07fd2a88%40googlegroups.com.
>> > >
>> > > For more options, visit https://groups.google.com/d/optout.
>

> --
> You received this message because you are subscribed to the Google Groups "Crossbar" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to crossbario+...@googlegroups.com.
> To post to this group, send email to cross...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/crossbario/af8cbd86-a283-4d7c-b1b6-0fe471dfda84%40googlegroups.com.

Alexander Gödde

unread,
Nov 5, 2015, 8:19:11 AM11/5/15
to Crossbar
No hurry! (And thanks again!)

Am Donnerstag, 5. November 2015 14:05:40 UTC+1 schrieb Elvis Stansvik:

>> > >> >> To post to this group, send email to cross...@googlegroups.com.
>> > >> >> To view this discussion on the web visit
>> > >> >> https://groups.google.com/d/msgid/crossbario/1e2ac060-e19d-4fa0-96b7-37d6d2440046%40googlegroups.com.
>> > >> >>
>> > >> >> For more options, visit https://groups.google.com/d/optout.
>> > >
>> > > --
>> > > You received this message because you are subscribed to the Google Groups "Crossbar" group.

>> > > To unsubscribe from this group and stop receiving emails from it, send an email to crossbario+unsubscribe@googlegroups.com.


>> > > To post to this group, send email to cross...@googlegroups.com.
>> > > To view this discussion on the web visit https://groups.google.com/d/msgid/crossbario/402020cf-4874-4ecf-8a66-98fe07fd2a88%40googlegroups.com.
>> > >
>> > > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "Crossbar" group.

> To unsubscribe from this group and stop receiving emails from it, send an email to crossbario+unsubscribe@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages