part 2 screen updated: save and hint buttons added, plot displaying added; plots.py updated: multiple plots available

This commit is contained in:
Вадим Силаев 2022-12-04 08:16:51 +03:00
parent 6cc5097b1d
commit d6f8f6f13f
2 changed files with 116 additions and 51 deletions

View File

@ -2,7 +2,7 @@ import matplotlib.pyplot as plt
import random
def get_point(part):
def get_point(part, num):
if part == 1:
v1 = open('voltmeter1.txt')
i1 = open('ampere-meter1.txt')
@ -34,28 +34,41 @@ def get_point(part):
i2.write(newi2)
v2.close()
i2.close()
if part == 3:
vol[2].append(random.random() * 100)
cur[2].append(random.random() * 100)
elif part == 3:
vol[2][num].append(random.random() * 100)
cur[2][num].append(random.random() * 100)
elif part == 4:
vol[3][num].append(random.random() * 100)
cur[3][num].append(random.random() * 100)
def update_plot(part):
def update_plot(part, num):
for i in range(10):
get_point(part)
get_point(part, num)
def saveplot(part):
plt.figure(figsize=(8, 6))
plt.scatter(cur[part - 1], vol[part - 1], marker='o')
for i in range(len(vol[part - 1])):
plt.scatter(cur[part - 1][i], vol[part - 1][i], marker='o')
plt.grid()
plt.savefig('tmpplot' + str(part) + '.jpg', dpi=200)
plt.savefig('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200)
plt.close()
def empty_plot(part):
vol[part - 1] = []
cur[part - 1] = []
vol[part - 1] = [[]]
cur[part - 1] = [[]]
plt.figure(figsize=(8, 6))
plt.scatter(cur[part - 1], vol[part - 1], marker='o')
plt.grid()
plt.savefig('tmpplot' + str(part) + '.jpg', dpi=200)
plt.savefig('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200)
plt.close()
def plus_plot(part):
vol[part - 1].append([])
cur[part - 1].append([])
vol = [[], [], []]
cur = [[], [], []]
def minus_plot(part):
vol[part - 1].pop()
cur[part - 1].pop()
vol = [[], [], [[]], [[]]]
cur = [[], [], [[]], [[]]]

View File

@ -1,9 +1,5 @@
import os
import sys
from PySide6 import QtCore, QtWidgets, QtGui
import time
import plots
import asyncio
import PIL
@ -113,7 +109,7 @@ class Part1(QtWidgets.QWidget):
self.back_button.setGeometry(QtCore.QRect(20, self.q.height() - 20, 80, 40))
self.back_button.setText("Назад")
self.pixmap0 = QtGui.QPixmap('tmpplot1.jpg')
self.pixmap0 = QtGui.QPixmap('tmpplots/tmpplot1.jpg')
self.pixmap = self.pixmap0.scaledToHeight(3 * h)
self.plot1 = QtWidgets.QLabel(self)
self.plot1.setPixmap(self.pixmap)
@ -160,7 +156,7 @@ class Part1(QtWidgets.QWidget):
file, check = QtWidgets.QFileDialog.getSaveFileName(None, "Сохранить график 1",
r"C:\Users\Vadim\Desktop\plot1.jpg", "Images (*.png *.jpg)")
if check:
plot1 = PIL.Image.open('tmpplot3.jpg')
plot1 = PIL.Image.open('tmpplots/tmpplot3.jpg')
plot1.save(file)
def hint(self):
@ -181,13 +177,14 @@ class Part1(QtWidgets.QWidget):
def show_plot(self):
self.points.setText('Измеренных точек: ' + str(self.n))
self.pixmap0 = QtGui.QPixmap('tmpplot3.jpg')
self.pixmap0 = QtGui.QPixmap('tmpplots/tmpplot3.jpg')
self.pixmap = self.pixmap0.scaledToHeight(0.6 * self.q.height())
self.plot1.setPixmap(self.pixmap)
def upd_plot(self):
if self.started:
plots.update_plot(3)
plots.update_plot(3, 0)
plots.saveplot(3)
self.n += 10
self.show_plot()
@ -214,19 +211,31 @@ class Part1(QtWidgets.QWidget):
self.show_plot()
class Part2(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.started = False
self.n = 0
self.num = 0
self.hint_open = False
self.started = False
self.q = QtGui.QScreen.availableGeometry(QtWidgets.QApplication.primaryScreen())
h = self.q.height() * 0.2
plots.empty_plot(4)
self.button = QtWidgets.QPushButton(self)
self.button.setGeometry(QtCore.QRect(20, 20, 40, 40))
self.button.setText("Esc")
self.points = QtWidgets.QLabel(self)
self.points.setGeometry(QtCore.QRect(7.5 * h - 150, 3 * h - 80, 300, 20))
self.points.setText('Измеренных точек в текущей серии: ' + str(self.n))
self.disclaimer = QtWidgets.QLabel(self)
self.disclaimer.setText('<html><p align=\"left\"><span style=\" font-size:10pt; font-weight:600;\">Не '
'забудьте прочитать методику<\p><p align=\"left\"><span style=\" font-size:10pt; '
'font-weight:600;\">и подсказку выше перед началом работы!<\p><\html>')
self.disclaimer.setGeometry(7.5 * h - 150, h, 400, 100)
self.title = QtWidgets.QLabel(self)
self.title.setText(
"<html><head/><body><p align=\"center\"><span style=\" font-size:16pt; font-weight:600;\"> ЧАСТЬ "
@ -238,7 +247,25 @@ class Part2(QtWidgets.QWidget):
self.back_button.setGeometry(QtCore.QRect(20, self.q.height() - 20, 80, 40))
self.back_button.setText("Назад")
self.pixmap0 = QtGui.QPixmap('Aspect-ratio-4x3.png')
self.start_btn = QtWidgets.QPushButton(self)
self.start_btn.setText("Добавить серию")
self.start_btn.setGeometry(QtCore.QRect(7.5 * h - 150, 3 * h - 50, 120, 30))
self.delete_btn = QtWidgets.QPushButton(self)
self.delete_btn.setText("Удалить серию")
self.delete_btn.setGeometry(QtCore.QRect(7.5 * h + 30, 3 * h - 50, 120, 30))
self.delete_btn.hide()
self.save_btn = QtWidgets.QPushButton(self)
self.save_btn.setText("Сохранить")
self.save_btn.setGeometry(QtCore.QRect(7.5 * h - 60, 3 * h, 120, 30))
self.save_btn.hide()
self.hint_btn = QtWidgets.QPushButton(self)
self.hint_btn.setText('?')
self.hint_btn.setGeometry(QtCore.QRect(self.q.width() - 60, 20, 40, 40))
self.pixmap0 = QtGui.QPixmap('tmpplots/tmpplot4.jpg')
self.pixmap = self.pixmap0.scaledToHeight(3 * h)
self.plot1 = QtWidgets.QLabel(self)
self.plot1.setPixmap(self.pixmap)
@ -263,27 +290,36 @@ class Part2(QtWidgets.QWidget):
"измерений</p><p align=\"left\"><span style=\" font-size:10pt;\">можно сохранить полученные "
"значения и график.</p></html>")
self.text.setGeometry(QtCore.QRect(6 * h, h + 20, 3 * h, 2 * h + 20))
self.start_btn = QtWidgets.QPushButton(self)
self.start_btn.setText("Добавить серию")
self.start_btn.setGeometry(QtCore.QRect(7.5 * h - 150, 4 * h - 50, 120, 30))
self.delete_btn = QtWidgets.QPushButton(self)
self.delete_btn.setText("Удалить серию")
self.delete_btn.setGeometry(QtCore.QRect(7.5 * h + 30, 4 * h - 50, 120, 30))
self.delete_btn.hide()
self.save_btn = QtWidgets.QPushButton(self)
self.save_btn.setText("Сохранить")
self.save_btn.setGeometry(QtCore.QRect(7.5 * h - 60, 4 * h, 120, 30))
self.save_btn.hide()
self.text.setStyleSheet("border: 1px solid black; background-color: white;")
self.text.hide()
self.button.clicked.connect(self.esc)
self.back_button.clicked.connect(self.back)
self.start_btn.clicked.connect(self.start_stop)
self.delete_btn.clicked.connect(self.delete)
self.hint_btn.clicked.connect(self.hint)
self.save_btn.clicked.connect(self.savefile)
timer = QtCore.QTimer(self)
timer.timeout.connect(self.upd_plot)
timer.start(500)
@QtCore.Slot()
def savefile(self):
file, check = QtWidgets.QFileDialog.getSaveFileName(None, "Сохранить график 2",
r"C:\Users\Vadim\Desktop\plot2.jpg", "Images (*.png *.jpg)")
if check:
plot1 = PIL.Image.open('tmpplots/tmpplot4.jpg')
plot1.save(file)
def hint(self):
if not self.hint_open:
self.text.show()
self.hint_open = True
else:
self.text.hide()
self.hint_open = False
def esc(self):
self.close()
@ -292,31 +328,47 @@ class Part2(QtWidgets.QWidget):
self.w.showFullScreen()
self.close()
def show_plot(self):
self.points.setText('Измеренных точек в текущей серии: ' + str(self.n))
self.pixmap0 = QtGui.QPixmap('tmpplots/tmpplot4.jpg')
self.pixmap = self.pixmap0.scaledToHeight(0.6 * self.q.height())
self.plot1.setPixmap(self.pixmap)
def upd_plot(self):
if self.started:
plots.update_plot(4, self.num - 1)
plots.saveplot(4)
self.n += 10
self.show_plot()
def start_stop(self):
if not self.started:
self.start_btn.setText("Стоп")
self.started = True
self.save_btn.hide()
self.n += 1
self.hint_btn.hide()
if self.num != 0:
plots.plus_plot(4)
self.num += 1
self.n = 0
else:
self.start_btn.setText("Добавить серию")
self.started = False
self.save_btn.show()
self.hint_btn.show()
self.delete_btn.show()
def delete(self):
self.started = False
self.start_btn.setText("Добавить серию")
self.n -= 1
if self.n == 0:
self.save_btn.hide()
self.hint_btn.show()
self.n = 0
plots.minus_plot(4)
plots.saveplot(4)
self.show_plot()
self.num -= 1
if self.num == 0:
self.save_btn.hide()
self.delete_btn.hide()
if __name__ == "__main__":
app = QtWidgets.QApplication([])
widget = TitleScreen()
widget.showFullScreen()
sys.exit(app.exec())
self.delete_btn.hide()