From 30041c57ba5d21d49b2d5a2819ef1ef78fd3ca43 Mon Sep 17 00:00:00 2001 From: Eli Stavitski Date: Mon, 10 Jul 2023 20:19:15 -0400 Subject: [PATCH] update ui --- pilatus_tools/ui/ui_pilatus.ui | 361 +++++++-------- pilatus_tools/widgets/widget_pilatus.py | 573 ++++++++++++++---------- 2 files changed, 497 insertions(+), 437 deletions(-) diff --git a/pilatus_tools/ui/ui_pilatus.ui b/pilatus_tools/ui/ui_pilatus.ui index 5b5536c..2e74fc0 100644 --- a/pilatus_tools/ui/ui_pilatus.ui +++ b/pilatus_tools/ui/ui_pilatus.ui @@ -118,7 +118,7 @@ 610 - 110 + 120 141 131 @@ -271,11 +271,11 @@ 610 260 571 - 160 + 161 - + @@ -294,8 +294,8 @@ - - + + 80 @@ -310,66 +310,50 @@ - - - - - 60 - 0 - - + + - 60 - 16777215 + 80 + 20 - - Counts + + 32000 + + + 9000 - + - Y + Height - - - + + + - 80 - 20 + 60 + 0 - - 32000 - - - 20 - - - - - 80 - 20 + 16777215 - - 32000 - - - 9000 + + Counts - - + + 80 @@ -384,25 +368,6 @@ - - - - - 60 - 0 - - - - - 60 - 16777215 - - - - Counts - - - @@ -419,21 +384,8 @@ - - - - - 40 - 16777215 - - - - 3 - - - - - + + 80 @@ -444,28 +396,31 @@ 32000 - 9000 + 20 - + + + + 60 + 0 + + 80 - 20 + 16777215 - - 32000 - - - 9000 + + Counts - - + + 80 @@ -480,8 +435,22 @@ - - + + + + Y + + + + + + + Width + + + + + 40 @@ -489,12 +458,12 @@ - 2 + 4 - - + + 40 @@ -502,11 +471,11 @@ - 4 + 2 - + @@ -522,15 +491,24 @@ - - - - Height + + + + + 80 + 20 + + + + 32000 + + + 9000 - - + + 60 @@ -539,7 +517,7 @@ - 60 + 80 16777215 @@ -548,8 +526,8 @@ - - + + 80 @@ -560,12 +538,12 @@ 32000 - 500 + 9000 - - + + 80 @@ -576,44 +554,38 @@ 32000 - 9000 + 500 - - + + - 80 + 16777215 20 - - 32000 - - - 9000 + + ROI - - + + - 80 - 20 + 40 + 16777215 - - 32000 - - - 9000 + + 3 - + 80 @@ -628,27 +600,24 @@ - - - - - 60 - 0 - - + + - 60 - 16777215 + 80 + 20 - - Counts + + 32000 + + + 9000 - - + + 80 @@ -663,15 +632,8 @@ - - - - X - - - - - + + 80 @@ -686,20 +648,17 @@ - - - - - 16777215 - 20 - - + + - ROI + X + + + Qt::RichText - + @@ -715,74 +674,54 @@ - - - - Width - - - - - + + - 25 - 25 + 80 + 20 - - ... + + 32000 - - true + + 9000 - - + + - 25 - 25 + 80 + 20 - - ... + + 32000 - - true + + 9000 - - - + + + - 25 - 25 + 60 + 0 - - ... - - - true - - - - - - 25 - 25 + 80 + 16777215 - ... - - - true + Counts @@ -793,8 +732,8 @@ 610 550 - 491 - 131 + 531 + 151 @@ -806,7 +745,7 @@ 10 30 431 - 91 + 104 @@ -931,7 +870,7 @@ 620 - 790 + 820 171 26 @@ -957,7 +896,7 @@ 620 - 690 + 720 161 80 @@ -1028,8 +967,8 @@ - 810 - 690 + 800 + 720 341 82 @@ -1037,6 +976,9 @@ + + 65000 + Qt::Horizontal @@ -1044,6 +986,9 @@ + + 65000 + Qt::Horizontal diff --git a/pilatus_tools/widgets/widget_pilatus.py b/pilatus_tools/widgets/widget_pilatus.py index 54c381e..0d460ab 100644 --- a/pilatus_tools/widgets/widget_pilatus.py +++ b/pilatus_tools/widgets/widget_pilatus.py @@ -1,7 +1,7 @@ import pkg_resources from PyQt5 import uic, QtCore from matplotlib.widgets import RectangleSelector, Cursor -from PyQt5.Qt import QSplashScreen, QObject +from PyQt5.Qt import QSplashScreen, QObject, QFont from PyQt5.QtWidgets import QToolTip from PyQt5.QtGui import QPixmap, QCursor from isstools.dialogs.BasicDialogs import message_box @@ -15,6 +15,8 @@ import matplotlib.patches as patches import time as ttime +import pyqtgraph as pg + import sys sys.path.append('/home/xf08id/Repos/') @@ -45,11 +47,12 @@ def __init__(self, self.pilatus100k_dict = self.detector_dict['Pilatus 100k'] self.pilatus100k_device = self.detector_dict['Pilatus 100k']['device'] - self.addCanvas() + # self.addCanvas() self.update_image_timer = QtCore.QTimer(self) - self.update_image_timer.setInterval(200) - self.update_image_timer.timeout.connect(self.update_continuous_plot) + self.update_image_timer.setInterval(1) + # # # self.update_image_timer.timeout.connect(self.update_continuous_plot) + self.update_image_timer.timeout.connect(self.plot_this) self.update_image_timer.start() self.update_counts_n_energy_timer = QtCore.QTimer(self) @@ -99,6 +102,19 @@ def __init__(self, self.label_min.setText(f'{self._min}') self.label_max.setText(f'{self._max}') + self.label_x.setText(u"\u25b4" + " " + u"\u25be") + self.label_y.setText(u"\u25c2" + " " + u"\u25b8") + self.label_x.setFont(QFont('Arial', 16)) + self.label_y.setFont(QFont('Arial', 16)) + # self.label_x. + + + + + + + + self._patches = {} self.lineEdit_min.returnPressed.connect(self.update_min_range) @@ -107,15 +123,15 @@ def __init__(self, self.horizontalSlider_max.sliderReleased.connect(self.update_slider_max_range) - self.RS = RectangleSelector(self.figure_pilatus_image.ax, - self.line_select_callback, - drawtype='box', - useblit=True, - button=[1, 3], - minspanx=5, - minspany=5, - spancoords='pixels', - interactive=True) + # self.RS = RectangleSelector(self.figure_pilatus_image.ax, + # self.line_select_callback, + # drawtype='box', + # useblit=True, + # button=[1, 3], + # minspanx=5, + # minspany=5, + # spancoords='pixels', + # interactive=True) # for i in range(1,5): # self.add_roi_counts_total(i) @@ -126,13 +142,13 @@ def __init__(self, for _keys in self.subscription_dict.keys(): self.add_pilatus_attribute(_keys) - for i in range(1, 5): - getattr(self, 'checkBox_roi' + str(i)).toggled.connect(self.add_roi_box) + # for i in range(1, 5): + # getattr(self, 'checkBox_roi' + str(i)).toggled.connect(self.add_roi_box) self.checkBox_auto_scale.toggled.connect(self.auto_scale_image) - for i in range(1,5): - getattr(self, 'pushButton_edit_roi' + str(i)).clicked.connect(self.set_roi) + # for i in range(1,5): + # getattr(self, 'pushButton_edit_roi' + str(i)).clicked.connect(self.set_roi) self.last_image_update_time = 0 self.colors = {1: 'r', @@ -153,7 +169,7 @@ def __init__(self, self.checkBox_roi3.setStyleSheet("QCheckBox::checked" "{" - "background-color : green" + "background-color : lime" "}") self.checkBox_roi4.setStyleSheet("QCheckBox::checked" @@ -161,6 +177,97 @@ def __init__(self, "background-color : yellow" "}") + self.create_plot_widget() + + + for i in range(1, 5): + getattr(self, 'checkBox_roi' + str(i)).toggled.connect(self.add_roi_box) + indx = str(i) + self.roi_boxes[indx].sigRegionChangeFinished.connect(partial(self.read_new_pos_n_size, indx)) + + + + def create_plot_widget(self): + self.window = pg.GraphicsLayoutWidget() + # self.window.setBackground('white') + self.verticalLayout_pilatus_image.addWidget(self.window) + self.plot = self.window.addPlot() + # self.plot.hideAxis('bottom') + # self.plot.hideAxis('left') + + self.set_n_add_image_properties() + + def set_n_add_image_properties(self): + self.image = pg.ImageItem(aspectLocked=True) + self.color_map = pg.colormap.getFromMatplotlib(name='jet') + self.image.setColorMap(self.color_map) + self.plot.addItem(self.image) + self.set_n_add_roi_properties() + + def set_n_add_roi_properties(self): + self.colors = {'1': 'red', + '2': 'cyan', + '3': 'lime', + '4': 'yellow'} + + self.roi_boxes = {} + + for i in range(1, 5): + indx = str(i) + x, y, dx, dy = self.pilatus100k_device.get_roi_coords(i) + self.roi_boxes[indx] = pg.ROI([y, x], [dy, dx], pen=pg.mkPen(self.colors[indx], width=5), + rotatable=False, aspectLocked=False) + + self.roi_boxes[indx].addScaleHandle([0.5, 0], [0.5, 1]) + self.roi_boxes[indx].addScaleHandle([0, 0.5], [1, 0.5]) + + def plot_this(self): + + + + _img = self.pilatus100k_device.image.array_data.get() + _img = _img.reshape(195,487) + + # _img = self.pilatus100k_device.image.array_data.value.reshape(195, 487) + ## Dead pixels + _img[158, 11] = 0 + _img[15, 352] = 0 + _img[171, 364] = 0 + _img[171, 365] = 0 + + self.image.setImage(_img) + self.image.setLevels([self._min, self._max]) + + + def add_roi_box(self): + sender_object = QObject().sender() + indx = sender_object.text() + + if not sender_object.isChecked(): + self.plot.removeItem(self.roi_boxes[indx]) + else: + self.plot.addItem(self.roi_boxes[indx]) + + def read_new_pos_n_size(self, roi_indx): + new_pos = self.roi_boxes[roi_indx].pos() + new_size = self.roi_boxes[roi_indx].size() + + print(f"{new_pos = } {new_size = }") + + getattr(self.pilatus100k_device, 'roi' + roi_indx).min_xyz.min_x.put(new_pos[1]) + getattr(self.pilatus100k_device, 'roi' + roi_indx).min_xyz.min_y.put(new_pos[0]) + + getattr(self.pilatus100k_device, 'roi' + roi_indx).size.x.put(new_size[1]) + getattr(self.pilatus100k_device, 'roi' + roi_indx).size.y.put(new_size[0]) + + + + + + + + + # self.pilatus100k_device.cam.acquire.subscribe(self.update_image_widget) def update_counts_n_energy(self): @@ -195,7 +302,7 @@ def update_slider_min_range(self): if _min < self._max: self.label_message.setText(" ") self._min = _min - self.update_pilatus_image() + # self.update_pilatus_image() else: self.label_message.setText("Error Min should be smaller then Max") @@ -207,7 +314,7 @@ def update_slider_max_range(self): if _max > self._min: self.label_message.setText(" ") self._max = _max - self.update_pilatus_image() + # self.update_pilatus_image() else: self.label_message.setText("Error Max should be larger then Min") @@ -215,7 +322,7 @@ def auto_scale_image(self): if self.checkBox_auto_scale.isChecked(): self._min = None self._max = None - self.update_pilatus_image() + # self.update_pilatus_image() def update_min_range(self): _value = int(self.lineEdit_min.text().split()[0]) @@ -230,7 +337,7 @@ def update_min_range(self): self.label_message.setText(" ") self.label_min.setText(f"{self._min}") self.horizontalSlider_min.setValue(self._min) - self.update_pilatus_image() + # self.update_pilatus_image() else: self.label_message.setText("Error Min should be smaller then Max") @@ -247,7 +354,7 @@ def update_max_range(self): self.label_message.setText(" ") self.label_max.setText(f"{self._max}") self.horizontalSlider_max.setValue(self._max) - self.update_pilatus_image() + # self.update_pilatus_image() else: self.label_message.setText("Error Max should be larger then Min") @@ -255,53 +362,61 @@ def update_max_range(self): #### Update Roi value - def set_roi(self): - sender = QObject() - sender_object = sender.sender() - object_name = sender_object.objectName() - _roi = object_name[-4:] - _roi_number = int(object_name[-1]) - if sender_object.isChecked(): - if getattr(self, 'checkBox_' + _roi).isChecked(): - x, y, dx, dy = self.pilatus100k_device.get_roi_coords(_roi_number) - self.RS.set_active(True) - self.RS.set_visible(True) - self.RS.extents = y, dy+y, x, x+dx - self.canvas_pilatus_image.draw_idle() - else: - self.RS.set_active(False) - self.RS.set_visible(False) - self.canvas_pilatus_image.draw_idle() - coord = self.RS.corners - x = coord[1][0] - w = coord[1][2] - coord[1][0] - y = coord[0][0] - h = coord[0][2] - coord[0][0] - getattr(self, f'spinBox_roi{_roi_number}_min_x').setValue(int(x)) - getattr(self, f'spinBox_roi{_roi_number}_min_y').setValue(int(y)) - getattr(self, f'spinBox_roi{_roi_number}_width').setValue(int(w)) - getattr(self, f'spinBox_roi{_roi_number}_height').setValue(int(h)) - self.update_roi_box() - - - # def add_roi_counts_total(self, ch): - # def update_roi_counts(value, **kwargs): - # getattr(self, 'label_counts_roi'+str(ch)).setText(f'{value} cts') - # - # getattr(self.pilatus100k_device, 'stats'+str(ch)).total.subscribe(update_roi_counts) - + # def set_roi(self): + # sender = QObject() + # sender_object = sender.sender() + # object_name = sender_object.objectName() + # _roi = object_name[-4:] + # _roi_number = int(object_name[-1]) + # if sender_object.isChecked(): + # if getattr(self, 'checkBox_' + _roi).isChecked(): + # x, y, dx, dy = self.pilatus100k_device.get_roi_coords(_roi_number) + # self.RS.set_active(True) + # self.RS.set_visible(True) + # self.RS.extents = y, dy+y, x, x+dx + # self.canvas_pilatus_image.draw_idle() + # else: + # self.RS.set_active(False) + # self.RS.set_visible(False) + # self.canvas_pilatus_image.draw_idle() + # coord = self.RS.corners + # x = coord[1][0] + # w = coord[1][2] - coord[1][0] + # y = coord[0][0] + # h = coord[0][2] - coord[0][0] + # getattr(self, f'spinBox_roi{_roi_number}_min_x').setValue(int(x)) + # getattr(self, f'spinBox_roi{_roi_number}_min_y').setValue(int(y)) + # getattr(self, f'spinBox_roi{_roi_number}_width').setValue(int(w)) + # getattr(self, f'spinBox_roi{_roi_number}_height').setValue(int(h)) + # self.update_roi_box() + # + # + # # def add_roi_counts_total(self, ch): + # # def update_roi_counts(value, **kwargs): + # # getattr(self, 'label_counts_roi'+str(ch)).setText(f'{value} cts') + # # + # # getattr(self.pilatus100k_device, 'stats'+str(ch)).total.subscribe(update_roi_counts) + #f def add_roi_parameters(self, ch): def update_roix_parameters(value, **kwargs): getattr(self, 'spinBox_roi' + str(ch) + '_min_x').setValue(value) + _pos_y = getattr(self.pilatus100k_device, 'roi' + str(ch)).min_xyz.min_y.get() + self.roi_boxes[str(ch)].setPos([_pos_y, value]) def update_roiy_parameters(value, **kwargs): getattr(self, 'spinBox_roi' + str(ch) + '_min_y').setValue(value) + _pos_x = getattr(self.pilatus100k_device, 'roi' + str(ch)).min_xyz.min_x.get() + self.roi_boxes[str(ch)].setPos([value, _pos_x]) def update_roix_size_parameters(value, **kwargs): getattr(self, 'spinBox_roi' + str(ch) + '_width').setValue(value) + _size_y = getattr(self.pilatus100k_device, 'roi' + str(ch)).size.y.get() + self.roi_boxes[str(ch)].setSize([_size_y, value]) def update_roiy_size_parameters(value, **kwargs): getattr(self, 'spinBox_roi' + str(ch) + '_height').setValue(value) + _size_x = getattr(self.pilatus100k_device, 'roi' + str(ch)).size.x.get() + self.roi_boxes[str(ch)].setSize([value, _size_x]) getattr(self.pilatus100k_device, 'roi' + str(ch)).min_xyz.min_x.subscribe(update_roix_parameters) getattr(self.pilatus100k_device, 'roi' + str(ch)).min_xyz.min_y.subscribe(update_roiy_parameters) @@ -309,152 +424,152 @@ def update_roiy_size_parameters(value, **kwargs): getattr(self.pilatus100k_device, 'roi' + str(ch)).size.x.subscribe(update_roix_size_parameters) getattr(self.pilatus100k_device, 'roi' + str(ch)).size.y.subscribe(update_roiy_size_parameters) - getattr(self, "spinBox_roi" + str(ch) + "_min_x").valueChanged.connect(partial(self.update_roix_value, str(ch))) - - getattr(self, 'spinBox_roi' + str(ch) + '_min_y').valueChanged.connect(partial(self.update_roiy_value, str(ch))) - - getattr(self, 'spinBox_roi' + str(ch) + '_width').valueChanged.connect(partial(self.update_roix_size_value, str(ch))) - - getattr(self, 'spinBox_roi' + str(ch) + '_height').valueChanged.connect(partial(self.update_roiy_size_value, str(ch))) + getattr(self, "spinBox_roi" + str(ch) + "_min_x").editingFinished.connect(partial(self.update_roix_value, str(ch))) + getattr(self, 'spinBox_roi' + str(ch) + '_min_y').editingFinished.connect(partial(self.update_roiy_value, str(ch))) + getattr(self, 'spinBox_roi' + str(ch) + '_width').editingFinished.connect(partial(self.update_roix_size_value, str(ch))) + getattr(self, 'spinBox_roi' + str(ch) + '_height').editingFinished.connect(partial(self.update_roiy_size_value, str(ch))) + # + # + # def update_roix_value(self, ch): sender = QObject() sender_object = sender.sender() sender_obj_value = sender_object.value() - getattr(self.pilatus100k_device, 'roi' + ch).min_xyz.min_x.set(sender_obj_value).wait() + getattr(self.pilatus100k_device, 'roi' + ch).min_xyz.min_x.put(sender_obj_value) def update_roiy_value(self, ch): sender = QObject() sender_object = sender.sender() sender_obj_value = sender_object.value() - getattr(self.pilatus100k_device, 'roi' + ch).min_xyz.min_y.set(sender_obj_value).wait() + getattr(self.pilatus100k_device, 'roi' + ch).min_xyz.min_y.put(sender_obj_value) def update_roix_size_value(self, ch): sender = QObject() sender_object = sender.sender() sender_obj_value = sender_object.value() - getattr(self.pilatus100k_device, 'roi' + ch).size.x.set(sender_obj_value).wait() + getattr(self.pilatus100k_device, 'roi' + ch).size.x.put(sender_obj_value) def update_roiy_size_value(self, ch): sender = QObject() sender_object = sender.sender() sender_obj_value = sender_object.value() - getattr(self.pilatus100k_device, 'roi' + ch).size.y.set(sender_obj_value).wait() - - - - def update_roi_box(self): - for i in range(1,5): - if getattr(self, 'checkBox_roi' + str(i)).isChecked(): - obj_name = getattr(self, 'checkBox_roi' + str(i)).objectName() - self._patches[obj_name].remove() - self.canvas_pilatus_image.draw_idle() - - x, y, dx, dy = self.pilatus100k_device.get_roi_coords(i) - rect = patches.Rectangle((y, x), dy, dx, linewidth=1, edgecolor=self.colors[i], facecolor='none') - self._patches[obj_name] = self.figure_pilatus_image.ax.add_patch(rect) - self.canvas_pilatus_image.draw_idle() - - def add_roi_box(self): - sender = QObject() - sender_object = sender.sender() - sender_obj_name = sender_object.objectName() - sender_obj_value = sender_object.text() - if sender_object.isChecked(): - x, y, dx, dy = self.pilatus100k_device.get_roi_coords(int(sender_obj_value)) - rect = patches.Rectangle((y, x), dy, dx, linewidth=1, edgecolor=self.colors[int(sender_obj_value)], - facecolor='none') - self._patches[sender_obj_name] = self.figure_pilatus_image.ax.add_patch(rect) - self.canvas_pilatus_image.draw_idle() - if not sender_object.isChecked(): - try: - self._patches[sender_obj_name].remove() - self.canvas_pilatus_image.draw_idle() - except: - pass + getattr(self.pilatus100k_device, 'roi' + ch).size.y.put(sender_obj_value) + # + # + # + # def update_roi_box(self): + # for i in range(1,5): + # if getattr(self, 'checkBox_roi' + str(i)).isChecked(): + # obj_name = getattr(self, 'checkBox_roi' + str(i)).objectName() + # self._patches[obj_name].remove() + # self.canvas_pilatus_image.draw_idle() + # + # x, y, dx, dy = self.pilatus100k_device.get_roi_coords(i) + # rect = patches.Rectangle((y, x), dy, dx, linewidth=1, edgecolor=self.colors[i], facecolor='none') + # self._patches[obj_name] = self.figure_pilatus_image.ax.add_patch(rect) + # self.canvas_pilatus_image.draw_idle() + # + # def add_roi_box(self): + # sender = QObject() + # sender_object = sender.sender() + # sender_obj_name = sender_object.objectName() + # sender_obj_value = sender_object.text() + # if sender_object.isChecked(): + # x, y, dx, dy = self.pilatus100k_device.get_roi_coords(int(sender_obj_value)) + # rect = patches.Rectangle((y, x), dy, dx, linewidth=1, edgecolor=self.colors[int(sender_obj_value)], + # facecolor='none') + # self._patches[sender_obj_name] = self.figure_pilatus_image.ax.add_patch(rect) + # self.canvas_pilatus_image.draw_idle() + # if not sender_object.isChecked(): + # try: + # self._patches[sender_obj_name].remove() + # self.canvas_pilatus_image.draw_idle() + # except: + # pass #### Update Roi value ##### Update, Add Pilatus Image - def update_pilatus_image(self): - - try: - - self.last_image_update_time = ttime.time() - self.figure_pilatus_image.ax.clear() - self.toolbar_pilatus_image.update() - - - # update_figure([self.figure_pilatus_image.ax], - # self.toolbar_pilatus_image, - # self.canvas_pilatus_image) - - _img = self.pilatus100k_device.image.array_data.get() - _img = _img.reshape(195, 487) - - # _img = self.pilatus100k_device.image.array_data.value.reshape(195, 487) - ## Dead pixels - _img[158, 11] = 0 - _img[15, 352] = 0 - _img[171, 364] = 0 - _img[171, 365] = 0 - - # self._min = _img.min() - # self._max = _img.max() - self.horizontalSlider_min.setMinimum(_img.min()) - self.horizontalSlider_max.setMinimum(_img.min()) - self.horizontalSlider_min.setMaximum(_img.max()) - self.horizontalSlider_max.setMaximum(_img.max()) - # self.horizontalSlider_min.setValue(_img.min()) - # self.horizontalSlider_max.setValue(_img.max()) - - # self.label_min.setText (str(self._min)) - # self.label_max.setText(str(self._max)) - - - - - self.figure_pilatus_image.ax.imshow(_img.T, interpolation='nearest', aspect='auto', vmin=self._min, vmax=self._max) - - - # Add the patch to the Axes - - for i in range(1,5): - if getattr(self, 'checkBox_roi' + str(i)).isChecked(): - x, y, dx, dy = self.pilatus100k_device.get_roi_coords(i) - rect = patches.Rectangle((y, x), dy, dx, linewidth=1, edgecolor=self.colors[i], facecolor='none') - self._patches['checkBox_roi' + str(i)] = self.figure_pilatus_image.ax.add_patch(rect) - # self.canvas_pilatus_image.draw_idle() - if not getattr(self, 'checkBox_roi' + str(i)).isChecked(): - try: - self._patches['checkBox_roi' + str(i)].remove() - # self.canvas_pilatus_image.draw_idle() - except: - pass - - - - # # self.figure_pilatus_image.ax.autoscale(True) - self.figure_pilatus_image.ax.set_xticks([]) - self.figure_pilatus_image.ax.set_yticks([]) - self.figure_pilatus_image.tight_layout(pad=0) - self.canvas_pilatus_image.draw_idle() - - except Exception as e: - print('Could not update the image. Error: ',e) + # def update_pilatus_image(self): + # + # try: + # + # self.last_image_update_time = ttime.time() + # self.figure_pilatus_image.ax.clear() + # self.toolbar_pilatus_image.update() + # + # + # # update_figure([self.figure_pilatus_image.ax], + # # self.toolbar_pilatus_image, + # # self.canvas_pilatus_image) + # + # _img = self.pilatus100k_device.image.array_data.get() + # _img = _img.reshape(195, 487) + # + # # _img = self.pilatus100k_device.image.array_data.value.reshape(195, 487) + # ## Dead pixels + # _img[158, 11] = 0 + # _img[15, 352] = 0 + # _img[171, 364] = 0 + # _img[171, 365] = 0 + # + # # self._min = _img.min() + # # self._max = _img.max() + # self.horizontalSlider_min.setMinimum(_img.min()) + # self.horizontalSlider_max.setMinimum(_img.min()) + # self.horizontalSlider_min.setMaximum(_img.max()) + # self.horizontalSlider_max.setMaximum(_img.max()) + # # self.horizontalSlider_min.setValue(_img.min()) + # # self.horizontalSlider_max.setValue(_img.max()) + # + # # self.label_min.setText (str(self._min)) + # # self.label_max.setText(str(self._max)) + # + # + # + # + # self.figure_pilatus_image.ax.imshow(_img.T, interpolation='nearest', aspect='auto', vmin=self._min, vmax=self._max) + # + # + # # Add the patch to the Axes + # + # for i in range(1,5): + # if getattr(self, 'checkBox_roi' + str(i)).isChecked(): + # x, y, dx, dy = self.pilatus100k_device.get_roi_coords(i) + # rect = patches.Rectangle((y, x), dy, dx, linewidth=1, edgecolor=self.colors[i], facecolor='none') + # self._patches['checkBox_roi' + str(i)] = self.figure_pilatus_image.ax.add_patch(rect) + # # self.canvas_pilatus_image.draw_idle() + # if not getattr(self, 'checkBox_roi' + str(i)).isChecked(): + # try: + # self._patches['checkBox_roi' + str(i)].remove() + # # self.canvas_pilatus_image.draw_idle() + # except: + # pass + # + # + # + # # # self.figure_pilatus_image.ax.autoscale(True) + # self.figure_pilatus_image.ax.set_xticks([]) + # self.figure_pilatus_image.ax.set_yticks([]) + # self.figure_pilatus_image.tight_layout(pad=0) + # self.canvas_pilatus_image.draw_idle() + # + # except Exception as e: + # print('Could not update the image. Error: ',e) - def update_continuous_plot(self): - if self.radioButton_continuous_exposure.isChecked() or self.checkBox_detector_flying.isChecked(): - try: - self.update_pilatus_image() - except: - pass + # def update_continuous_plot(self): + # if self.radioButton_continuous_exposure.isChecked() or self.checkBox_detector_flying.isChecked(): + # try: + # self.update_pilatus_image() + # except: + # pass # def update_image_widget(self, value, old_value, **kwargs): # if value == 0 and old_value == 1: @@ -476,60 +591,60 @@ def update_continuous_plot(self): # # if (ttime.time() - self.last_image_update_time) > 0.1: # # self.update_pilatus_image() - def addCanvas(self): - self.figure_pilatus_image = Figure() - self.figure_pilatus_image.set_facecolor(color='#FcF9F6') - self.canvas_pilatus_image = FigureCanvas(self.figure_pilatus_image) - self.toolbar_pilatus_image = NavigationToolbar(self.canvas_pilatus_image, self, coordinates=True) - self.verticalLayout_pilatus_image.addWidget(self.toolbar_pilatus_image) - self.verticalLayout_pilatus_image.addWidget(self.canvas_pilatus_image, stretch=1) - self.figure_pilatus_image.ax = self.figure_pilatus_image.add_subplot(111) - - self.canvas_pilatus_image.draw_idle() - self.figure_pilatus_image.tight_layout() - - # self.figure_pilatus_image.ax.set_yticks = ([]) - # self.figure_pilatus_image.ax.set_xticks = ([]) - # - # self.canvas_pilatus_image.draw_idle() - - - # cursor = Cursor(self.figure_pilatus_image.ax, useblit=True, color='green', linewidth=0.75) - # - # self.cid_start = self.canvas_pilatus_image.mpl_connect('button_press_event', self.roi_mouse_click_start) - # self.cid_move = self.canvas_pilatus_image.mpl_connect('motion_notify_event', self.roi_mouse_click_move) - # self.cid_finish = self.canvas_pilatus_image.mpl_connect('button_release_event', self.roi_mouse_click_finish) - - def line_select_callback(self, eclick, erelease): - pass - # - # x1, y1 = eclick.xdata, eclick.ydata - # x2, y2 = erelease.xdata, erelease.ydata - # print(f'{x1 = :3.3f} {y1 = :3.3f} {x2 = :3.3f} {y2 = :3.3f}') - # - # for i in range(1,5): - # if getattr(self, 'checkBox_roi' + str(i)).isChecked(): - # getattr(self, "spinBox_roi" + str(i) + "_min_x").setValue(int(y1)) - # getattr(self, 'spinBox_roi' + str(i) + '_min_y').setValue(int(x1)) - # getattr(self, 'spinBox_roi' + str(i) + '_width').setValue(int(y2-y1)) - # getattr(self, 'spinBox_roi' + str(i) + '_height').setValue(int(x2-x1)) - # self.update_roi_box() - - def roi_mouse_click_start(self, event): - if event.button == 3: - self.cur_mouse_coords = (event.xdata, event.ydata) - print('MOTION STARTED') - - def roi_mouse_click_move(self, event): - if self.cur_mouse_coords is not None: - self.cur_mouse_coords = (event.xdata, event.ydata) - print(self.cur_mouse_coords) - - def roi_mouse_click_finish(self, event): - if event.button == 3: - if self.cur_mouse_coords is not None: - self.cur_mouse_coords = None - print('MOTION FINISHED') + # def addCanvas(self): + # self.figure_pilatus_image = Figure() + # self.figure_pilatus_image.set_facecolor(color='#FcF9F6') + # self.canvas_pilatus_image = FigureCanvas(self.figure_pilatus_image) + # self.toolbar_pilatus_image = NavigationToolbar(self.canvas_pilatus_image, self, coordinates=True) + # self.verticalLayout_pilatus_image.addWidget(self.toolbar_pilatus_image) + # self.verticalLayout_pilatus_image.addWidget(self.canvas_pilatus_image, stretch=1) + # self.figure_pilatus_image.ax = self.figure_pilatus_image.add_subplot(111) + # + # self.canvas_pilatus_image.draw_idle() + # self.figure_pilatus_image.tight_layout() + # + # # self.figure_pilatus_image.ax.set_yticks = ([]) + # # self.figure_pilatus_image.ax.set_xticks = ([]) + # # + # # self.canvas_pilatus_image.draw_idle() + # + # + # # cursor = Cursor(self.figure_pilatus_image.ax, useblit=True, color='green', linewidth=0.75) + # # + # # self.cid_start = self.canvas_pilatus_image.mpl_connect('button_press_event', self.roi_mouse_click_start) + # # self.cid_move = self.canvas_pilatus_image.mpl_connect('motion_notify_event', self.roi_mouse_click_move) + # # self.cid_finish = self.canvas_pilatus_image.mpl_connect('button_release_event', self.roi_mouse_click_finish) + # + # def line_select_callback(self, eclick, erelease): + # pass + # # + # # x1, y1 = eclick.xdata, eclick.ydata + # # x2, y2 = erelease.xdata, erelease.ydata + # # print(f'{x1 = :3.3f} {y1 = :3.3f} {x2 = :3.3f} {y2 = :3.3f}') + # # + # # for i in range(1,5): + # # if getattr(self, 'checkBox_roi' + str(i)).isChecked(): + # # getattr(self, "spinBox_roi" + str(i) + "_min_x").setValue(int(y1)) + # # getattr(self, 'spinBox_roi' + str(i) + '_min_y').setValue(int(x1)) + # # getattr(self, 'spinBox_roi' + str(i) + '_width').setValue(int(y2-y1)) + # # getattr(self, 'spinBox_roi' + str(i) + '_height').setValue(int(x2-x1)) + # # self.update_roi_box() + # + # def roi_mouse_click_start(self, event): + # if event.button == 3: + # self.cur_mouse_coords = (event.xdata, event.ydata) + # print('MOTION STARTED') + # + # def roi_mouse_click_move(self, event): + # if self.cur_mouse_coords is not None: + # self.cur_mouse_coords = (event.xdata, event.ydata) + # print(self.cur_mouse_coords) + # + # def roi_mouse_click_finish(self, event): + # if event.button == 3: + # if self.cur_mouse_coords is not None: + # self.cur_mouse_coords = None + # print('MOTION FINISHED') ##### Update, Add Pilatus Image @@ -560,13 +675,13 @@ def open_detector_setting(self): self.lineEdit_cutoff_energy.setEnabled(False) def stop_acquire_image(self): - status_obj = self.pilatus100k_device.cam.acquire.put(0) + self.pilatus100k_device.cam.acquire.put(0) # self.update_pilatus_image() def acquire_image(self): # self.plan_processor.add_plan_and_run_if_idle('take_pil100k_test_image_plan', {}) - status_obj = self.pilatus100k_device.cam.acquire.set(1) + self.pilatus100k_device.cam.acquire.put(1) # self.update_pilatus_image()