class PlotDialog(QtGui.QDialog): def __init__(self, parent, width=5, height=4, dpi=100, **options): super(PlotDialog, self).__init__() self.parent_widget = parent self.figure = plt.figure() self.canvas = FigureCanvas(self.figure) self.toolbar = NavigationToolbar(self.canvas, self) self.layout = QtGui.QVBoxLayout() self.layout.addWidget(self.toolbar) self.layout.addWidget(self.canvas) self.setLayout(self.layout) self.figure.canvas.mpl_connect('motion_notify_event', self._on_mouse_motion) self.figure.canvas.mpl_connect('button_press_event', self._on_mouse_button) #self.plot() def _on_mouse_motion(self, event): if event.xdata != None and event.ydata != None: self.on_mouse_motion(event) def _on_mouse_button(self, event): if event.xdata != None and event.ydata != None: self.on_mouse_button(event) def on_mouse_button(self, event): pass def on_mouse_motion(self, event): label, x, y = self.get_tooltip(event) self.set_tooltip(x, y, label) def set_tooltip(self, x, y, label): y = self.canvas.height() - 1 - y print(("motion", label, x, y)) if label: print(("self.canvas.x/y()", self.canvas.geometry().x(), self.canvas.geometry().y())) print(("self.pos.x/y()", self.canvas.pos().x() + self.pos().x(), self.canvas.pos().y() + self.pos().y())) point = QtCore.QPoint(x + self.canvas.x() + self.pos().x(), y + self.canvas.y() + self.pos().y()) QtGui.QToolTip.showText(point, label) def plot(self): pass
class LatexLabel(QtGui.QWidget): def __init__(self, parent=None): super().__init__(parent) bg = self.palette().window().color() color = (bg.redF(), bg.greenF(), bg.blueF()) self.figure = plt.figure(edgecolor=color, facecolor=color) self.canvas = FigureCanvas(self.figure) fill_placeholder(self, self.canvas) self.text = self.figure.suptitle('', x=0.5, y=0.5, horizontalalignment='center', verticalalignment='center', fontsize=36) self.latex_text = '' @property def latex_text(self): return self._latex_text @latex_text.setter def latex_text(self, val): self._latex_text = val self.text.set_text(val) self.adjust_text_size() self.canvas.draw() def resizeEvent(self, event): super().resizeEvent(event) self.adjust_text_size() def adjust_text_size(self): bounds = self.text.get_window_extent(self.canvas.get_renderer()) if bounds.width != 0 and bounds.height != 0: scaling = min(self.canvas.width() / bounds.width, self.canvas.height() / bounds.height) self.text.set_fontsize(self.text.get_fontsize() * scaling)
class StatsDialog(QDialog): def __init__(self, standalone=True): QDialog.__init__(self) self.setWindowIcon(QIcon("img/32x32/view-statistics.png")) self.setWindowTitle("Statistics") layout = QVBoxLayout() self.canvas_width = 0 self.canvas_height = 0 self.canvas = None self.standalone = standalone self.page = 0 self.len_page = 100 self.fig = None self.tabs = QTabWidget() self.stats_image = QWidget() self.tabs.addTab(self.stats_image, QIcon("img/32x32/view-investment.png"), "Statistics") self.list_container = QWidget() list_layout = QVBoxLayout() self.list_pager = QWidget() pager_layout = QHBoxLayout() self.page_num_label = QLabel() first_button = QPushButton(QIcon.fromTheme("arrow-left-double", QIcon.fromTheme("go-first")), "") prev_button = QPushButton(QIcon.fromTheme("arrow-left", QIcon.fromTheme("go-previous")), "") next_button = QPushButton(QIcon.fromTheme("arrow-right", QIcon.fromTheme("go-next")), "") last_button = QPushButton(QIcon.fromTheme("arrow-right-double", QIcon.fromTheme("go-last")), "") self.connect(prev_button, SIGNAL("clicked()"), self.prev_page) self.connect(next_button, SIGNAL("clicked()"), self.next_page) self.connect(first_button, SIGNAL("clicked()"), self.first_page) self.connect(last_button, SIGNAL("clicked()"), self.last_page) pager_layout.addStretch() pager_layout.addWidget(first_button) pager_layout.addWidget(prev_button) pager_layout.addWidget(self.page_num_label) pager_layout.addWidget(next_button) pager_layout.addWidget(last_button) pager_layout.addStretch() self.list_widget = QTableWidget() self.list_widget.insertColumn(0) self.list_widget.insertColumn(0) self.list_widget.insertColumn(0) self.list_widget.setColumnWidth(0, 150) self.list_widget.setColumnWidth(2, 150) self.list_widget.setHorizontalHeaderItem(0, QTableWidgetItem("Name")) self.list_widget.setHorizontalHeaderItem(1, QTableWidgetItem("Price")) self.list_widget.setHorizontalHeaderItem(2, QTableWidgetItem("Time/Date")) self.list_pager.setLayout(pager_layout) list_layout.addWidget(self.list_pager) list_layout.addWidget(self.list_widget) self.list_container.setLayout(list_layout) self.tabs.addTab(self.list_container, QIcon("img/32x32/view-income-categories.png"), "List") layout.addWidget(self.tabs) if self.standalone: button_box = QDialogButtonBox() ok_button = button_box.addButton(button_box.Ok) self.connect(ok_button, SIGNAL("clicked()"), self.ok_clicked) layout.addWidget(button_box) self.setLayout(layout) def update(self, transactions): self.transactions = transactions self.page = 0 self.update_list(self.transactions) fig = renderPlot(self.transactions) if self.canvas: self.canvas.setParent(None) self.canvas.destroy() try: self.canvas = FigureCanvasQTAgg(fig) self.hide() self.canvas.setParent(self.stats_image) self.show() self.resize(self.canvas.width(), self.canvas.height() + 100) except AttributeError: # pass if there are still no transactions pass def update_list(self, transactions): self.transactions = transactions self.list_widget.clear() self.list_widget.setRowCount(0) reverse_transactions = transactions.reverse() self.page_num_label.setText(str(self.page + 1) + "/" + str(len(transactions) / self.len_page + 1)) for idx, transaction in enumerate(transactions[self.page * self.len_page : (self.page + 1) * self.len_page]): self.list_widget.insertRow(idx) self.list_widget.setCellWidget(idx, 0, QLabel(transaction.customer.name)) self.list_widget.setCellWidget(idx, 1, QLabel(str(transaction.price) + u" \u20AC")) self.list_widget.setCellWidget(idx, 2, QLabel(transaction.time.strftime("%H:%M:%S, %d.%m.%Y"))) def first_page(self): if self.page != 0: self.page = 0 self.update_list(self.transactions) def prev_page(self): if self.page > 0: self.page -= 1 self.update_list(self.transactions) def next_page(self): if self.page < len(self.transactions) / self.len_page: self.page += 1 self.update_list(self.transactions) def last_page(self): if self.page != len(self.transactions) / self.len_page: self.page = len(self.transactions) / self.len_page self.update_list(self.transactions) def ok_clicked(self): self.hide()
class IScatterWidget(QtGui.QWidget): image_changed = QtCore.pyqtSignal(numpy.ndarray) selection_changed = QtCore.pyqtSignal(list) send_current_image = QtCore.pyqtSignal(list) def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.figure = Figure() self.figure.patch.set_alpha(0) self.canvas = FigureCanvasQTAgg(self.figure) self.axes = self.figure.add_subplot(111, adjustable='box') self.contour_eval_func = None self.selector = RectangleSelector(self.axes, self.selector_cb, drawtype='box', useblit=True, button=[1,], minspanx=5, minspany=5, spancoords='pixels', lineprops=dict(color='orange', linestyle='-', inewidth = 2, alpha=0.5), rectprops = dict(facecolor='orange', edgecolor = 'orange', alpha=0.5, fill=True)) layout = QtGui.QHBoxLayout() layout.addWidget(self.canvas) axis_selector = QtGui.QWidget(self) axis_selector_layout = QtGui.QVBoxLayout() self.sample_selection_dct = {} for sample_selection in ['Plate', 'Well', 'Site', 'Treatment 1', 'Treatment 2', 'Group']: axis_selector_layout.addWidget(QtGui.QLabel(sample_selection)) self.sample_selection_dct[sample_selection] = QtGui.QComboBox(self) axis_selector_layout.addWidget(self.sample_selection_dct[sample_selection]) self.sample_selection_dct[sample_selection].addItem("All") self.sample_selection_dct[sample_selection].currentIndexChanged[str].connect(partial(self.sample_selection_changed, sample_selection)) axis_selector_layout.addWidget(QtGui.QLabel("Results by")) self.cmb_result_sample_selection = QtGui.QComboBox(self) axis_selector_layout.addWidget(self.cmb_result_sample_selection) self.cmb_result_sample_selection.addItem("All") self.cmb_result_sample_selection.addItem("Clustering") self.cmb_result_sample_selection.addItem("Outliers") self.cmb_result_sample_selection.addItem("Classification") self.cmb_result_sample_selection.currentIndexChanged[str].connect(self.result_selection_changed) axis_selector_layout.addStretch() axis_selector_layout.addWidget(QtGui.QLabel("X:")) self.axis_x_cmb = QtGui.QComboBox(self) axis_selector_layout.addWidget(self.axis_x_cmb) axis_selector_layout.addWidget(QtGui.QLabel("Y:")) self.axis_y_cmb = QtGui.QComboBox(self) axis_selector_layout.addWidget(self.axis_y_cmb) self.axis_c_label = QtGui.QLabel("C:") axis_selector_layout.addWidget(self.axis_c_label) self.axis_c_chk = QtGui.QCheckBox(self) self.axis_c_chk.setChecked(False) self._last_c_dim = 0 self.axis_c_cmb = QtGui.QComboBox(self) self.axis_c_cmb.setEnabled(False) axis_selector_layout.addWidget(self.axis_c_chk) axis_selector_layout.addWidget(self.axis_c_cmb) axis_selector_layout.addStretch() self.export_to_image_btn = QtGui.QPushButton('Export image File') axis_selector_layout.addWidget(self.export_to_image_btn) self.export_to_image_btn.clicked.connect(self.export_axes_to_image) self.export_to_cp_btn = QtGui.QPushButton('Export image clipboard') axis_selector_layout.addWidget(self.export_to_cp_btn) self.export_to_cp_btn.clicked.connect(self.export_axes_to_clipboard) self.cmb_colormap = QtGui.QComboBox(self) for c in SimpleMplImageViewerWithBlending.colors: self.cmb_colormap.addItem(c) axis_selector_layout.addWidget(self.cmb_colormap) self.cmb_colormap.currentIndexChanged[str].connect(self.colormap_changed) self.btn_move_to_combined_image = QtGui.QPushButton('vv') axis_selector_layout.addWidget(self.btn_move_to_combined_image) self.btn_move_to_combined_image.clicked.connect(self.move_to_combined_image) axis_selector.setLayout(axis_selector_layout) layout.addWidget(axis_selector) self.setLayout(layout) self.canvas.mpl_connect('scroll_event', self.mouse_wheel_zoom) def colormap_changed(self, colormap): self.current_cmap = str(colormap) self.update_axis() def move_to_combined_image(self): self.send_current_image.emit(self.current_raw_images) def export_axes_to_clipboard(self): bbox = self.axes.get_window_extent().transformed(self.figure.dpi_scale_trans.inverted()) x, y, width, height = bbox.x0, bbox.y1, bbox.width, bbox.height width *= self.figure.dpi height *= self.figure.dpi x *= self.figure.dpi y *= self.figure.dpi pixmap = QtGui.QPixmap.grabWidget(self.canvas, int(x)+3, self.canvas.height() - int(y)+3, int(width)-5, int(height)-5) QtGui.QApplication.clipboard().setPixmap(pixmap) def export_axes_to_image(self): file_name = QtGui.QFileDialog.getSaveFileName(self, "Select file name", ".", "Image Files (*.png *.jpg *.pdf)") print file_name if file_name: extent = self.axes.get_window_extent().transformed(self.figure.dpi_scale_trans.inverted()) self.figure.savefig(str(file_name), bbox_inches=extent) def sample_selection_changed(self, type_, idx): self.sample_selection = [True] * len(self.sample_selection) lkp_tmp = dict([v, u] for u, v in enumerate(['Plate', 'Well', 'Site', 'Treatment 1', 'Treatment 2', 'Group'])) for cur_sel_type, cur_sel_box in self.sample_selection_dct.items(): cur_sel = str(cur_sel_box.currentText()) if cur_sel.startswith('All'): continue for i, s in enumerate(self.sample_ids): if not s[lkp_tmp[cur_sel_type]].startswith(cur_sel): self.sample_selection[i] = False self.update_axis() def result_selection_changed(self, type_): self.update_axis() def set_countour_eval_cb(self, contour_eval_func): self.contour_eval_func = contour_eval_func def selector_cb(self, epress, erelease): x_min, x_max = min(epress.xdata, erelease.xdata), max(epress.xdata, erelease.xdata) y_min, y_max = min(epress.ydata, erelease.ydata), max(epress.ydata, erelease.ydata) ind = numpy.array([True if ((x > x_min) and (x < x_max) and (y > y_min) and (y < y_max) and self.sample_selection[k] ) else False for k, (x, y) in enumerate(self.xys)]) edgecolors = self.collection.get_edgecolors() facecolors = self.collection.get_facecolors() ids = [self.data[k].ref for k in range(len(ind)) if ind[k]] print ind.sum(), 'objects selected with refs', ids tmp_idx = numpy.nonzero(self.sample_selection)[0] for i in range(len(self.xys[tmp_idx])): if ind[i]: edgecolors[i] = DataPoint.colorin else: edgecolors[i] = facecolors[i] self.canvas.draw() self.update_image(ind) def mouse_wheel_zoom(self, event, base_scale=1.2): if event.key is None or not event.key.startswith('control'): return cur_xlim = self.axes.get_xlim() cur_ylim = self.axes.get_ylim() cur_xrange = (cur_xlim[1] - cur_xlim[0])*.5 cur_yrange = (cur_ylim[1] - cur_ylim[0])*.5 xdata = event.xdata # get event x location ydata = event.ydata # get event y location if event.button == 'up': # deal with zoom in scale_factor = 1/ base_scale xd, yd = xdata, ydata elif event.button == 'down': # deal with zoom out scale_factor = base_scale xd, yd = xdata, ydata else: # deal with something that should never happen scale_factor = 1 print event.button # set new limits self.axes.set_xlim([xd - cur_xrange*scale_factor, xd + cur_xrange*scale_factor]) self.axes.set_ylim([yd - cur_yrange*scale_factor, yd + cur_yrange*scale_factor]) self.canvas.draw() # force re-draw def update_image(self, ind): self.ind = ind ids = [self.data[k].ref for k in range(len(ind)) if ind[k]] treat = [self.sample_ids[k] for k in range(len(ind)) if ind[k]] img = self.image_generator_callback(treat, ids) self.image_changed.emit(img) self.selection_changed.emit(treat) def set_data(self, data_matrix, data_names, sample_ids, x_dim, y_dim, data_ch5_idx, image_generator_callback): self.image_generator_callback = image_generator_callback self.data_matrix = data_matrix self.data_names = data_names self.data_ch5_idx = data_ch5_idx self.sample_ids = sample_ids self.sample_selection = [True] * len(sample_ids) self.data_mins, self.data_maxs = self.data_matrix.min(0), self.data_matrix.max(0) self.fill_selection_boxes() assert self.data_matrix.shape[0] == len(self.sample_ids) assert self.data_matrix.shape[1] == len(self.data_names) self.x_dim = x_dim self.y_dim = y_dim self.c_dim = None self.ind = [False]*data_matrix.shape[0] for dn in data_names: self.axis_x_cmb.addItem(dn) self.axis_y_cmb.addItem(dn) self.axis_c_cmb.addItem(dn) self.update_axis() self.axis_x_cmb.setCurrentIndex(x_dim) self.axis_y_cmb.setCurrentIndex(y_dim) self.axis_x_cmb.currentIndexChanged.connect(self.axis_x_changed) self.axis_y_cmb.currentIndexChanged.connect(self.axis_y_changed) self.axis_c_cmb.currentIndexChanged.connect(self.axis_c_changed) self.axis_c_chk.stateChanged.connect(self.axis_c_toggled) def fill_selection_boxes(self): s = zip(*self.sample_ids) for i, s_name in enumerate(['Plate', 'Well', 'Site', 'Treatment 1', 'Treatment 2', 'Group']): for each in numpy.unique(s[i]): self.sample_selection_dct[s_name].addItem(str(each)) def axis_x_changed(self, x_dim): self.x_dim = x_dim self.update_axis() def axis_y_changed(self, y_dim): self.y_dim = y_dim self.update_axis() def axis_c_changed(self, c_dim): self.c_dim = c_dim self.update_axis() def axis_c_toggled(self, state): if not state: self._last_c_dim = self.c_dim self.c_dim = None self.axis_c_cmb.setEnabled(False) else: self.c_dim = self._last_c_dim self.axis_c_cmb.setEnabled(True) self.update_axis() def update_axis(self): self.axes.clear() self.data = [DataPoint(xy[0], xy[1], self.data_ch5_idx[i], False) for i, xy in enumerate(self.data_matrix[:, [self.x_dim, self.y_dim]])] self.Nxy = len(self.data) tmp_idx = numpy.nonzero(self.sample_selection)[0] self.xys = numpy.array([(d.x, d.y) for d in self.data]) if self.c_dim is None: facecolors = numpy.array([d.color for d in self.data])[tmp_idx] edgecolors = numpy.array([d.color for d in self.data])[tmp_idx] else: f_0_min = self.data_matrix[:, self.c_dim].min() f_0_max = self.data_matrix[:, self.c_dim].max() cNorm = colors.Normalize(vmin=f_0_min, vmax=f_0_max) scalarMap = cm.ScalarMappable(norm=cNorm, cmap=cm.jet) facecolors = [scalarMap.to_rgba(c) for c in self.data_matrix[tmp_idx, self.c_dim]] edgecolors = [scalarMap.to_rgba(c) for c in self.data_matrix[tmp_idx, self.c_dim]] for i in range(len(self.xys[tmp_idx])): if self.ind[i]: edgecolors[i] = DataPoint.colorin self.collection = CircleCollection( sizes=(22,), facecolors=facecolors, edgecolors=edgecolors, offsets = self.xys[tmp_idx], transOffset = self.axes.transData) self.axes.add_collection(self.collection) self.update_axis_lims() if self.contour_eval_func is not None: xx, yy, Z = self.contour_eval_func(self.axes.get_xlim(), self.axes.get_ylim(), self.x_dim, self.y_dim) self.axes.contourf(xx, yy, Z, levels=numpy.linspace(Z.min(), 0, 17), cmap=cm.Reds_r, alpha=0.2) self.axes.contour(xx, yy, Z, levels=[0], linewidths=1, colors='k') self.axes.contourf(xx, yy, Z, levels=numpy.linspace(0, Z.max(), 17), cmap=cm.Greens, alpha=0.3) self.figure.tight_layout() self.canvas.draw() def update_axis_lims(self): f_0_min = self.data_mins[self.x_dim] f_0_max = self.data_maxs[self.x_dim] f_1_min = self.data_mins[self.y_dim] f_1_max = self.data_maxs[self.y_dim] self.axes.set_xlim(f_0_min, f_0_max) self.axes.set_ylim(f_1_min, f_1_max) self.axes.set_xlabel(self.data_names[self.x_dim]) self.axes.set_ylabel(self.data_names[self.y_dim]) self.axes.set_aspect(abs((f_0_max-f_0_min)/(f_1_max-f_1_min))/1)
class figureViewDialog(QtGui.QDialog): def __init__(self, titles, images, windowTitle, parent=None): super(figureViewDialog, self).__init__(parent) self.setWindowFlags( QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowMaximizeButtonHint) self.figure = plt.Figure() self.canvas = FigureCanvas(self.figure) self.canvasHeight = self.canvas.height() self.toolbar = NavigationToolbar(self.canvas, self) self.toolbar.setStyleSheet('background-image:url(./images/b1.png); background-attachment: fixed; color: rgb(70, 0, 0);') self.images = images self.titles = titles self.setStyleSheet('background-image:url(./images/kb.png); background-attachment: fixed; color: rgb(70, 0, 0);') font = QtGui.QFont() font.setBold(True) font.setPointSize(9) font.setFamily('Nirmala UI') buttonsFrame = QtGui.QFrame() buttonsFrame.setStyleSheet('background-image:url(./images/b1.png); background-attachment: fixed; color: rgb(70, 0, 0);') buttonsFrame.setFixedHeight(50) buttonsLayout = QtGui.QHBoxLayout() numOfButtons = len(titles) self.buttons = [] for i in range(numOfButtons): newButton = QtGui.QPushButton() newButton.setMinimumHeight(31) newButton.setFont(font) newButton.setStyleSheet('background-image:url(./images/kb.png); background-attachment: fixed; ' 'color: rgb(70, 0, 0);') newButton.setAutoDefault(False) buttonsLayout.addWidget(newButton) self.buttons.append(newButton) buttonsFrame.setLayout(buttonsLayout) self.lblNoti = QtGui.QLabel() font = QtGui.QFont() font.setBold(True) font.setPointSize(8) font.setFamily('Nirmala UI') self.lblNoti.setFont(font) self.setStyleSheet('QLabel {color: #8c4600;}') self.lblNoti.setText('') self.lblNoti.setFixedHeight(15) self.lblNoti.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) lblFrame = QtGui.QFrame() lblFrame.setStyleSheet( 'background-image:url(./images/b1.png); background-attachment: fixed; color: rgb(70, 0, 0);') lblFrameLayout = QtGui.QHBoxLayout() lblFrame.setStyleSheet('QFrame {background-color: white;}') self.lblHead = QtGui.QLabel() font = QtGui.QFont() font.setPointSize(26) font.setFamily('Baskerville Old Face') self.lblHead.setFont(font) self.lblHead.setStyleSheet('QLabel {color: #8c4600;}') self.lblHead.setText('DHAROHAR') self.lblHead.setFixedHeight(25) self.lblHead.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) lblFrameLayout.addWidget(self.lblHead) lblFrame.setLayout(lblFrameLayout) topFrame = QtGui.QFrame() topFrame.setStyleSheet( 'background-image:url(./images/b1.png); background-attachment: fixed; color: rgb(70, 0, 0);') topFrame.setMaximumHeight(55) toplayout = QtGui.QHBoxLayout() toplayout.addWidget(self.toolbar) toplayout.addWidget(lblFrame) topFrame.setLayout(toplayout) self.canvas.setMinimumHeight(500) mainLayout = QtGui.QVBoxLayout() mainLayout.addWidget(topFrame) mainLayout.addWidget(self.canvas) mainLayout.addWidget(buttonsFrame) mainLayout.addWidget(self.lblNoti) self.setLayout(mainLayout) self.setWindowTitle(windowTitle) self.connections() self.plot() def connections(self): if len(self.titles) == 6: self.buttons[0].clicked.connect(self.saveFigure1) self.buttons[1].clicked.connect(self.saveFigure2) self.buttons[2].clicked.connect(self.saveFigure3) self.buttons[3].clicked.connect(self.saveFigure4) self.buttons[4].clicked.connect(self.saveFigure5) self.buttons[5].clicked.connect(self.saveFigure6) elif len(self.titles) == 5: self.buttons[0].clicked.connect(self.saveFigure1) self.buttons[1].clicked.connect(self.saveFigure2) self.buttons[2].clicked.connect(self.saveFigure3) self.buttons[3].clicked.connect(self.saveFigure4) self.buttons[4].clicked.connect(self.saveFigure5) elif len(self.titles) == 4: self.buttons[0].clicked.connect(self.saveFigure1) self.buttons[1].clicked.connect(self.saveFigure2) self.buttons[2].clicked.connect(self.saveFigure3) self.buttons[3].clicked.connect(self.saveFigure4) elif len(self.titles) == 3: self.buttons[0].clicked.connect(self.saveFigure1) self.buttons[1].clicked.connect(self.saveFigure2) self.buttons[2].clicked.connect(self.saveFigure3) elif len(self.titles) == 2: self.buttons[0].clicked.connect(self.saveFigure1) self.buttons[1].clicked.connect(self.saveFigure2) elif len(self.titles) == 1: self.buttons[0].clicked.connect(self.saveFigure1) def saveFigure1(self): filename = str(QtGui.QFileDialog.getSaveFileName(self, 'Save file', '', 'Image Files(*.png *.jpeg *.jpg *.tiff ' '*.bmp *.tif)', None)) if not filename: self.lblNoti.setText("To save a figure, provide a file name and click 'Save'.") else: self.lblNoti.setText('Saving... Please wait...') self.buttons[0].setEnabled(False) self.buttons[0].setFlat(True) plt.imsave(filename, self.images[0], cmap='gray') self.lblNoti.setText("Figure '" + self.titles[0] + "' Saved.") self.buttons[0].setEnabled(True) self.buttons[0].setFlat(False) def saveFigure2(self): filename = str(QtGui.QFileDialog.getSaveFileName(self, 'Save file', '', 'Image Files(*.png *.jpeg *.jpg *.tiff ' '*.bmp *.tif)', None)) if not filename: self.lblNoti.setText("To save a figure, provide a file name and click 'Save'.") else: self.lblNoti.setText('Saving... Please wait...') self.buttons[1].setEnabled(False) self.buttons[1].setFlat(True) plt.imsave(filename, self.images[1], cmap='gray') self.lblNoti.setText("Figure '" + self.titles[1] + "' Saved.") self.buttons[1].setEnabled(True) self.buttons[1].setFlat(False) def saveFigure3(self): filename = str(QtGui.QFileDialog.getSaveFileName(self, 'Save file', '', 'Image Files(*.png *.jpeg *.jpg *.tiff ' '*.bmp *.tif)', None)) if not filename: self.lblNoti.setText("To save a figure, provide a file name and click 'Save'.") else: self.lblNoti.setText('Saving... Please wait...') self.buttons[2].setEnabled(False) self.buttons[2].setFlat(True) plt.imsave(filename, self.images[2], cmap='gray') self.lblNoti.setText("Figure '" + self.titles[2] + "' Saved.") self.buttons[2].setEnabled(True) self.buttons[2].setFlat(False) def saveFigure4(self): filename = str(QtGui.QFileDialog.getSaveFileName(self, 'Save file', '', 'Image Files(*.png *.jpeg *.jpg *.tiff ' '*.bmp *.tif)', None)) if not filename: self.lblNoti.setText("To save a figure, provide a file name and click 'Save'.") else: self.lblNoti.setText('Saving... Please wait...') self.buttons[3].setEnabled(False) self.buttons[3].setFlat(True) plt.imsave(filename, self.images[3], cmap='gray') self.lblNoti.setText("Figure '" + self.titles[3] + "' Saved.") self.buttons[3].setEnabled(True) self.buttons[3].setFlat(False) def saveFigure5(self): filename = str(QtGui.QFileDialog.getSaveFileName(self, 'Save file', '', 'Image Files(*.png *.jpeg *.jpg *.tiff ' '*.bmp *.tif)', None)) if not filename: self.lblNoti.setText("To save a figure, provide a file name and click 'Save'.") else: self.lblNoti.setText('Saving... Please wait...') self.buttons[4].setEnabled(False) self.buttons[4].setFlat(True) plt.imsave(filename, self.images[4], cmap='gray') self.lblNoti.setText("Figure '" + self.titles[4] + "' Saved.") self.buttons[4].setEnabled(True) self.buttons[4].setFlat(False) def saveFigure6(self): filename = str(QtGui.QFileDialog.getSaveFileName(self, 'Save file', '', 'Image Files(*.png *.jpeg *.jpg *.tiff ' '*.bmp *.tif)', None)) if not filename: self.lblNoti.setText("To save a figure, provide a file name and click 'Save'.") else: self.lblNoti.setText('Saving... Please wait...') self.buttons[5].setEnabled(False) self.buttons[5].setFlat(True) plt.imsave(filename, self.images[5], cmap='gray') self.lblNoti.setText("Figure '" + self.titles[5] + "' Saved.") self.buttons[5].setEnabled(True) self.buttons[5].setFlat(False) def plot(self): R = 1 C = len(self.titles) for i in range(1, C + 1): fig = self.figure.add_subplot(R, C, i) fig.clear() fig.imshow(self.images[i - 1], cmap='gray') fig.set_title(self.titles[i - 1]) fig.axis('off') self.buttons[i - 1].setText("Save - '" + self.titles[i - 1] + "'") self.canvas.draw()