-
Notifications
You must be signed in to change notification settings - Fork 10
Writing Gui Clients
This page describes how to write GUI clients using the PyQt4 Python library. We assume some familiarity with PyQt, please see this tutorial for an excellent introduction for writing PyQt programs. We explain how to create a LabRAD client that encompasses a graphical user interface containing, buttons, spinboxes, dropdown menus, and any other PyQt widgets. The created clients are similar scripts in that they interface with a server and are able to execute server settings in response to user action i.e pressing a button. In addition, the GUI clients are able subscribe to signals from the server and act in response to these signals being emitted. For these reasons, GUI clients are referred to as asynchronous clients.
LabRAD is built on top of the twisted Python library. In twisted, the timing of all events is controlled by an event loop called a reactor. Similarly to twisted, PyQt has its own reactor to control the timing graphical events. For the two libraries to work together, the two event loops must be combined. This is done with a freely available (qt4reactor)[https://github.com/ghtdak/qtreactor/blob/master/qt4reactor.py] as follows: `` from twisted.internet.defer import inlineCallbacks class sampleWidget(QtGui.QWidget): def init(self, reactor, parent=None): super(sampleWidget, self).init(parent) self.reactor = reactor self.connect()
@inlineCallbacks
def connect(self):
from labrad.wrappers import connectAsync
self.cxn = yield connectAsync()
def closeEvent(self, x):
self.reactor.stop()
if name=="main": a = QtGui.QApplication( [] ) import qt4reactor qt4reactor.install() from twisted.internet import reactor pmtWidget = pmtWidget(reactor) pmtWidget.show() reactor.run() ``