-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFocusCorrectionPlaneWindow.py
205 lines (160 loc) · 6.78 KB
/
FocusCorrectionPlaneWindow.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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
from pyqtgraph.Qt import QtCore, QtGui
from PositionList import posList as PositionList
import functools
from imageSourceMM import imageSource
import threading
import numpy as np
class FocusCorrectionPlaneWindow(QtGui.QWidget):
def __init__(self , posList,imgSrc, debug=True):
QtGui.QWidget.__init__(self)
self.layout = QtGui.QHBoxLayout()
table_layout = QtGui.QVBoxLayout()
self.positionListTable = QtGui.QTableWidget(self)
self.imgSrc = imgSrc
self.posList = posList
table_layout.addWidget(self.positionListTable)
self.fill_table()
self.positionListTable.itemSelectionChanged.connect(self.select_row)
self.currentPositionTable = QtGui.QTableWidget(self)
self.setup_current_position_table()
table_layout.addWidget(self.currentPositionTable)
self.currentPositionTable.setSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Expanding)
table_layout.addStretch(1)
buttonlayout = QtGui.QVBoxLayout()
mark_button=QtGui.QPushButton("mark new",self)
reshift_button = QtGui.QPushButton("reshift Z",self)
delete_button = QtGui.QPushButton("delete selected",self)
delete_all_button = QtGui.QPushButton("delete all",self)
goto_button = QtGui.QPushButton("go to selected",self)
load_button = QtGui.QPushButton("Load Position list",self)
save_button = QtGui.QPushButton("Save Position list",self)
delete_button.clicked.connect(self.delete_selected)
mark_button.clicked.connect(self.mark_new)
delete_all_button.clicked.connect(self.delete_all)
goto_button.clicked.connect(self.goto_selected)
load_button.clicked.connect(self.load_position_list)
save_button.clicked.connect(self.save_position_list)
buttonlayout.addWidget(mark_button)
buttonlayout.addWidget(reshift_button)
buttonlayout.addWidget(goto_button)
buttonlayout.addWidget(delete_button)
buttonlayout.addWidget(delete_all_button)
buttonlayout.addWidget(load_button)
buttonlayout.addWidget(save_button)
buttonlayout.addStretch(1)
self.layout.addLayout(table_layout)
self.layout.addLayout(buttonlayout)
self.setLayout(self.layout)
self.resize(430, 500)
self._dialog = None
self.update_current_pos()
def load_position_list(self,evt):
fileName = QtGui.QFileDialog.getOpenFileName(self, 'Position List File', selectedFilter='*.csv')
print fileName
self.posList.LoadFromFile(fileName,'AxioVision')
self.fill_table()
self.update_plane()
def save_position_list(self,evt):
fileName = QtGui.QFileDialog.getSaveFileName(self, 'Position List File', selectedFilter='*.csv')
print fileName
self.posList.save_position_list(fileName)
def setup_current_position_table(self):
self.currentPositionTable.clear()
self.currentPositionTable.setRowCount(1)
self.currentPositionTable.setColumnCount(3)
self.currentPositionTable.setHorizontalHeaderLabels(["Xcurr", "Ycurr","Zcurr"])
def goto_selected(self):
i_sel=self.positionListTable.currentRow()
(xx,yy,zz)=self.posList.getXYZ()
x=xx[i_sel]
y=yy[i_sel]
z=zz[i_sel]
self.imgSrc.set_xy(x,y)
self.imgSrc.set_z(z)
def update_plane(self):
x,y,z = self.posList.getXYZ()
if len(x)>3:
XYZ = np.column_stack((x,y,z))
self.imgSrc.define_focal_plane(np.transpose(XYZ))
def delete_all(self):
"delete all the positions"
self.posList.select_all()
self.posList.delete_selected()
self.fill_table()
def delete_selected(self):
i_sel = self.positionListTable.currentRow()
self.posList.delete_position(i_sel)
self.update_plane()
self.fill_table()
def get_xyz(self):
x,y = self.imgSrc.get_xy()
z = self.imgSrc.get_z()
return x,y,z
def mark_new(self):
x,y,z = self.get_xyz()
self.posList.add_position(x=x,y=y,z=z,edgecolor='m')
self.update_plane()
self.fill_table()
def select_row(self):
#print "hello"
i_sel=self.positionListTable.currentRow()
N=self.positionListTable.rowCount()
for i in range(N):
if i == i_sel:
color = QtCore.Qt.lightGray
else:
color = QtCore.Qt.white
for j in range(3):
self.positionListTable.item(i,j).setBackground(color)
def closeEvent(self,evt=None):
print "closing"
self.cursor_timer.cancel()
def update_current_pos(self):
x,y,z = self.get_xyz()
self.fill_row(x,y,z,0,table=self.currentPositionTable)
self.cursor_timer = threading.Timer(.5, self.update_current_pos)
self.cursor_timer.start()
def fill_table(self):
(xx,yy,zz)=self.posList.getXYZ()
N=len(xx)
self.positionListTable.clear()
self.positionListTable.setRowCount(N)
self.positionListTable.setColumnCount(3)
self.positionListTable.setHorizontalHeaderLabels(["X", "Y","Z"])
for i in range(N):
self.fill_row(xx[i],yy[i],zz[i],i,self.positionListTable)
self.positionListTable.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self.positionListTable.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.positionListTable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers)
def fill_row(self,x,y,z,row,table):
self.add_name_item(str(x),row=row,table=table,col=0)
self.add_name_item(str(y),row=row,table=table,col=1)
self.add_name_item(str(z),row=row,table=table,col=2)
def add_name_item(self,text,row,table,isReadOnly=True,col=0,greyBack = False):
NameItem = QtGui.QTableWidgetItem(text)
if isReadOnly:
NameItem.setFlags(QtCore.Qt.ItemIsEnabled)
if greyBack:
NameItem.setBackground(QtCore.Qt.lightGray)
table.setItem(row, col, NameItem)
return NameItem
def handle_open_dialog(self):
if self._dialog is None:
self._dialog = QtGui.QDialog(self)
self._dialog.resize(200, 100)
self._dialog.show()
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
defaultMMpath = "C:\Program Files\Micro-Manager-1.4"
configFile = QtGui.QFileDialog.getOpenFileName(
None, "pick a uManager cfg file", defaultMMpath, "*.cfg")
configFile = str(configFile.replace("/", "\\"))
print configFile
imgSrc = imageSource(configFile)
plist = PositionList(None)
win = FocusCorrectionPlaneWindow(plist,imgSrc)
win.show()
app.exec_()
imgSrc.shutdown()
sys.exit()