-
Notifications
You must be signed in to change notification settings - Fork 0
/
generic_gui.py
71 lines (55 loc) · 2.02 KB
/
generic_gui.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
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout, \
QFileDialog, QMessageBox
from PyQt5.QtCore import Qt
import pyqtgraph as pg
import numpy as np
class Interface(QWidget):
def __init__(self):
super().__init__()
self.l = QGridLayout(self)
# Create a plot outside the central widget
x = np.linspace(0, 10*np.pi)
y = np.sin(x)/x**2
self.plot = pg.plot(x, y)
# Create an ImageView inside the central widget
self.imv = pg.ImageView()
self.l.addWidget(self.imv)
# random, grayscale image
random_im = np.random.randint(0, 255, (10, 10)).astype(np.uint8)
self.imv.setImage(random_im)
def keyPressEvent(self, e):
modifiers = QApplication.keyboardModifiers()
# Checks for a specific key ("I") and if Ctrl is pressed
if e.key() == Qt.Key_I and modifiers == Qt.ControlModifier:
QMessageBox.information(self, "Shortcut", "Shortcut recognized!")
class Main(QMainWindow):
def __init__(self):
super().__init__()
self.status = self.statusBar()
self.menu = self.menuBar()
# Main top menu
self.file = self.menu.addMenu("&File")
self.file.addAction("Open", self.open)
self.file.addAction("Save", self.save)
self.file.addAction("Close", self.close)
# Central widget
self.w = None
# Title
self.setWindowTitle("Generic GUI")
self.setGeometry(100, 100, 800, 600)
def open(self):
self.fn = QFileDialog.getOpenFileName()[0]
if self.fn:
self.status.showMessage(self.fn)
self.w = Interface()
self.setCentralWidget(self.w)
def save(self):
QMessageBox.critical(self,
"Meaningful error",
"Something went wrong!")
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
m = Main()
m.show()
sys.exit(app.exec_())