Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Inspiration: http://zetcode.com/gui/pysidetutorial/widgets/
- import sys, zmq, infoPack_pb2
- from PyQt4 import QtGui, QtCore
- class Example(QtGui.QWidget):
- def __init__(self):
- super(Example, self).__init__()
- self.initUI()
- # Set up zeromq send connection
- context = zmq.Context()
- self.publisher = context.socket(zmq.PUB)
- self.publisher.connect('tcp://localhost:2000')
- # Set up zeromq receiver connection
- self.receiver = context.socket(zmq.SUB)
- self.receiver.connect('tcp://localhost:4444')
- self.receiver.setsockopt(zmq.SUBSCRIBE, '')
- ## WHERE TO PUT THE ZEROMQ.POLLER() AND WHERE TO RECEIVE THE MESSAGE AND INVOKE THE currentSteerUpdate() METHOD?
- def initUI(self):
- steeringInstruction = QtGui.QSlider(QtCore.Qt.Horizontal, self)
- steeringInstruction.setTickPosition(QtGui.QSlider.TicksBothSides)
- steeringInstruction.setTickInterval(10)
- steeringInstruction.setFocusPolicy(QtCore.Qt.NoFocus)
- steeringInstruction.setRange(-100, 100)
- steeringInstruction.setGeometry(10, 40, 480, 30)
- steeringInstruction.valueChanged[int].connect(self.sendSteerInstruction)
- self.currentSteer = QtGui.QSlider(QtCore.Qt.Horizontal, self)
- self.currentSteer.setFocusPolicy(QtCore.Qt.NoFocus)
- self.currentSteer.setRange(-100, 100)
- self.currentSteer.setGeometry(10, 90, 480, 30)
- self.label = QtGui.QLabel('0', self)
- self.label.move(245, 5)
- self.label.setGeometry(245, 5, 30, 30)
- self.setGeometry(300, 300, 500, 150)
- self.setWindowTitle('Steering')
- self.show()
- def sendSteerInstruction(self, value):
- instructionObj = infoPack_pb2.steeringInstruction()
- instructionObj.steeringInstruction = value
- steeringPb = instructionObj.SerializeToString()
- self.publisher.send(steeringPb)
- self.label.setText(str(value))
- print(value)
- def currentSteerUpdate(self, message):
- currentSteerObj = infoPack_pb2.currentSteer()
- currentSteerObj.ParseFromString(message)
- self.currentSteer.setValue(currentSteerObj.currentSteer)
- def main():
- app = QtGui.QApplication(sys.argv)
- ex = Example()
- sys.exit(app.exec_())
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement