-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
81 lines (66 loc) · 2.66 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! /usr/bin/env python3
# coding: utf-8
import sys
import os
import random
import matplotlib
matplotlib.use('Qt5Agg')
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QSizePolicy, QWidget, QTextBrowser, QLineEdit, QPushButton
import numpy as np
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.animation import FuncAnimation
import matplotlib.pyplot as plt
from modual import animation, read, sendtest1, sendtest0
#using matplotlib canvas which can add to qt layout
class MyMplCanvas(FigureCanvas):
def __init__(self, parent=None, width=38, height=6):
fig = Figure(figsize=(width, height))
self.ax1 = fig.add_subplot(311)
self.ax2 = fig.add_subplot(312)
self.ax3 = fig.add_subplot(313)
# tight layout to remove white places
fig.set_tight_layout(True)
FigureCanvas.__init__(self, fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self,
QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
class ApplicationWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
QMainWindow.resize(self,1500,900)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setWindowTitle("application main window")
self.main_widget = QtWidgets.QWidget(self)
vbox = QtWidgets.QVBoxLayout(self.main_widget)
# set canvas size
self.canvas = MyMplCanvas(self.main_widget,width=12, height=12)
vbox.addWidget(self.canvas)
self.textBrowser = QTextBrowser(self)
vbox.addWidget(self.textBrowser)
self.setLayout(vbox)
# make the cursor always focus the newset line
self.textBrowser.textChanged.connect(lambda:self.textBrowser.moveCursor(QtGui.QTextCursor.End))
self.main_widget.setFocus()
self.setCentralWidget(self.main_widget)
# dynamic update the plot
self.plot = animation.animationClass(self.canvas, self)
# read data thread
self.read = read.readClass(self)
self.read.start()
# simulate send date0 thread
self.sendtest0 = sendtest0.sendClass()
self.sendtest0.start()
# simulate send data1 thread
self.sendtest1 = sendtest1.sendClass()
self.sendtest1.start()
if __name__ == "__main__":
App = QApplication(sys.argv)
aw = ApplicationWindow()
# show the max size at the beginning
aw.showMaximized()
App.exit()
sys.exit(App.exec_())