-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaddMicrographDialog.py
More file actions
183 lines (132 loc) · 6.57 KB
/
addMicrographDialog.py
File metadata and controls
183 lines (132 loc) · 6.57 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# import PyQt5 elements
from PyQt5.QtWidgets import QApplication, QDialog
# general imports
import numpy
# import canvas class
from mplCanvas import MicrographCanvas
# import UI
from UIs.addMicrographDialogUi import UiAddMicrographDialog
class AddMicrographDialog(QDialog):
"""
AddMicrographDialog
This dialog enables the user to import a micrograph into the program. The dialog
asks for at least three fixed and moving points in order to align the micrograph
with the map.
"""
# TODO: make data selectable in this dialog
# TODO: make micrographs usable as first data in this dialog
def __init__(self, parent, file_name):
# call widget init
QDialog.__init__(self, parent)
# link app
self._app = QApplication.instance()
# link map
self._map = self._app.maps.get_selected_map()
# fixed and moving points
self._points_fixed = numpy.array([])
self._points_moving = numpy.array([])
# load and set up UI
self.ui = UiAddMicrographDialog(self)
# link actions for dialog buttons
self.ui.clear_last_fixed_push_button.clicked.connect(self.cb_clear_last_fixed)
self.ui.clear_all_fixed_push_button.clicked.connect(self.cb_clear_all_fixed)
self.ui.clear_last_moving_push_button.clicked.connect(self.cb_clear_last_moving)
self.ui.clear_all_moving_push_button.clicked.connect(self.cb_clear_all_moving)
# link and disable submit button
self._ok_push_button = self.ui.button_box.button(self.ui.button_box.Ok)
self._ok_push_button.setEnabled(False)
# create map canvas
self._micro_canvas = MicrographCanvas(self._map.get_data(), self._map.get_data_name(), file_name,
self.ui.plot_widget)
self._micro_canvas.add_callback('button_press_event', self.cb_map_clicked)
# get axes
self._map_axes, self._micro_axes = self._micro_canvas.get_axes()
# add toolbar to the toolbar widget
self._micro_canvas.add_toolbar(self.ui.toolbar_widget)
def cb_clear_all_fixed(self):
# clear all fixed points
self._points_fixed = numpy.array([])
# disable buttons for fixed point removing
self.ui.clear_all_fixed_push_button.setEnabled(False)
self.ui.clear_last_fixed_push_button.setEnabled(False)
# update the canvas
self._micro_canvas.update_points(self._points_fixed, self._points_moving)
# disable the submit button
self._ok_push_button.setEnabled(False)
def cb_clear_all_moving(self):
# remove all moving points
self._points_moving = numpy.array([])
# disable buttons for moving points removing
self.ui.clear_all_moving_push_button.setEnabled(False)
self.ui.clear_last_moving_push_button.setEnabled(False)
# update the canvas
self._micro_canvas.update_points(self._points_fixed, self._points_moving)
# disable the submit button
self._ok_push_button.setEnabled(False)
def cb_clear_last_fixed(self):
# remove last added fixed point
self._points_fixed = self._points_fixed[:-2]
# check if this was the only point and disable buttons for fixed points removing
if len(self._points_fixed) == 0:
self.ui.clear_all_fixed_push_button.setEnabled(False)
self.ui.clear_last_fixed_push_button.setEnabled(False)
# update micro canvas
self._micro_canvas.update_points(self._points_fixed, self._points_moving)
# check if the submit button should be enabled or disabled
if len(self._points_fixed) == len(self._points_moving) and len(self._points_fixed) > 2:
self._ok_push_button.setEnabled(True)
else:
self._ok_push_button.setEnabled(False)
def cb_clear_last_moving(self):
# remove last added moving point
self._points_moving = self._points_moving[:-2]
# check if this was the only one and disable buttons for moving points removing
if len(self._points_moving) == 0:
self.ui.clear_all_moving_push_button.setEnabled(False)
self.ui.clear_last_moving_push_button.setEnabled(False)
# update canvas
self._micro_canvas.update_points(self._points_fixed, self._points_moving)
# check whether submit button should be enabled or disabled
if len(self._points_fixed) == len(self._points_moving) and len(self._points_fixed) > 2:
self._ok_push_button.setEnabled(True)
else:
self._ok_push_button.setEnabled(False)
def cb_map_clicked(self, event):
# check if toolbar is active
if self._micro_canvas.get_toolbar_active() is None:
# check which axes were clicked
if event.inaxes is None:
return
elif event.inaxes == self._map_axes:
# add fixed point
self._points_fixed = numpy.concatenate((self._points_fixed, [event.xdata, event.ydata]), axis=0)
elif event.inaxes == self._micro_axes:
# add moving point
self._points_moving = numpy.concatenate((self._points_moving, [event.xdata, event.ydata]), axis=0)
# update canvas
self._micro_canvas.update_points(self._points_fixed, self._points_moving)
# enable or disable buttons for fixed points removing
if len(self._points_fixed) > 0:
self.ui.clear_all_fixed_push_button.setEnabled(True)
self.ui.clear_last_fixed_push_button.setEnabled(True)
else:
self.ui.clear_all_fixed_push_button.setEnabled(False)
self.ui.clear_last_fixed_push_button.setEnabled(False)
# enable or disable buttons for moving points removing
if len(self._points_moving) > 0:
self.ui.clear_all_moving_push_button.setEnabled(True)
self.ui.clear_last_moving_push_button.setEnabled(True)
else:
self.ui.clear_all_moving_push_button.setEnabled(False)
self.ui.clear_last_moving_push_button.setEnabled(False)
# enable or disable submit button
if len(self._points_fixed) == len(self._points_moving) and len(self._points_fixed) > 2:
self._ok_push_button.setEnabled(True)
else:
self._ok_push_button.setEnabled(False)
def get_points_fixed(self):
# return the fixed points
return self._points_fixed
def get_points_moving(self):
# return the moving points
return self._points_moving