From b4447145040c7df3fe7cf911c32e05a3814b0908 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Kopper Date: Mon, 15 Apr 2019 17:30:01 -0300 Subject: [PATCH] Initial commit 2 --- Pipfile | 15 +++ SADAMAP.py | 6 +- interfaces/Mock.py | 5 + .../UI/CalibracaoPressaoW.ui | 107 ++++++++++++++---- threads/MainThread.py | 29 +++++ .../CalibracaoPressaoW.py | 67 +++++++---- MainWindow.py => ui/MainWindow.py | 7 +- 7 files changed, 189 insertions(+), 47 deletions(-) create mode 100644 Pipfile create mode 100644 interfaces/Mock.py rename {Resources => resources}/UI/CalibracaoPressaoW.ui (91%) create mode 100644 threads/MainThread.py rename CalibracaoPressaoW.py => ui/CalibracaoPressaoW.py (86%) rename MainWindow.py => ui/MainWindow.py (51%) diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..eeff6a1 --- /dev/null +++ b/Pipfile @@ -0,0 +1,15 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +pyqtgraph = "*" +numpy = "*" +pyserial = "*" +pyqt5 = "*" + +[requires] +python_version = "3.5" diff --git a/SADAMAP.py b/SADAMAP.py index 24344ec..25d985f 100644 --- a/SADAMAP.py +++ b/SADAMAP.py @@ -1,14 +1,14 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Classe Main (Principal) # -# Autor: Alisson Claudino (alisson.claudino@ufrgs.br) -> https://lief.if.ufrgs.br/~itsalissom # +# Autores: Pedro Henrique Kopper (pedro.kopper@ufrgs.br) -> https://lief.if.ufrgs.br/~phckopper # +# Alisson Claudino (alisson.claudino@ufrgs.br) -> https://lief.if.ufrgs.br/~itsalissom # Licença: GNU GPLv2 # # Propósito: Inicializar o programa # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # import sys -from MainWindow import Ui_MainWindow +from ui.MainWindow import Ui_MainWindow if __name__ == '__main__': mainWindow = Ui_MainWindow() - #engine=SystemEngine() sys.exit(mainWindow.app.exec_()) diff --git a/interfaces/Mock.py b/interfaces/Mock.py new file mode 100644 index 0000000..a8bbe64 --- /dev/null +++ b/interfaces/Mock.py @@ -0,0 +1,5 @@ +from random import random + +class Interface(object): + def read(self): + return random() * 20 \ No newline at end of file diff --git a/Resources/UI/CalibracaoPressaoW.ui b/resources/UI/CalibracaoPressaoW.ui similarity index 91% rename from Resources/UI/CalibracaoPressaoW.ui rename to resources/UI/CalibracaoPressaoW.ui index 5c90ae7..3af8065 100644 --- a/Resources/UI/CalibracaoPressaoW.ui +++ b/resources/UI/CalibracaoPressaoW.ui @@ -48,7 +48,7 @@ QGroupBox QLineEdit { font: bold 13px "FreeMono"; } - + 430 @@ -198,8 +198,7 @@ color:rgb(255,255,255); - - + Tensão no Calibrante @@ -516,24 +515,6 @@ font: 14pt "Noto Serif"; - - - - 430 - 560 - 921 - 111 - - - - padding: 2px; -border: 2px solid rgb(5, 5, 5); -font: normal 10pt "FreeMono"; - - - - - @@ -559,8 +540,7 @@ font: normal 10pt "FreeMono"; - - + Cronômetro @@ -757,6 +737,80 @@ border: 1px solid rgb(255,255,255); + + + + 430 + 560 + 921 + 111 + + + + + 0 + 0 + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOff + + + false + + + + + 0 + 0 + 904 + 109 + + + + + 0 + 0 + + + + + + 0 + 0 + 921 + 800 + + + + + 0 + 0 + + + + IBeamCursor + + + padding: 2px; +border: 2px solid rgb(5, 5, 5); +font: 10pt "Liberation Mono"; + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + @@ -855,6 +909,13 @@ border: 1px solid rgb(255,255,255); + + + PlotWidget + QGraphicsView +
pyqtgraph
+
+
diff --git a/threads/MainThread.py b/threads/MainThread.py new file mode 100644 index 0000000..fb545a7 --- /dev/null +++ b/threads/MainThread.py @@ -0,0 +1,29 @@ +from time import sleep +from PyQt5.QtCore import QThread, QTimer + +from interfaces.Mock import Interface + +class MainThread(QThread): + def __init__(self, ui, parent=None): + super(MainThread, self).__init__(parent) + self.ui = ui + self.interface = Interface() + self.data = [] + + def run(self): + self.timer = QTimer() + self.timer.timeout.connect(self._updateGraph) + self.timer.start(100) + thread_instance = QThread() + thread_instance.start() + thread_instance.exec_() + + def _updateGraph(self): + self._log("DEBUG", "Loop") + self.ui.mainGraph.clear() + self.data.append(self.interface.read()) + self.ui.mainGraph.plot(self.data) + + def _log(self, level, msg): + self.ui.consoleView.setText("{} {}\n{}".format(level, msg, self.ui.consoleView.text())) + print(self.ui.consoleView.size()) \ No newline at end of file diff --git a/CalibracaoPressaoW.py b/ui/CalibracaoPressaoW.py similarity index 86% rename from CalibracaoPressaoW.py rename to ui/CalibracaoPressaoW.py index bc943fc..3197f7b 100644 --- a/CalibracaoPressaoW.py +++ b/ui/CalibracaoPressaoW.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file 'Resources/UI/CalibracaoPressaoW.ui' +# Form implementation generated from reading ui file 'resources/UI/CalibracaoPressaoW.ui' # # Created by: PyQt5 UI code generator 5.12.1 # @@ -38,17 +38,17 @@ class Ui_CalibracaoPressaoW(object): " font: bold 13px \"FreeMono\";\n" "}") self.centralWidget.setObjectName("centralWidget") - self.CentralGraph = QtWidgets.QGraphicsView(self.centralWidget) - self.CentralGraph.setGeometry(QtCore.QRect(430, 10, 921, 531)) + self.mainGraph = PlotWidget(self.centralWidget) + self.mainGraph.setGeometry(QtCore.QRect(430, 10, 921, 531)) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.CentralGraph.sizePolicy().hasHeightForWidth()) - self.CentralGraph.setSizePolicy(sizePolicy) - self.CentralGraph.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) - self.CentralGraph.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) - self.CentralGraph.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignJustify) - self.CentralGraph.setObjectName("CentralGraph") + sizePolicy.setHeightForWidth(self.mainGraph.sizePolicy().hasHeightForWidth()) + self.mainGraph.setSizePolicy(sizePolicy) + self.mainGraph.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) + self.mainGraph.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) + self.mainGraph.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignJustify) + self.mainGraph.setObjectName("mainGraph") self.scaleBox = QtWidgets.QGroupBox(self.centralWidget) self.scaleBox.setGeometry(QtCore.QRect(20, 10, 401, 221)) self.scaleBox.setToolTip("") @@ -83,8 +83,7 @@ class Ui_CalibracaoPressaoW(object): self.f_min.setObjectName("f_min") self.pressureBox = QtWidgets.QGroupBox(self.scaleBox) self.pressureBox.setGeometry(QtCore.QRect(210, 30, 181, 101)) - self.pressureBox.setStyleSheet("\n" -"") + self.pressureBox.setStyleSheet("") self.pressureBox.setObjectName("pressureBox") self.p_max = QtWidgets.QLineEdit(self.pressureBox) self.p_max.setGeometry(QtCore.QRect(80, 30, 61, 21)) @@ -171,21 +170,13 @@ class Ui_CalibracaoPressaoW(object): "color:rgb(255,255,255);\n" "font: 14pt \"Noto Serif\";") self.calibratorLabel.setObjectName("calibratorLabel") - self.arqSalvoLabel = QtWidgets.QLabel(self.centralWidget) - self.arqSalvoLabel.setGeometry(QtCore.QRect(430, 560, 921, 111)) - self.arqSalvoLabel.setStyleSheet("padding: 2px;\n" -"border: 2px solid rgb(5, 5, 5);\n" -"font: normal 10pt \"FreeMono\";") - self.arqSalvoLabel.setText("") - self.arqSalvoLabel.setObjectName("arqSalvoLabel") self.cronometroBox = QtWidgets.QGroupBox(self.centralWidget) self.cronometroBox.setGeometry(QtCore.QRect(20, 340, 401, 201)) self.cronometroBox.setStyleSheet("border: 2px solid rgb(123, 0, 129);") self.cronometroBox.setObjectName("cronometroBox") self.timerGBox = QtWidgets.QGroupBox(self.cronometroBox) self.timerGBox.setGeometry(QtCore.QRect(10, 30, 211, 71)) - self.timerGBox.setStyleSheet("\n" -"") + self.timerGBox.setStyleSheet("") self.timerGBox.setObjectName("timerGBox") self.timerLabel = QtWidgets.QLabel(self.timerGBox) self.timerLabel.setGeometry(QtCore.QRect(20, 30, 81, 31)) @@ -245,6 +236,41 @@ class Ui_CalibracaoPressaoW(object): self.stopRegTimerButton.setStyleSheet("background-color: rgb(80,80,80);\n" "border: 1px solid rgb(255,255,255);") self.stopRegTimerButton.setObjectName("stopRegTimerButton") + self.scrollArea = QtWidgets.QScrollArea(self.centralWidget) + self.scrollArea.setGeometry(QtCore.QRect(430, 560, 921, 111)) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.scrollArea.sizePolicy().hasHeightForWidth()) + self.scrollArea.setSizePolicy(sizePolicy) + self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) + self.scrollArea.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) + self.scrollArea.setWidgetResizable(False) + self.scrollArea.setObjectName("scrollArea") + self.scrollAreaWidgetContents = QtWidgets.QWidget() + self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 904, 109)) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.scrollAreaWidgetContents.sizePolicy().hasHeightForWidth()) + self.scrollAreaWidgetContents.setSizePolicy(sizePolicy) + self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents") + self.consoleView = QtWidgets.QLabel(self.scrollAreaWidgetContents) + self.consoleView.setGeometry(QtCore.QRect(0, 0, 921, 800)) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.MinimumExpanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.consoleView.sizePolicy().hasHeightForWidth()) + self.consoleView.setSizePolicy(sizePolicy) + self.consoleView.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor)) + self.consoleView.setStyleSheet("padding: 2px;\n" +"border: 2px solid rgb(5, 5, 5);\n" +"font: 10pt \"Liberation Mono\";") + self.consoleView.setText("") + self.consoleView.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop) + self.consoleView.setWordWrap(True) + self.consoleView.setObjectName("consoleView") + self.scrollArea.setWidget(self.scrollAreaWidgetContents) CalibracaoPressaoW.setCentralWidget(self.centralWidget) self.menuBar = QtWidgets.QMenuBar(CalibracaoPressaoW) self.menuBar.setGeometry(QtCore.QRect(0, 0, 1366, 24)) @@ -360,3 +386,4 @@ class Ui_CalibracaoPressaoW(object): self.selectPortaUSB.setText(_translate("CalibracaoPressaoW", "Selecionar porta USB")) +from pyqtgraph import PlotWidget diff --git a/MainWindow.py b/ui/MainWindow.py similarity index 51% rename from MainWindow.py rename to ui/MainWindow.py index 085d6d7..752e235 100644 --- a/MainWindow.py +++ b/ui/MainWindow.py @@ -1,6 +1,7 @@ import sys from PyQt5 import QtWidgets -from CalibracaoPressaoW import Ui_CalibracaoPressaoW +from ui.CalibracaoPressaoW import Ui_CalibracaoPressaoW +from threads.MainThread import MainThread class Ui_MainWindow(object): @@ -12,4 +13,8 @@ class Ui_MainWindow(object): self.ui = Ui_CalibracaoPressaoW() self.ui.setupUi(self.dialog) + main_thread = MainThread(self.ui) + main_thread.finished.connect(self.app.exit) + main_thread.start() + self.dialog.showMaximized() \ No newline at end of file -- 2.22.0