Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PySide import QtCore, QtGui
- import zmq
- #import infoPack_pb2
- class SlidersGroup(QtGui.QGroupBox):
- valueChanged = QtCore.Signal(int)
- def __init__(self, orientation, title, parent=None):
- super(SlidersGroup, self).__init__(title, parent)
- self.slider = QtGui.QSlider(orientation)
- self.slider.setFocusPolicy(QtCore.Qt.StrongFocus)
- self.slider.setTickPosition(QtGui.QSlider.TicksBothSides)
- self.slider.setTickInterval(10)
- self.slider.setSingleStep(1)
- self.scrollBar = QtGui.QScrollBar(orientation)
- self.scrollBar.setFocusPolicy(QtCore.Qt.StrongFocus)
- self.dial = QtGui.QDial()
- self.dial.setFocusPolicy(QtCore.Qt.StrongFocus)
- self.slider.valueChanged.connect(self.scrollBar.setValue)
- self.scrollBar.valueChanged.connect(self.dial.setValue)
- self.dial.valueChanged.connect(self.slider.setValue)
- self.dial.valueChanged.connect(self.valueChanged)
- direction = QtGui.QBoxLayout.TopToBottom
- slidersLayout = QtGui.QBoxLayout(direction)
- slidersLayout.addWidget(self.slider)
- slidersLayout.addWidget(self.scrollBar)
- slidersLayout.addWidget(self.dial)
- self.setLayout(slidersLayout)
- def setValue(self, value):
- self.slider.setValue(value)
- def setMinimum(self, value):
- self.slider.setMinimum(value)
- self.scrollBar.setMinimum(value)
- self.dial.setMinimum(value)
- def setMaximum(self, value):
- self.slider.setMaximum(value)
- self.scrollBar.setMaximum(value)
- self.dial.setMaximum(value)
- # Set up connection with zeromq
- context = zmq.Context()
- self.publisher = context.socket(zmq.PUB)
- self.publisher.connect('tcp://localhost:2000')
- class Window(QtGui.QWidget):
- def __init__(self):
- super(Window, self).__init__()
- self.horizontalSliders = SlidersGroup(QtCore.Qt.Horizontal, "Steering Control")
- self.stackedWidget = QtGui.QStackedWidget()
- self.stackedWidget.addWidget(self.horizontalSliders)
- self.createControls("Controls")
- layout = QtGui.QHBoxLayout()
- layout.addWidget(self.stackedWidget)
- self.setLayout(layout)
- self.minimumSpinBox.setValue(-100)
- self.maximumSpinBox.setValue(100)
- self.setWindowTitle("Control Unit")
- def createControls(self, title):
- self.controlsGroup = QtGui.QGroupBox(title)
- self.minimumSpinBox = QtGui.QSpinBox()
- self.minimumSpinBox.setRange(-100, 100)
- self.minimumSpinBox.setSingleStep(1)
- self.maximumSpinBox = QtGui.QSpinBox()
- self.maximumSpinBox.setRange(-100, 100)
- self.maximumSpinBox.setSingleStep(1)
- self.minimumSpinBox.valueChanged.connect(self.horizontalSliders.setMinimum)
- self.maximumSpinBox.valueChanged.connect(self.horizontalSliders.setMaximum)
- controlsLayout = QtGui.QGridLayout()
- self.controlsGroup.setLayout(controlsLayout)
- ## I HERE NEED TO READ OUT THE VALUES FROM THE SLIDER AND SEND THEM SOMEWHERE USING ZEROMQ
- #instruction = infoPack_pb2.steeringInstruction()
- #instruction.steeringInstruction = i
- #steeringPb = instruction.SerializeToString()
- #publisher.send(steeringPb)
- if __name__ == '__main__':
- import sys
- app = QtGui.QApplication(sys.argv)
- window = Window()
- window.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement