Last active
August 13, 2017 01:03
-
-
Save eyllanesc/c1e9e2f44757dfbce9e4aad3a9fd8a44 to your computer and use it in GitHub Desktop.
Promoted Widgets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5.QtCore import QSize, Qt | |
from PyQt5.QtGui import QPainter, QColor | |
from PyQt5.QtWidgets import QLabel, QWidget, QVBoxLayout, QApplication | |
class Led(QWidget): | |
def __init__(self, colorOn, colorOff, parent=None): | |
QLabel.__init__(self, parent) | |
self.colorOn = colorOn | |
self.colorOff = colorOff | |
self.state = False | |
def paintEvent(self, event): | |
painter = QPainter(self) | |
painter.setRenderHint(QPainter.Antialiasing) | |
painter.setBrush(self.colorOn if self.state else self.colorOff) | |
painter.drawEllipse(self.rect()) | |
def minimumSizeHint(self): | |
return QSize(60, 60) | |
def setState(self, state): | |
self.state = state | |
class LedWidget(QWidget): | |
def __init__(self, parent=None): | |
QWidget.__init__(self, parent) | |
text = "TEXT" | |
onColor = QColor("red") | |
offColor = QColor("green") | |
self.led = Led(onColor, offColor, self) | |
self.setLayout(QVBoxLayout()) | |
self.layout().addWidget(self.led) | |
label = QLabel(text, self) | |
label.setAlignment(Qt.AlignCenter) | |
self.layout().addWidget(label) | |
if __name__ == "__main__": | |
import sys | |
app = QApplication(sys.argv) | |
w = LedWidget("Text", QColor("red"), QColor("green")) | |
w.show() | |
sys.exit(app.exec_()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Form implementation generated from reading ui file 'main.ui' | |
# | |
# Created by: PyQt5 UI code generator 5.9 | |
# | |
# WARNING! All changes made in this file will be lost! | |
from PyQt5 import QtCore, QtGui, QtWidgets | |
class Ui_MainWindow(object): | |
def setupUi(self, MainWindow): | |
MainWindow.setObjectName("MainWindow") | |
MainWindow.resize(800, 600) | |
MainWindow.setStyleSheet("") | |
self.centralwidget = QtWidgets.QWidget(MainWindow) | |
self.centralwidget.setObjectName("centralwidget") | |
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.centralwidget) | |
self.horizontalLayout_2.setObjectName("horizontalLayout_2") | |
self.verticalLayout_2 = QtWidgets.QVBoxLayout() | |
self.verticalLayout_2.setSizeConstraint(QtWidgets.QLayout.SetMinimumSize) | |
self.verticalLayout_2.setObjectName("verticalLayout_2") | |
self.label_8 = QtWidgets.QLabel(self.centralwidget) | |
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred) | |
sizePolicy.setHorizontalStretch(0) | |
sizePolicy.setVerticalStretch(0) | |
sizePolicy.setHeightForWidth(self.label_8.sizePolicy().hasHeightForWidth()) | |
self.label_8.setSizePolicy(sizePolicy) | |
font = QtGui.QFont() | |
font.setPointSize(15) | |
font.setBold(True) | |
font.setWeight(75) | |
self.label_8.setFont(font) | |
self.label_8.setAlignment(QtCore.Qt.AlignCenter) | |
self.label_8.setObjectName("label_8") | |
self.verticalLayout_2.addWidget(self.label_8) | |
self.label_9 = QtWidgets.QLabel(self.centralwidget) | |
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) | |
sizePolicy.setHorizontalStretch(0) | |
sizePolicy.setVerticalStretch(0) | |
sizePolicy.setHeightForWidth(self.label_9.sizePolicy().hasHeightForWidth()) | |
self.label_9.setSizePolicy(sizePolicy) | |
font = QtGui.QFont() | |
font.setPointSize(15) | |
font.setBold(True) | |
font.setWeight(75) | |
self.label_9.setFont(font) | |
self.label_9.setAlignment(QtCore.Qt.AlignCenter) | |
self.label_9.setObjectName("label_9") | |
self.verticalLayout_2.addWidget(self.label_9) | |
self.label_10 = QtWidgets.QLabel(self.centralwidget) | |
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) | |
sizePolicy.setHorizontalStretch(0) | |
sizePolicy.setVerticalStretch(0) | |
sizePolicy.setHeightForWidth(self.label_10.sizePolicy().hasHeightForWidth()) | |
self.label_10.setSizePolicy(sizePolicy) | |
font = QtGui.QFont() | |
font.setPointSize(15) | |
font.setBold(True) | |
font.setWeight(75) | |
self.label_10.setFont(font) | |
self.label_10.setAlignment(QtCore.Qt.AlignCenter) | |
self.label_10.setObjectName("label_10") | |
self.verticalLayout_2.addWidget(self.label_10) | |
self.label_7 = QtWidgets.QLabel(self.centralwidget) | |
font = QtGui.QFont() | |
font.setPointSize(15) | |
font.setBold(True) | |
font.setWeight(75) | |
self.label_7.setFont(font) | |
self.label_7.setAlignment(QtCore.Qt.AlignCenter) | |
self.label_7.setObjectName("label_7") | |
self.verticalLayout_2.addWidget(self.label_7) | |
self.label_11 = QtWidgets.QLabel(self.centralwidget) | |
font = QtGui.QFont() | |
font.setPointSize(15) | |
font.setBold(True) | |
font.setWeight(75) | |
self.label_11.setFont(font) | |
self.label_11.setAlignment(QtCore.Qt.AlignCenter) | |
self.label_11.setObjectName("label_11") | |
self.verticalLayout_2.addWidget(self.label_11) | |
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) | |
self.verticalLayout_2.addItem(spacerItem) | |
self.verticalLayout = QtWidgets.QVBoxLayout() | |
self.verticalLayout.setObjectName("verticalLayout") | |
self.dial = QtWidgets.QDial(self.centralwidget) | |
self.dial.setObjectName("dial") | |
self.verticalLayout.addWidget(self.dial) | |
self.label = QtWidgets.QLabel(self.centralwidget) | |
self.label.setObjectName("label") | |
self.verticalLayout.addWidget(self.label) | |
self.onOffLoadDial = QtWidgets.QPushButton(self.centralwidget) | |
self.onOffLoadDial.setStyleSheet("#onOffLoadDial {background-color: red;\n" | |
"border-image: url(:/img/Power_off_icon.png);\n" | |
"background-repeat: no-repeat;\n" | |
"border-radius:30px;\n" | |
"max-width:65px;\n" | |
"max-height:65px;\n" | |
"min-width:65px;\n" | |
"min-height:65px;\n" | |
"}\n" | |
"\n" | |
"#onOffLoadDial:checked{\n" | |
"background-color: green;\\n\n" | |
"}") | |
self.onOffLoadDial.setText("") | |
self.onOffLoadDial.setObjectName("onOffLoadDial") | |
self.verticalLayout.addWidget(self.onOffLoadDial) | |
self.verticalLayout_2.addLayout(self.verticalLayout) | |
self.horizontalLayout_2.addLayout(self.verticalLayout_2) | |
self.verticalLayout_3 = QtWidgets.QVBoxLayout() | |
self.verticalLayout_3.setObjectName("verticalLayout_3") | |
self.gridLayout = QtWidgets.QGridLayout() | |
self.gridLayout.setObjectName("gridLayout") | |
self.widget_3 = dynPlot1(self.centralwidget) | |
self.widget_3.setStyleSheet("background-color: rgb(85, 170, 127);") | |
self.widget_3.setObjectName("widget_3") | |
self.gridLayout.addWidget(self.widget_3, 0, 0, 1, 1) | |
self.widget = dynPlot2(self.centralwidget) | |
self.widget.setStyleSheet("background-color: rgb(255, 85, 255);") | |
self.widget.setObjectName("widget") | |
self.gridLayout.addWidget(self.widget, 0, 1, 1, 1) | |
self.widget_2 = dynPlot3(self.centralwidget) | |
self.widget_2.setStyleSheet("background-color: rgb(255, 85, 0);") | |
self.widget_2.setObjectName("widget_2") | |
self.gridLayout.addWidget(self.widget_2, 1, 0, 1, 1) | |
self.widget_4 = dynPlot4(self.centralwidget) | |
self.widget_4.setStyleSheet("background-color: rgb(170, 85, 0);") | |
self.widget_4.setObjectName("widget_4") | |
self.gridLayout.addWidget(self.widget_4, 1, 1, 1, 1) | |
self.verticalLayout_3.addLayout(self.gridLayout) | |
self.horizontalLayout = QtWidgets.QHBoxLayout() | |
self.horizontalLayout.setObjectName("horizontalLayout") | |
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) | |
self.horizontalLayout.addItem(spacerItem1) | |
self.widget_5 = LedWidget(self.centralwidget) | |
self.widget_5.setMinimumSize(QtCore.QSize(0, 0)) | |
self.widget_5.setObjectName("widget_5") | |
self.horizontalLayout.addWidget(self.widget_5) | |
self.widget_6 = LedWidget(self.centralwidget) | |
self.widget_6.setMinimumSize(QtCore.QSize(0, 0)) | |
self.widget_6.setObjectName("widget_6") | |
self.horizontalLayout.addWidget(self.widget_6) | |
self.widget_7 = LedWidget(self.centralwidget) | |
self.widget_7.setMinimumSize(QtCore.QSize(0, 0)) | |
self.widget_7.setObjectName("widget_7") | |
self.horizontalLayout.addWidget(self.widget_7) | |
self.widget_8 = LedWidget(self.centralwidget) | |
self.widget_8.setMinimumSize(QtCore.QSize(0, 0)) | |
self.widget_8.setObjectName("widget_8") | |
self.horizontalLayout.addWidget(self.widget_8) | |
self.widget_9 = LedWidget(self.centralwidget) | |
self.widget_9.setMinimumSize(QtCore.QSize(0, 0)) | |
self.widget_9.setObjectName("widget_9") | |
self.horizontalLayout.addWidget(self.widget_9) | |
spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) | |
self.horizontalLayout.addItem(spacerItem2) | |
self.verticalLayout_3.addLayout(self.horizontalLayout) | |
self.horizontalLayout_2.addLayout(self.verticalLayout_3) | |
MainWindow.setCentralWidget(self.centralwidget) | |
self.menubar = QtWidgets.QMenuBar(MainWindow) | |
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22)) | |
self.menubar.setObjectName("menubar") | |
MainWindow.setMenuBar(self.menubar) | |
self.statusbar = QtWidgets.QStatusBar(MainWindow) | |
self.statusbar.setObjectName("statusbar") | |
MainWindow.setStatusBar(self.statusbar) | |
self.retranslateUi(MainWindow) | |
QtCore.QMetaObject.connectSlotsByName(MainWindow) | |
def retranslateUi(self, MainWindow): | |
_translate = QtCore.QCoreApplication.translate | |
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) | |
self.label_8.setText(_translate("MainWindow", "P")) | |
self.label_9.setText(_translate("MainWindow", "V")) | |
self.label_10.setText(_translate("MainWindow", "I")) | |
self.label_7.setText(_translate("MainWindow", "Temp")) | |
self.label_11.setText(_translate("MainWindow", "Q")) | |
self.label.setText(_translate("MainWindow", "TextLabel")) | |
from LedWidget import LedWidget | |
from plot import dynPlot1, dynPlot2, dynPlot3, dynPlot4 | |
import resources_rc | |
if __name__ == "__main__": | |
import sys | |
app = QtWidgets.QApplication(sys.argv) | |
MainWindow = QtWidgets.QMainWindow() | |
ui = Ui_MainWindow() | |
ui.setupUi(MainWindow) | |
MainWindow.show() | |
sys.exit(app.exec_()) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<ui version="4.0"> | |
<class>MainWindow</class> | |
<widget class="QMainWindow" name="MainWindow"> | |
<property name="geometry"> | |
<rect> | |
<x>0</x> | |
<y>0</y> | |
<width>800</width> | |
<height>600</height> | |
</rect> | |
</property> | |
<property name="windowTitle"> | |
<string>MainWindow</string> | |
</property> | |
<property name="styleSheet"> | |
<string notr="true"/> | |
</property> | |
<widget class="QWidget" name="centralwidget"> | |
<layout class="QHBoxLayout" name="horizontalLayout_2"> | |
<item> | |
<layout class="QVBoxLayout" name="verticalLayout_2"> | |
<property name="sizeConstraint"> | |
<enum>QLayout::SetMinimumSize</enum> | |
</property> | |
<item> | |
<widget class="QLabel" name="label_8"> | |
<property name="sizePolicy"> | |
<sizepolicy hsizetype="Minimum" vsizetype="Preferred"> | |
<horstretch>0</horstretch> | |
<verstretch>0</verstretch> | |
</sizepolicy> | |
</property> | |
<property name="font"> | |
<font> | |
<pointsize>15</pointsize> | |
<weight>75</weight> | |
<bold>true</bold> | |
</font> | |
</property> | |
<property name="text"> | |
<string>P</string> | |
</property> | |
<property name="alignment"> | |
<set>Qt::AlignCenter</set> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="QLabel" name="label_9"> | |
<property name="sizePolicy"> | |
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> | |
<horstretch>0</horstretch> | |
<verstretch>0</verstretch> | |
</sizepolicy> | |
</property> | |
<property name="font"> | |
<font> | |
<pointsize>15</pointsize> | |
<weight>75</weight> | |
<bold>true</bold> | |
</font> | |
</property> | |
<property name="text"> | |
<string>V</string> | |
</property> | |
<property name="alignment"> | |
<set>Qt::AlignCenter</set> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="QLabel" name="label_10"> | |
<property name="sizePolicy"> | |
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> | |
<horstretch>0</horstretch> | |
<verstretch>0</verstretch> | |
</sizepolicy> | |
</property> | |
<property name="font"> | |
<font> | |
<pointsize>15</pointsize> | |
<weight>75</weight> | |
<bold>true</bold> | |
</font> | |
</property> | |
<property name="text"> | |
<string>I</string> | |
</property> | |
<property name="alignment"> | |
<set>Qt::AlignCenter</set> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="QLabel" name="label_7"> | |
<property name="font"> | |
<font> | |
<pointsize>15</pointsize> | |
<weight>75</weight> | |
<bold>true</bold> | |
</font> | |
</property> | |
<property name="text"> | |
<string>Temp</string> | |
</property> | |
<property name="alignment"> | |
<set>Qt::AlignCenter</set> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="QLabel" name="label_11"> | |
<property name="font"> | |
<font> | |
<pointsize>15</pointsize> | |
<weight>75</weight> | |
<bold>true</bold> | |
</font> | |
</property> | |
<property name="text"> | |
<string>Q</string> | |
</property> | |
<property name="alignment"> | |
<set>Qt::AlignCenter</set> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<spacer name="verticalSpacer"> | |
<property name="orientation"> | |
<enum>Qt::Vertical</enum> | |
</property> | |
<property name="sizeHint" stdset="0"> | |
<size> | |
<width>20</width> | |
<height>40</height> | |
</size> | |
</property> | |
</spacer> | |
</item> | |
<item> | |
<layout class="QVBoxLayout" name="verticalLayout"> | |
<item> | |
<widget class="QDial" name="dial"/> | |
</item> | |
<item> | |
<widget class="QLabel" name="label"> | |
<property name="text"> | |
<string>TextLabel</string> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="QPushButton" name="onOffLoadDial"> | |
<property name="styleSheet"> | |
<string notr="true">#onOffLoadDial {background-color: red; | |
border-image: url(:/img/Power_off_icon.png); | |
background-repeat: no-repeat; | |
border-radius:30px; | |
max-width:65px; | |
max-height:65px; | |
min-width:65px; | |
min-height:65px; | |
} | |
#onOffLoadDial:checked{ | |
background-color: green;\n | |
}</string> | |
</property> | |
<property name="text"> | |
<string/> | |
</property> | |
</widget> | |
</item> | |
</layout> | |
</item> | |
</layout> | |
</item> | |
<item> | |
<layout class="QVBoxLayout" name="verticalLayout_3"> | |
<item> | |
<layout class="QGridLayout" name="gridLayout"> | |
<item row="0" column="0"> | |
<widget class="dynPlot1" name="widget_3" native="true"> | |
<property name="styleSheet"> | |
<string notr="true">background-color: rgb(85, 170, 127);</string> | |
</property> | |
</widget> | |
</item> | |
<item row="0" column="1"> | |
<widget class="dynPlot2" name="widget" native="true"> | |
<property name="styleSheet"> | |
<string notr="true">background-color: rgb(255, 85, 255);</string> | |
</property> | |
</widget> | |
</item> | |
<item row="1" column="0"> | |
<widget class="dynPlot3" name="widget_2" native="true"> | |
<property name="styleSheet"> | |
<string notr="true">background-color: rgb(255, 85, 0);</string> | |
</property> | |
</widget> | |
</item> | |
<item row="1" column="1"> | |
<widget class="dynPlot4" name="widget_4" native="true"> | |
<property name="styleSheet"> | |
<string notr="true">background-color: rgb(170, 85, 0);</string> | |
</property> | |
</widget> | |
</item> | |
</layout> | |
</item> | |
<item> | |
<layout class="QHBoxLayout" name="horizontalLayout"> | |
<item> | |
<spacer name="horizontalSpacer"> | |
<property name="orientation"> | |
<enum>Qt::Horizontal</enum> | |
</property> | |
<property name="sizeHint" stdset="0"> | |
<size> | |
<width>40</width> | |
<height>20</height> | |
</size> | |
</property> | |
</spacer> | |
</item> | |
<item> | |
<widget class="LedWidget" name="widget_5" native="true"> | |
<property name="minimumSize"> | |
<size> | |
<width>0</width> | |
<height>0</height> | |
</size> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="LedWidget" name="widget_6" native="true"> | |
<property name="minimumSize"> | |
<size> | |
<width>0</width> | |
<height>0</height> | |
</size> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="LedWidget" name="widget_7" native="true"> | |
<property name="minimumSize"> | |
<size> | |
<width>0</width> | |
<height>0</height> | |
</size> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="LedWidget" name="widget_8" native="true"> | |
<property name="minimumSize"> | |
<size> | |
<width>0</width> | |
<height>0</height> | |
</size> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="LedWidget" name="widget_9" native="true"> | |
<property name="minimumSize"> | |
<size> | |
<width>0</width> | |
<height>0</height> | |
</size> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<spacer name="horizontalSpacer_2"> | |
<property name="orientation"> | |
<enum>Qt::Horizontal</enum> | |
</property> | |
<property name="sizeHint" stdset="0"> | |
<size> | |
<width>40</width> | |
<height>20</height> | |
</size> | |
</property> | |
</spacer> | |
</item> | |
</layout> | |
</item> | |
</layout> | |
</item> | |
</layout> | |
</widget> | |
<widget class="QMenuBar" name="menubar"> | |
<property name="geometry"> | |
<rect> | |
<x>0</x> | |
<y>0</y> | |
<width>800</width> | |
<height>22</height> | |
</rect> | |
</property> | |
</widget> | |
<widget class="QStatusBar" name="statusbar"/> | |
</widget> | |
<customwidgets> | |
<customwidget> | |
<class>dynPlot1</class> | |
<extends>QWidget</extends> | |
<header>plot.h</header> | |
<container>1</container> | |
</customwidget> | |
<customwidget> | |
<class>dynPlot2</class> | |
<extends>QWidget</extends> | |
<header>plot.h</header> | |
<container>1</container> | |
</customwidget> | |
<customwidget> | |
<class>dynPlot3</class> | |
<extends>QWidget</extends> | |
<header>plot.h</header> | |
<container>1</container> | |
</customwidget> | |
<customwidget> | |
<class>dynPlot4</class> | |
<extends>QWidget</extends> | |
<header>plot.h</header> | |
<container>1</container> | |
</customwidget> | |
<customwidget> | |
<class>LedWidget</class> | |
<extends>QWidget</extends> | |
<header>LedWidget.h</header> | |
<container>1</container> | |
</customwidget> | |
</customwidgets> | |
<resources/> | |
<connections/> | |
</ui> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,3, | |
2,4, | |
3,5, | |
4,6, | |
5,7, | |
6,9, | |
7,10, | |
8,120, | |
9,110, | |
10,124, | |
11,122, | |
12,125, | |
13,120, | |
14,122, | |
15,123, | |
16,119, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,2, | |
2,4, | |
3,6, | |
4,8, | |
5,6, | |
6,7, | |
7,4, | |
8,9, | |
9,4, | |
10,3, | |
11,8, | |
12,5, | |
13,2, | |
14,6, | |
15,9, | |
16,7, | |
17,4, | |
18,3, | |
19,6, | |
20,3, | |
22,7, | |
23,8, | |
24,6, | |
25,9, | |
26,3, | |
27,50, | |
28,55, | |
29,100, | |
30,12, | |
31,20, | |
32,1, | |
33,4, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,2, | |
2,4, | |
3,6, | |
4,8, | |
5,6, | |
6,7, | |
7,4, | |
8,9, | |
9,4, | |
10,3, | |
11,8, | |
12,5, | |
13,2, | |
14,6, | |
15,9, | |
16,7, | |
17,4, | |
18,3, | |
19,6, | |
20,3, | |
22,7, | |
23,8, | |
24,6, | |
25,9, | |
26,3, | |
27,50, | |
28,55, | |
29,100, | |
30,12, | |
31,20, | |
32,1, | |
33,4, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,2, | |
2,4, | |
3,6, | |
4,8, | |
5,6, | |
6,7, | |
7,4, | |
8,9, | |
9,4, | |
10,3, | |
11,8, | |
12,5, | |
13,2, | |
14,6, | |
15,9, | |
16,7, | |
17,4, | |
18,3, | |
19,6, | |
20,3, | |
22,7, | |
23,8, | |
24,6, | |
25,9, | |
26,3, | |
27,50, | |
28,55, | |
29,100, | |
30,12, | |
31,20, | |
32,1, | |
33,4, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib | |
from PyQt5.QtCore import QTimer, QSize | |
matplotlib.use("Qt5Agg") | |
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas | |
from matplotlib.figure import Figure | |
from PyQt5.QtWidgets import QSizePolicy | |
class mplCanvas(FigureCanvas): | |
def __init__(self, parent=None, width=5, height=4, dpi=100): | |
fig = Figure(figsize=(width, height), dpi=dpi) | |
self.axes = fig.add_subplot(111) | |
# we clear the screen otherwise we run out of memory. | |
self.compute_initial_figure() | |
FigureCanvas.__init__(self, fig) | |
self.setParent(parent) | |
FigureCanvas.setSizePolicy(self, | |
QSizePolicy.Expanding, | |
QSizePolicy.Expanding) | |
FigureCanvas.updateGeometry(self) | |
timer = QTimer(self) | |
timer.timeout.connect(self.update_figure) | |
timer.start(500) | |
def minimumSizeHint(self): | |
return QSize(500, 450) | |
def compute_initial_figure(self): | |
pass | |
def update_figure(self): | |
pass | |
# ----------------------------------------------------------------- | |
# Each plot has one of these. | |
# Outlet 1 POWER | |
class dynPlot1(mplCanvas): | |
def __init__(self, *args, **kwargs): | |
mplCanvas.__init__(self, *args, **kwargs) | |
def compute_initial_figure(self): | |
self.axes.plot([0, 1, 2, 3], [0, 1, 2, 3], 'r') | |
def update_figure(self): | |
self.axes.clear() | |
f = open('outlet1.txt', 'r') | |
d = f.readlines() | |
f.close() | |
x = [] | |
y = [] | |
for i in range(len(d)): | |
hold = d[i].split(',') | |
x.append(float(hold[0])) | |
y.append(float(hold[1])) | |
self.axes.plot(x, y, 'r', label='Voltage (V)') | |
self.axes.set_xlabel('Time (s)') | |
self.axes.set_ylabel('Voltage (V)') | |
###Legend on plot | |
self.axes.legend(loc='upper left') | |
self.draw() | |
# Outlet 2 VOltage | |
class dynPlot2(mplCanvas): | |
def __init__(self, *args, **kwargs): | |
mplCanvas.__init__(self, *args, **kwargs) | |
def compute_initial_figure(self): | |
self.axes.plot([0, 1, 2, 3], [0, 1, 2, 3], 'r') | |
def update_figure(self): | |
self.axes.clear() | |
f = open('outlet2.txt', 'r') | |
d = f.readlines() | |
f.close() | |
x = [] | |
y = [] | |
for i in range(len(d)): | |
hold = d[i].split(',') | |
x.append(float(hold[0])) | |
y.append(float(hold[1])) | |
self.axes.plot(x, y, 'r', label='Power (W)') | |
self.axes.set_xlabel('Time (s)') | |
self.axes.set_ylabel('Power (W)') | |
###Legend on plot | |
self.axes.legend(loc='upper left') | |
self.draw() | |
# CUrrent | |
class dynPlot3(mplCanvas): | |
def __init__(self, *args, **kwargs): | |
mplCanvas.__init__(self, *args, **kwargs) | |
def compute_initial_figure(self): | |
self.axes.plot([0, 1, 2, 3], [0, 1, 2, 3], 'r') | |
def update_figure(self): | |
self.axes.clear() | |
f = open('outlet2.txt', 'r') | |
d = f.readlines() | |
f.close() | |
x = [] | |
y = [] | |
for i in range(len(d)): | |
hold = d[i].split(',') | |
x.append(float(hold[0])) | |
y.append(float(hold[1])) | |
self.axes.plot(x, y, 'r', label='Current (A)') | |
self.axes.set_xlabel('Time (s)') | |
self.axes.set_ylabel('Current (A)') | |
self.axes.legend(loc='upper left') | |
self.draw() | |
# Temperature | |
class dynPlot4(mplCanvas): | |
def __init__(self, *args, **kwargs): | |
mplCanvas.__init__(self, *args, **kwargs) | |
def compute_initial_figure(self): | |
self.axes.plot([0, 1, 2, 3], [0, 1, 2, 3], 'r') | |
def update_figure(self): | |
self.axes.clear() | |
f = open('outlet2.txt', 'r') | |
d = f.readlines() | |
f.close() | |
x = [] | |
y = [] | |
for i in range(len(d)): | |
hold = d[i].split(',') | |
x.append(float(hold[0])) | |
y.append(float(hold[1])) | |
self.axes.plot(x, y, 'r', label='Temperature (F)') | |
self.axes.set_xlabel('Time (s)') | |
self.axes.set_ylabel('Temperature (F)') | |
self.axes.legend(loc='upper left') | |
self.draw() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the current output I get, I recommend you review how to promote widgets with Qt Designer for PyQt