wump avatar wump committed a78037c

add buttons to select multiple lights

Comments (0)

Files changed (1)

         self._lampsel = QtGui.QListWidget()
         self._lampsel.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
         self.addLamps(self._lampsel)
-        layout.addWidget(self._lampsel)
+
+        button_left = QtGui.QPushButton('All left')
+        button_wallwasher = QtGui.QPushButton('All WW')
+        button_right = QtGui.QPushButton('All Right')
+
+        vlayout = QtGui.QVBoxLayout()
+        vlayout.addWidget(self._lampsel)
+        vlayout.addWidget(button_left)
+        vlayout.addWidget(button_wallwasher)
+        vlayout.addWidget(button_right)
+
+        layout.addLayout(vlayout)
 
         self._colorsel = QtGui.QColorDialog()
         self._colorsel.setOption(QtGui.QColorDialog.NoButtons)
         layout.addWidget(self._colorsel)
 
+        button_left.clicked.connect(
+            self.lightSetter([self.lamp_left, self.lamp_wwleft]))
+        button_wallwasher.clicked.connect(
+            self.lightSetter([self.lamp_wwleft, self.lamp_wwcenter, self.lamp_wwright]))
+        button_right.clicked.connect(
+            self.lightSetter([self.lamp_right, self.lamp_wwright]))
         self._colorsel.currentColorChanged.connect(self.doColorChanged)
 
     def addLamps(self, widget):
-        left = QtGui.QListWidgetItem('Left')
-        left.setData(Qt.UserRole, Lights.LEFT)
-        right = QtGui.QListWidgetItem('Right')
-        right.setData(Qt.UserRole, Lights.RIGHT)
-        wwleft = QtGui.QListWidgetItem('WW-Left')
-        wwleft.setData(Qt.UserRole, Lights.WWLEFT)
-        wwcenter = QtGui.QListWidgetItem('WW-Center')
-        wwcenter.setData(Qt.UserRole, Lights.WWCENTER)
-        wwright = QtGui.QListWidgetItem('WW-Right')
-        wwright.setData(Qt.UserRole, Lights.WWRIGHT)
+        self.lamp_left = QtGui.QListWidgetItem('Left')
+        self.lamp_left.setData(Qt.UserRole, Lights.LEFT)
+        self.lamp_right = QtGui.QListWidgetItem('Right')
+        self.lamp_right.setData(Qt.UserRole, Lights.RIGHT)
+        self.lamp_wwleft = QtGui.QListWidgetItem('WW-Left')
+        self.lamp_wwleft.setData(Qt.UserRole, Lights.WWLEFT)
+        self.lamp_wwcenter = QtGui.QListWidgetItem('WW-Center')
+        self.lamp_wwcenter.setData(Qt.UserRole, Lights.WWCENTER)
+        self.lamp_wwright = QtGui.QListWidgetItem('WW-Right')
+        self.lamp_wwright.setData(Qt.UserRole, Lights.WWRIGHT)
 
-        widget.addItem(left)
-        widget.addItem(right)
-        widget.addItem(wwleft)
-        widget.addItem(wwcenter)
-        widget.addItem(wwright)
+        widget.addItem(self.lamp_left)
+        widget.addItem(self.lamp_right)
+        widget.addItem(self.lamp_wwleft)
+        widget.addItem(self.lamp_wwcenter)
+        widget.addItem(self.lamp_wwright)
 
     def doColorChanged(self, color):
         color = [color.red(), color.green(), color.blue()]
             lamp_id = idx.data(Qt.UserRole).toInt()[0]
             self.dev.set_color_rgb8(lamp_id, color)
 
+    def lightSetter(self, lights):
+        def function():
+            self._lampsel.selectionModel().clear()
+            for light in lights:
+                light.setSelected(True)
+        return function
+
 
 
 def main(args):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.