|
@@ -1 +1,161 @@
|
|
|
-__author__ = 'blaxxun'
|
|
|
+from PyQt4 import QtGui, QtCore
|
|
|
+import logging
|
|
|
+
|
|
|
+import kcgwidget as kcgw
|
|
|
+
|
|
|
+# class StatusLED(QtGui.QWidget):
|
|
|
+# def __init__(self, status):
|
|
|
+# super(StatusLED, self).__init__()
|
|
|
+# self.pixmap_on = QtGui.QPixmap('images/led_on.jpg')
|
|
|
+# self.pixmap_off = QtGui.QPixmap('images/led_off.jpg')
|
|
|
+# self.led = QtGui.QLabel()
|
|
|
+# if status:
|
|
|
+# self.set_on()
|
|
|
+# else:
|
|
|
+# self.set_off()
|
|
|
+# def set_on(self):
|
|
|
+# self.led.setPixmap(self.pixmap_on)
|
|
|
+# def set_off(self):
|
|
|
+# self.led.setPixmap(self.pixmap_off)
|
|
|
+
|
|
|
+class LED(QtGui.QWidget):
|
|
|
+
|
|
|
+ def __init__(self, parent=None, status=None, height=10, width=10):
|
|
|
+ QtGui.QWidget.__init__(self, parent)
|
|
|
+ colorRGB=(255, 0, 0)
|
|
|
+ self.width = width
|
|
|
+ self.height = height
|
|
|
+ self.color = QtGui.QColor(colorRGB[0], colorRGB[1], colorRGB[2])
|
|
|
+ self.center = QtCore.QPoint(width, height)
|
|
|
+ self.setMinimumSize(2 * width, 2 * height)
|
|
|
+ self.setMaximumSize(2 * width, 2 * height)
|
|
|
+ if status:
|
|
|
+ self.set_on()
|
|
|
+ elif status == False:
|
|
|
+ self.set_off()
|
|
|
+ else:
|
|
|
+ self.set_out()
|
|
|
+ self.status = status
|
|
|
+
|
|
|
+ def paintEvent(self, event):
|
|
|
+ paint = QtGui.QPainter()
|
|
|
+ paint.begin(self)
|
|
|
+ paint.setRenderHint(QtGui.QPainter.Antialiasing)
|
|
|
+
|
|
|
+ # draw a grey 'socket' for the LED
|
|
|
+ paint.setPen(QtGui.QColor(160, 160, 160))
|
|
|
+ paint.setBrush(QtGui.QColor(180, 180, 180))
|
|
|
+ paint.drawEllipse(self.center, self.width, self.height)
|
|
|
+
|
|
|
+ # draw the body of the LED
|
|
|
+ paint.setBrush(self.color)
|
|
|
+ paint.drawEllipse(self.center, self.width*0.85, self.height*0.85)
|
|
|
+
|
|
|
+ def set_on(self):
|
|
|
+ self.color = QtGui.QColor(0, 255, 0)
|
|
|
+ self.update()
|
|
|
+ self.status = True
|
|
|
+ def set_off(self):
|
|
|
+ self.color = QtGui.QColor(255, 0, 0)
|
|
|
+ self.update()
|
|
|
+ self.status = False
|
|
|
+ def set_out(self):
|
|
|
+ self.color = QtGui.QColor(150, 150, 150)
|
|
|
+ self.update()
|
|
|
+ self.status = None
|
|
|
+
|
|
|
+class StatusLED(QtGui.QWidget):
|
|
|
+ def __init__(self, text, status=None):
|
|
|
+ super(StatusLED, self).__init__()
|
|
|
+ self.layout = QtGui.QHBoxLayout()
|
|
|
+ self.label = QtGui.QLabel(text)
|
|
|
+ self.led = LED(status=status, width=9, height=9)
|
|
|
+ self.layout.addWidget(self.led)
|
|
|
+ self.layout.addWidget(self.label)
|
|
|
+ self.setLayout(self.layout)
|
|
|
+ def set_on(self):
|
|
|
+ self.led.set_on()
|
|
|
+ def set_off(self):
|
|
|
+ self.led.set_off()
|
|
|
+ def set_out(self):
|
|
|
+ self.led.set_out()
|
|
|
+ def toggle(self):
|
|
|
+ if self.led.status:
|
|
|
+ self.led.set_off()
|
|
|
+ elif self.led.status == False:
|
|
|
+ self.led.set_on()
|
|
|
+ else:
|
|
|
+ self.led.set_on()
|
|
|
+
|
|
|
+class LogHandler(logging.Handler):
|
|
|
+ def __init__(self, log_area):
|
|
|
+ logging.Handler.__init__(self)
|
|
|
+ self.text_area = log_area
|
|
|
+
|
|
|
+ def emit(self, record):
|
|
|
+ self.text_area.append(self.format(record))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class ControlWidget(kcgw.KCGWidgets):
|
|
|
+ def __init__(self):
|
|
|
+ super(ControlWidget, self).__init__()
|
|
|
+
|
|
|
+ self.initUi()
|
|
|
+
|
|
|
+ def dummy_button_press_function(self, w=None):
|
|
|
+ logging.info("Button Pressed - {}".format(w))
|
|
|
+ def initUi(self):
|
|
|
+ self.overlayout = QtGui.QVBoxLayout()
|
|
|
+ self.setLayout(self.overlayout)
|
|
|
+ self.layout = QtGui.QHBoxLayout()
|
|
|
+ self.overlayout.addLayout(self.layout)
|
|
|
+ self.overlayout.addStretch(1)
|
|
|
+
|
|
|
+ self.gridLayout = QtGui.QGridLayout()
|
|
|
+ self.gridLayout.addWidget(self.createLabel("Board Control"), 0, 0)
|
|
|
+ self.gridLayout.addWidget(self.createLabel("Board Status"), 0, 1)
|
|
|
+
|
|
|
+ # LED Status
|
|
|
+ self.pipeline_led = StatusLED("DataFlow Pipeline")
|
|
|
+ self.master_control_led = StatusLED("Master Control")
|
|
|
+ self.data_check_led = StatusLED("Data Check")
|
|
|
+ self.pll_ld_led = StatusLED("PLL_LD")
|
|
|
+ self.gridLayout.addWidget(self.pipeline_led, 1, 1)
|
|
|
+ self.gridLayout.addWidget(self.master_control_led, 2, 1)
|
|
|
+ self.gridLayout.addWidget(self.data_check_led, 3, 1)
|
|
|
+ self.gridLayout.addWidget(self.pll_ld_led, 4, 1)
|
|
|
+
|
|
|
+ # Buttons
|
|
|
+ self.gridLayout.addWidget(self.createButton(text="Start Board", connect=lambda: self.dummy_button_press_function(1)), 1, 0)
|
|
|
+ self.gridLayout.addWidget(self.createButton(text="Calibrate", connect=lambda: self.dummy_button_press_function(2)), 2, 0)
|
|
|
+ self.gridLayout.addWidget(self.createButton(text="Synchronize", connect=lambda: self.dummy_button_press_function(3)), 3, 0)
|
|
|
+ self.gridLayout.addWidget(self.createButton(text="Set Defaults", connect=lambda: self.dummy_button_press_function(4)), 4, 0)
|
|
|
+ self.gridLayout.addWidget(self.createButton(text="Soft Reset", connect=lambda: self.dummy_button_press_function(5)), 5, 0)
|
|
|
+ self.gridLayout.addWidget(self.createButton(text="Board Off", connect=lambda: self.dummy_button_press_function(6)), 6, 0)
|
|
|
+ self.gridLayout.addWidget(self.createButton(text="Check Status", connect=self.on_check), 5, 1)
|
|
|
+
|
|
|
+
|
|
|
+ self.layout.addLayout(self.gridLayout)
|
|
|
+ self.layout.addStretch(1)
|
|
|
+ self.log_area = QtGui.QTextEdit()
|
|
|
+ self.log_area.setReadOnly(True)
|
|
|
+ self.overlayout.addWidget(self.log_area)
|
|
|
+
|
|
|
+ # Logging
|
|
|
+ log_handler = LogHandler(self.log_area)
|
|
|
+ log_handler.setFormatter(logging.Formatter('%(asctime)s - %(funcName)s(): %(message)s'))
|
|
|
+ self.logger = logging.getLogger()
|
|
|
+ self.logger.addHandler(log_handler)
|
|
|
+ self.logger.setLevel(logging.INFO)
|
|
|
+
|
|
|
+ def on_check(self):
|
|
|
+ import random
|
|
|
+ r = [random.random()+0.5 for i in range(4)]
|
|
|
+ ledlist = [self.pipeline_led, self.master_control_led, self.data_check_led, self.pll_ld_led]
|
|
|
+ for i, led in enumerate(ledlist):
|
|
|
+ if int(r[i]) == 1:
|
|
|
+ led.set_on()
|
|
|
+ else:
|
|
|
+ led.set_off()
|
|
|
+ logging.info("Checked: {}".format(str([int(i) for i in r])))
|