forked from vshekar/qmicroscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxfp.py
143 lines (120 loc) · 4.06 KB
/
xfp.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import sys
from qtpy.QtCore import (
QPoint,
QSettings,
QSize,
)
from qtpy.QtWidgets import (
QCheckBox,
QLineEdit,
QPushButton,
QApplication,
QVBoxLayout,
QHBoxLayout,
QFormLayout,
QSpinBox,
QMainWindow,
QWidget,
)
from qmicroscope.microscope import Microscope
from qmicroscope.container import Container
from qmicroscope.settings import Settings
from qmicroscope.plugins import (
ZoomPlugin,
GridPlugin,
PresetPlugin,
ScalePlugin,
TogglePlugin,
CrossHairPlugin,
RecordPlugin,
)
class Form(QMainWindow):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
# Create widgets
self.setWindowTitle("NSLS-II Microscope Widget")
plugins = [
ZoomPlugin,
GridPlugin,
CrossHairPlugin,
PresetPlugin,
ScalePlugin,
TogglePlugin,
RecordPlugin,
]
self.container = Container(self, plugins=plugins)
self.container.count = 3
self.container.size = [2, 2]
self.microscope = self.container.microscope(0)
# self.microscope = Microscope(self)
self.startButton = QPushButton("Start")
self.settingsButton = QPushButton("Settings")
# Create layout and add widgets
layout = QVBoxLayout()
hButtonBox = QHBoxLayout()
hButtonBox.addStretch()
hButtonBox.addWidget(self.startButton)
hButtonBox.addWidget(self.settingsButton)
hButtonBox.addStretch()
layout.addLayout(hButtonBox)
layout.addWidget(self.container)
# Set main windows widget using our central layout
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
# Add button signal to slot to start/stop
self.startButton.clicked.connect(self.startButtonPressed)
self.settingsButton.clicked.connect(self.settingsButtonClicked)
# Connect to the microscope ROI clicked signal
if self.microscope:
self.microscope.roiClicked.connect(self.onRoiClicked)
# Read the settings and persist them
settings = QSettings("NSLS2", "main")
self.readSettings(settings)
self.settingsDialog = Settings(self)
self.settingsDialog.setContainer(self.container)
# event : QCloseEvent
def closeEvent(self, event):
settings = QSettings("NSLS2", "main")
self.writeSettings(settings)
event.accept()
def startButtonPressed(self):
# Currently being a little lame - only update state on start/stop.
print("Button pressed!", self.startButton.text())
if self.startButton.text() == "Start":
self.container.start(True)
self.startButton.setText("Stop")
else:
self.container.start(False)
self.startButton.setText("Start")
def settingsButtonClicked(self):
# Open the settings dialog.
self.settingsDialog.show()
def onRoiClicked(self, x, y):
print(f"ROI: {x}, {y}")
def readSettings(self, settings):
"""Load the application's settings."""
settings.beginGroup("MainWindow")
self.resize(settings.value("size", QSize(400, 400)))
self.move(settings.value("pos", QPoint(200, 200)))
self.container.readSettings(settings)
settings.endGroup()
def writeSettings(self, settings):
"""Save the applications's settings persistently."""
settings.beginGroup("MainWindow")
settings.setValue("size", self.size())
settings.setValue("pos", self.pos())
self.container.writeSettings(settings)
settings.endGroup()
if __name__ == "__main__":
# Set up some application basics for saving settings
QApplication.setOrganizationName("BNL")
QApplication.setOrganizationDomain("bnl.gov")
QApplication.setApplicationName("QCamera")
# Create the Qt Application
app = QApplication(sys.argv)
# Create and show the form
form = Form()
form.show()
# Run the main Qt loop
sys.exit(app.exec_())