Commits

wump committed 771cc3b

Add qt-based color selector

Comments (0)

Files changed (1)

+'''
+Qt4-based color selection UI for AMBX.
+(C) W.J. van der Laan 2011
+'''
+from PyQt4 import QtCore, QtGui
+from PyQt4.QtCore import Qt
+import logging
+from ambx.ambx import AMBX, Lights
+
+logger = logging.getLogger("gui")
+
+class MainWindow(QtGui.QWidget):
+    def __init__(self, parent=None):
+        QtGui.QWidget.__init__(self, parent)
+        self.dev = None # Must be set
+
+        self.resize(600, 400)
+        self.setWindowTitle('AMBX color selector')
+        
+        layout = QtGui.QHBoxLayout(self)
+
+        self._lampsel = QtGui.QListWidget()
+        self._lampsel.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
+        self.addLamps(self._lampsel)
+        layout.addWidget(self._lampsel)
+
+        self._colorsel = QtGui.QColorDialog()
+        self._colorsel.setOption(QtGui.QColorDialog.NoButtons)
+        layout.addWidget(self._colorsel)
+
+        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)
+
+        widget.addItem(left)
+        widget.addItem(right)
+        widget.addItem(wwleft)
+        widget.addItem(wwcenter)
+        widget.addItem(wwright)
+
+    def doColorChanged(self, color):
+        color = [color.red(), color.green(), color.blue()]
+        for idx in self._lampsel.selectedIndexes():
+            lamp_id = idx.data(Qt.UserRole).toInt()[0]
+            self.dev.set_color_rgb8(lamp_id, color)
+
+
+
+def main(args):
+    logging.basicConfig(level=logging.DEBUG,
+            datefmt='%a, %d %b %Y %H:%M:%S',
+            format='%(asctime)s %(levelname)-8s %(name)-8s %(message)s',
+            stream=sys.stdout)
+
+    dev = AMBX(0)
+    app = QtGui.QApplication(args)
+    window = MainWindow()
+    window.dev = dev
+    window.show()
+    return app.exec_()
+
+if __name__ == '__main__':
+    import sys
+    exit(main(sys.argv))