Advertisement
Guest User

How to read out sliders

a guest
Apr 1st, 2013
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.55 KB | None | 0 0
  1. from PySide import QtCore, QtGui
  2. import zmq
  3. #import infoPack_pb2
  4.        
  5. class SlidersGroup(QtGui.QGroupBox):
  6.  
  7.     valueChanged = QtCore.Signal(int)
  8.  
  9.     def __init__(self, orientation, title, parent=None):
  10.         super(SlidersGroup, self).__init__(title, parent)
  11.  
  12.         self.slider = QtGui.QSlider(orientation)
  13.         self.slider.setFocusPolicy(QtCore.Qt.StrongFocus)
  14.         self.slider.setTickPosition(QtGui.QSlider.TicksBothSides)
  15.         self.slider.setTickInterval(10)
  16.         self.slider.setSingleStep(1)
  17.  
  18.         self.scrollBar = QtGui.QScrollBar(orientation)
  19.         self.scrollBar.setFocusPolicy(QtCore.Qt.StrongFocus)
  20.  
  21.         self.dial = QtGui.QDial()
  22.         self.dial.setFocusPolicy(QtCore.Qt.StrongFocus)
  23.  
  24.         self.slider.valueChanged.connect(self.scrollBar.setValue)
  25.         self.scrollBar.valueChanged.connect(self.dial.setValue)
  26.         self.dial.valueChanged.connect(self.slider.setValue)
  27.         self.dial.valueChanged.connect(self.valueChanged)
  28.  
  29.         direction = QtGui.QBoxLayout.TopToBottom
  30.  
  31.         slidersLayout = QtGui.QBoxLayout(direction)
  32.         slidersLayout.addWidget(self.slider)
  33.         slidersLayout.addWidget(self.scrollBar)
  34.         slidersLayout.addWidget(self.dial)
  35.         self.setLayout(slidersLayout)
  36.  
  37.     def setValue(self, value):    
  38.         self.slider.setValue(value)    
  39.  
  40.     def setMinimum(self, value):    
  41.         self.slider.setMinimum(value)
  42.         self.scrollBar.setMinimum(value)
  43.         self.dial.setMinimum(value)    
  44.  
  45.     def setMaximum(self, value):    
  46.         self.slider.setMaximum(value)
  47.         self.scrollBar.setMaximum(value)
  48.         self.dial.setMaximum(value)    
  49.        
  50.         # Set up connection with zeromq
  51.         context = zmq.Context()
  52.         self.publisher = context.socket(zmq.PUB)
  53.         self.publisher.connect('tcp://localhost:2000')
  54.  
  55. class Window(QtGui.QWidget):
  56.     def __init__(self):
  57.         super(Window, self).__init__()
  58.  
  59.         self.horizontalSliders = SlidersGroup(QtCore.Qt.Horizontal, "Steering Control")
  60.  
  61.         self.stackedWidget = QtGui.QStackedWidget()
  62.         self.stackedWidget.addWidget(self.horizontalSliders)
  63.  
  64.         self.createControls("Controls")
  65.  
  66.         layout = QtGui.QHBoxLayout()
  67.         layout.addWidget(self.stackedWidget)
  68.         self.setLayout(layout)
  69.  
  70.         self.minimumSpinBox.setValue(-100)
  71.         self.maximumSpinBox.setValue(100)
  72.  
  73.         self.setWindowTitle("Control Unit")
  74.  
  75.     def createControls(self, title):
  76.         self.controlsGroup = QtGui.QGroupBox(title)
  77.  
  78.         self.minimumSpinBox = QtGui.QSpinBox()
  79.         self.minimumSpinBox.setRange(-100, 100)
  80.         self.minimumSpinBox.setSingleStep(1)
  81.  
  82.         self.maximumSpinBox = QtGui.QSpinBox()
  83.         self.maximumSpinBox.setRange(-100, 100)
  84.         self.maximumSpinBox.setSingleStep(1)
  85.        
  86.         self.minimumSpinBox.valueChanged.connect(self.horizontalSliders.setMinimum)        
  87.         self.maximumSpinBox.valueChanged.connect(self.horizontalSliders.setMaximum)
  88.  
  89.         controlsLayout = QtGui.QGridLayout()
  90.        
  91.         self.controlsGroup.setLayout(controlsLayout)
  92.        
  93.         ## I HERE NEED TO READ OUT THE VALUES FROM THE SLIDER AND SEND THEM SOMEWHERE USING ZEROMQ
  94.         #instruction = infoPack_pb2.steeringInstruction()
  95.         #instruction.steeringInstruction = i
  96.         #steeringPb = instruction.SerializeToString()
  97.         #publisher.send(steeringPb)
  98.  
  99.  
  100. if __name__ == '__main__':
  101.  
  102.     import sys
  103.  
  104.     app = QtGui.QApplication(sys.argv)
  105.     window = Window()
  106.     window.show()
  107.     sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement