def __init__(self, settings, database): QWidget.__init__(self) last_files_list = LastFilesList(settings) self.settings = settings self.database = database self.ui = Ui_HomePage() self.ui.setupUi(self) self.toolbar = QToolBar() welcome_text = "{} {}".format(QApplication.instance().applicationName(), QApplication.instance().applicationVersion()) self.ui.welcome_label.setText(self.ui.welcome_label.text().format(welcome_text)) file_action = QtCommons.addToolbarPopup(self.toolbar, 'File', icon_file=':/file_20') project_action = QtCommons.addToolbarPopup(self.toolbar, 'Project', icon_file=':/project_20') #file_action.menu().addAction(QIcon(':/stack_20'), 'Stack Images', lambda: open_file_sticky('Open Reference FITS Image',FITS_IMG_EXTS, lambda f: self.stack_images.emit(f[0]), settings, IMPORT_IMG )) import_image_action = lambda: ImportImage.pick(lambda f: self.import_image.emit(f[0]), settings) file_action.menu().addAction(ImportImage.icon(), ImportImage.ACTION_TEXT, import_image_action) self.ui.import_image.clicked.connect(import_image_action) file_action.menu().addAction(QIcon(':/plot_20'), 'Calibrate Spectrum', lambda: open_file_sticky('Open raw FITS Spectrum',FITS_EXTS, lambda f: self.calibrate.emit(f[0]), settings, RAW_PROFILE, [IMPORT_IMG] )) file_action.menu().addAction(QIcon(':/math_20'), 'Spectra Math', lambda: self.math.emit(None) ) file_action.menu().addAction(QIcon(':/done_20'), 'Finish Spectrum', lambda: open_file_sticky('Open FITS Spectrum',FITS_EXTS, lambda f: self.finish.emit(f[0]), settings, CALIBRATED_PROFILE, [RAW_PROFILE,IMPORT_IMG] )) project_action.menu().addAction(QIcon(':/project_new_20'), 'New', lambda: self.new_project.emit()) pick_project = lambda: open_directory_sticky('Open Project', self.__project_picked, settings, PROJECTS) self.ui.pick_project.clicked.connect(pick_project) project_action.menu().addAction(QIcon(':/new_open_20'), 'Open...', pick_project) self.recent_raw_model = QStandardItemModel() self.recent_calibrated_model = QStandardItemModel() self.recent_projects_model = QStandardItemModel() self.ui.recent_raw_list.setModel(self.recent_raw_model) self.ui.recent_calibrated_list.setModel(self.recent_calibrated_model) self.ui.recent_projects.setModel(self.recent_projects_model) for widget in [self.ui.recent_raw_list, self.ui.recent_calibrated_list, self.ui.recent_projects]: widget.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) LastFilesList.instance().files_changed.connect(self.__populate_lists) selected_path = lambda model, view: model.item(view.selectionModel().selectedRows()[0].row()).data() button_enable = lambda view, button: view.selectionModel().selectionChanged.connect(lambda sel, desel: button.setEnabled(len(sel.indexes() )) ) button_enable(self.ui.recent_raw_list, self.ui.calibrate) button_enable(self.ui.recent_calibrated_list, self.ui.math) button_enable(self.ui.recent_calibrated_list, self.ui.finish) button_enable(self.ui.recent_projects, self.ui.open_recent_project) self.ui.calibrate.clicked.connect(lambda: self.calibrate.emit(selected_path(self.recent_raw_model, self.ui.recent_raw_list))) self.ui.math.clicked.connect(lambda: self.math.emit(selected_path(self.recent_calibrated_model, self.ui.recent_calibrated_list))) self.ui.finish.clicked.connect(lambda: self.finish.emit(selected_path(self.recent_calibrated_model, self.ui.recent_calibrated_list))) self.ui.open_recent_project.clicked.connect(lambda: self.open_project.emit(selected_path(self.recent_projects_model, self.ui.recent_projects))) self.ui.new_project.clicked.connect(self.new_project.emit) self.reference_catalogues = ReferenceCatalogues(database) self.ui.download_catalogs.clicked.connect(self.download_catalogs) self.__populate_lists()
def __init__(self): Instances.MainWindow = self font = QApplication.instance().font() rc('font', **{'family':'serif','serif':[font.defaultFamily()]}) super(PySpectrumMainWindow, self).__init__() self.ui = Ui_PySpectrumMainWindow() self.database = sqlite3.connect(os.path.join('data', 'pyspectrum.db')) self.ui.setupUi(self) self.settings = QSettings("GuLinux", "PySpectrum") self.homepage = HomePage(self.settings, self.database) self.ui.stackedWidget.addWidget(self.homepage) self.windows_menu = QtCommons.addToolbarPopup(self.ui.toolBar, 'Windows', icon_file=':/bullet_list_20') self.actionClose = self.ui.toolBar.addAction(QIcon(':/close_20'), "Close") self.actionClose.setEnabled(False) self.actionClose.triggered.connect(self.close_widget) self.homepage.import_image.connect(self.open_image) self.homepage.calibrate.connect(self.calibrate) self.homepage.math.connect(self.plots_math) self.homepage.finish.connect(self.finish_spectrum) self.homepage.new_project.connect(self.__new_project) self.homepage.stack_images.connect(self.__stack_images) self.homepage.open_project.connect(self.__open_project) self.ui.stackedWidget.currentChanged.connect(self.current_changed) self.current_widget_toolbar = None self.restoreGeometry(self.settings.value('window_geometry', QByteArray())) self.widgets = [(self.homepage, "Home")] self.current_changed(self.ui.stackedWidget.indexOf(self.homepage)) def action_checked(actions, action): for a in actions: a.setChecked(a == action) self.windows_menu.menu().triggered.connect(lambda a: action_checked(self.windows_menu.menu().actions(), a)) self.__rebuild_windows_menu()
def __init__(self, name, wavelength, axes, on_remove, show_wavelength = False, fontsize = 12, position = None, color='#80ff80'): self.axes = axes self.wavelength = wavelength self.name = name self.fontsize = fontsize self.show_lambda = show_wavelength self.on_remove = on_remove self.edit_dialog = QDialog() self.line = self.axes.axvline(wavelength, color=color) self.label = MoveableLabel(axes=axes, on_dblclick = lambda m: self.edit_dialog.show(), x=wavelength + 50, y=0.5, text=name, fontsize=fontsize) self.axes.figure.canvas.draw() self.press = None self.edit_dialog_ui = Ui_LineEdit() self.edit_dialog_ui.setupUi(self.edit_dialog) self.line_text = QtCommons.nestWidget(self.edit_dialog_ui.line_text_wrapper, GreekLineEdit()) self.edit_dialog_ui.show_lambda.setChecked(show_wavelength) self.edit_dialog_ui.wavelength.setText("{} Å".format(wavelength)) self.line_text.setText(name) self.edit_dialog.accepted.connect(self.update_line) self.edit_dialog_ui.reset_default_text.clicked.connect(lambda: self.line_text.setText(name)) text_size = self.label.get_size() self.edit_dialog_ui.text_size.setValue(text_size) self.edit_dialog_ui.reset_default_size.clicked.connect(lambda: self.edit_dialog_ui.text_size.setValue(text_size)) self.edit_dialog_ui.remove_line.clicked.connect(self.edit_dialog.reject) self.edit_dialog_ui.remove_line.clicked.connect(self.remove) self.update_line() if position: self.label.set_x(position[0]) self.label.set_y(position[1])
def __init__(self, fits_file, settings, database, project=None): super(CalibrateSpectrum, self).__init__() self.project=project self.settings = settings self.fits_spectrum = FitsSpectrum(fits_file) self.fits_spectrum.spectrum.normalize_to_max() self.fits_file = fits_file self.ui = Ui_CalibrateSpectrum() self.ui.setupUi(self) self.toolbar = QToolBar('Calibration Toolbar') self.toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.ui.x_axis_pick.setMenu(QMenu()) self.ui.x_axis_pick.menu().addAction("Maximum from range").triggered.connect(lambda: self.pick_from_range('maximum')) self.ui.x_axis_pick.menu().addAction("Minimum from range").triggered.connect(lambda: self.pick_from_range('minimum')) self.ui.x_axis_pick.menu().addAction("Central value from range").triggered.connect(lambda: self.pick_from_range('central')) self.ui.wavelength_pick.clicked.connect(lambda: self.lines_dialog.show()) save_action = self.toolbar.addAction(QIcon(':/save_20'), 'Save', self.save_spectrum) self.spectrum_plot = QtCommons.nestWidget(self.ui.spectrum_plot_widget, QMathPlotWidget()) self.reference_spectra_dialog = ReferenceSpectraDialog(database) self.reference_spectra_dialog.setup_menu(self.toolbar, self.spectrum_plot.axes, settings) self.object_properties = ObjectProperties(self.fits_file, project=project) self.object_properties_dialog = ObjectPropertiesDialog(settings, self.object_properties) self.toolbar.addAction("Object properties", self.object_properties_dialog.show) self.calibration_model = QStandardItemModel() self.calibration_model.setHorizontalHeaderLabels(["x-axis", "wavelength", "error"]) self.ui.calibration_points.setModel(self.calibration_model) self.ui.calibration_points.selectionModel().selectionChanged.connect(lambda selected, deselected: self.ui.remove_calibration_point.setEnabled(len(selected.indexes()) > 0) ) self.ui.add_calibration_point.clicked.connect(self.add_calibration_point) self.ui.remove_calibration_point.setEnabled(False) self.ui.remove_calibration_point.clicked.connect(self.remove_calibration_point) if project and project.avg_dispersion(): self.ui.set_dispersion.setMenu(QMenu()) self.ui.set_dispersion.menu().addAction('From input value', self.calculate_calibration) self.ui.set_dispersion.menu().addAction('From Project', lambda: self.calculate_calibration(project.avg_dispersion())) else: self.ui.set_dispersion.clicked.connect(self.calculate_calibration) self.ui.point_is_star.toggled.connect(lambda checked: self.ui.wavelength_pick.setEnabled(not checked)) self.ui.point_is_star.toggled.connect(lambda checked: self.ui.point_wavelength.setEnabled(not checked)) self.fits_spectrum.plot_to(self.spectrum_plot.axes) self.toolbar.addSeparator() self.toolbar.addAction("Zoom", self.spectrum_plot.select_zoom) self.toolbar.addAction("Reset Zoom", lambda: self.spectrum_plot.reset_zoom(self.fits_spectrum.spectrum.wavelengths, self.fits_spectrum.spectrum.fluxes.min(), self.fits_spectrum.spectrum.fluxes.max())) self.toolbar.addSeparator() self.lines_dialog = LinesDialog(database, settings, self.spectrum_plot, enable_picker = False, selection_mode = 'single') self.lines_dialog.lines.connect(self.picked_line) hdu_calibration_points = [h for h in self.fits_file if h.name == FitsSpectrum.CALIBRATION_DATA] if len(hdu_calibration_points) > 0: for point in hdu_calibration_points[-1].data: self.add_calibration_point_data(point[0], point[1]) self.calculate_calibration()
def __init__(self, fits_file, settings, project = None): super(ImportImage, self).__init__() self.settings = settings self.fits_file = fits_file self.project = project try: image_hdu_index = fits_file.index_of('IMAGE') except KeyError: image_hdu_index = 0 original_image = fits.ImageHDU(data=fits_file[image_hdu_index].data, header=fits_file[image_hdu_index].header, name='IMAGE') for hdu in [h for h in self.fits_file if h.name == 'IMAGE']: self.fits_file.remove(hdu) self.fits_file.append(original_image) self.ui = Ui_ImportImage() self.ui.setupUi(self) self.rotate_dialog = RotateImageDialog(self.fits_file, image_hdu_index, project=project) self.rotate_dialog.rotated.connect(self.rotated) self.image_plot = QtCommons.nestWidget(self.ui.image_widget, QImPlotWidget(self.rotate_dialog.data_rotated, cmap='gray')) self.spatial_plot = QtCommons.nestWidget(self.ui.spatial_plot_widget, QMathPlotWidget()) self.spectrum_plot = QtCommons.nestWidget(self.ui.spectrum_plot_widget, QMathPlotWidget()) self.image_view = self.image_plot.axes_image self.toolbar = QToolBar('Image Toolbar') self.toolbar.addAction(QIcon(':/rotate_20'), "Rotate", lambda: self.rotate_dialog.show()) self.toolbar.addAction(QIcon(':/save_20'), "Save", self.save_profile) self.toolbar.addAction(QIcon(':/select_all_20'), "Select spectrum data", lambda: self.spatial_plot.add_span_selector('select_spectrum', self.spectrum_span_selected,direction='horizontal')) self.toolbar.addAction(QIcon.fromTheme('edit-select-invert'), "Select background data", lambda: self.spatial_plot.add_span_selector('select_background', self.background_span_selected,direction='horizontal', rectprops = dict(facecolor='blue', alpha=0.5))).setEnabled(False) #self.toolbar.addAction('Stack', self.show_stack_images_dialog) self.toolbar.addSeparator() self.object_properties = ObjectProperties(self.fits_file, project=project) self.object_properties_dialog = ObjectPropertiesDialog(settings, self.object_properties) self.toolbar.addAction("Object properties", self.object_properties_dialog.show) self.rotated()
def __init__(self, name, wavelength, axes, on_remove, show_wavelength=False, fontsize=12, position=None, color='#80ff80'): self.axes = axes self.wavelength = wavelength self.name = name self.fontsize = fontsize self.show_lambda = show_wavelength self.on_remove = on_remove self.edit_dialog = QDialog() self.line = self.axes.axvline(wavelength, color=color) self.label = MoveableLabel( axes=axes, on_dblclick=lambda m: self.edit_dialog.show(), x=wavelength + 50, y=0.5, text=name, fontsize=fontsize) self.axes.figure.canvas.draw() self.press = None self.edit_dialog_ui = Ui_LineEdit() self.edit_dialog_ui.setupUi(self.edit_dialog) self.line_text = QtCommons.nestWidget( self.edit_dialog_ui.line_text_wrapper, GreekLineEdit()) self.edit_dialog_ui.show_lambda.setChecked(show_wavelength) self.edit_dialog_ui.wavelength.setText("{} Å".format(wavelength)) self.line_text.setText(name) self.edit_dialog.accepted.connect(self.update_line) self.edit_dialog_ui.reset_default_text.clicked.connect( lambda: self.line_text.setText(name)) text_size = self.label.get_size() self.edit_dialog_ui.text_size.setValue(text_size) self.edit_dialog_ui.reset_default_size.clicked.connect( lambda: self.edit_dialog_ui.text_size.setValue(text_size)) self.edit_dialog_ui.remove_line.clicked.connect( self.edit_dialog.reject) self.edit_dialog_ui.remove_line.clicked.connect(self.remove) self.update_line() if position: self.label.set_x(position[0]) self.label.set_y(position[1])
def __init__(self, settings, database, project=None): super(PlotsMath, self).__init__() self.ui = Ui_PlotsMath() self.ui.setupUi(self) self.settings = settings self.project=project self.plot = QtCommons.nestWidget(self.ui.plot, QMathPlotWidget()) self.reference_dialog = ReferenceSpectraDialog(database) self.reference_dialog.fits_picked.connect(self.open_fits) self.toolbar = QToolBar('Instrument Response Toolbar') open_btn = QtCommons.addToolbarPopup(self.toolbar, text="Open...", icon_file=':/new_open_20') open_file_action = open_btn.menu().addAction('FITS file') open_btn.menu().addAction('Reference library', self.reference_dialog.show) self.blackbody_menu = blackbody.BlackBodyAction(self.blackbody, open_btn.menu()) if project: save_result = QtCommons.addToolbarPopup(self.toolbar, text='Save', icon_file=':/save_20') save_result.menu().addAction('As File', lambda: QtCommons.save_file('Save Operation Result...', FITS_EXTS, lambda f: self.save(f[0]), project.path)) save_result.menu().addAction('As Instrument Response', self.save_project_instrument_response) open_file_action.triggered.connect(lambda: QtCommons.open_file('Open FITS Spectrum',FITS_EXTS, lambda f: self.open_fits(f[0]), project.path)) else: open_file_action.triggered.connect(lambda: open_file_sticky('Open FITS Spectrum',FITS_EXTS, lambda f: self.open_fits(f[0]), self.settings, CALIBRATED_PROFILE, [RAW_PROFILE])) self.toolbar.addAction(QIcon(':/save_20'), 'Save', lambda: save_file_sticky('Save Operation Result...', 'FITS file (.fit)', lambda f: self.save(f[0]), self.settings, MATH_OPERATION, [CALIBRATED_PROFILE])) self.toolbar.addAction('Set operand', self.set_operand) self.toolbar.addSeparator() self.toolbar.addAction(self.ui.actionZoom) self.ui.actionZoom.triggered.connect(self.start_zoom) self.toolbar.addAction(self.ui.actionReset_Zoom) self.ui.actionReset_Zoom.triggered.connect(self.reset_zoom) self.toolbar.addSeparator() self.operands_model = QStandardItemModel() self.ui.operands_listview.setModel(self.operands_model) remove_btn = QtCommons.addToolbarPopup(self.toolbar, text='Remove...') remove_btn.menu().addAction(self.ui.actionSelectPointsToRemove) remove_btn.menu().addAction("Before point", lambda: spectrum_trim_dialog(self.spectrum, 'before', self.plot.axes, lambda: self.draw(), self, before_removal=self.undo.save_undo)) remove_btn.menu().addAction("After point", lambda: spectrum_trim_dialog(self.spectrum, 'after', self.plot.axes, lambda: self.draw(), self, before_removal=self.undo.save_undo)) self.ui.clear_operands.clicked.connect(self.operands_model.clear) self.ui.remove_operand.clicked.connect(lambda: self.operands_model.removeRows(self.ui.operands_listview.selectionModel().selectedRows()[0].row(), 1)) self.operands_model.rowsInserted.connect(lambda: self.ui.clear_operands.setEnabled(self.operands_model.rowCount() > 0) ) self.operands_model.rowsRemoved.connect(lambda: self.ui.clear_operands.setEnabled(self.operands_model.rowCount() > 0) ) self.ui.operands_listview.selectionModel().selectionChanged.connect(lambda s, u: self.ui.remove_operand.setEnabled(len(s))) self.ui.actionSelectPointsToRemove.triggered.connect(self.pick_rm_points) self.undo = Undo(None, self.draw) self.undo.add_actions(self.toolbar) self.ui.spline_factor.valueChanged.connect(self.factor_valueChanged) self.ui.spline_degrees.valueChanged.connect(lambda v: self.draw()) self.ui.spline_factor_auto.toggled.connect(lambda v: self.draw()) self.ui.spline_factor_auto.toggled.connect(lambda v: self.ui.spline_factor.setEnabled(not v)) self.ui.execute.clicked.connect(self.execute_operation) self.plot.figure.tight_layout()
def __init__(self, data, min, max, settings, type): super(SelectPlottedPoints, self).__init__() self.ui = Ui_SelectPlottedPoints() self.ui.setupUi(self) self.type = type self.min = min self.y_axis = data[min:max] self.x_axis = np.arange(min, min+len(self.y_axis)) self.ui.x_coordinate.setRange(self.x_axis[0], self.x_axis[-1]) self.plot = QtCommons.nestWidget(self.ui.plot_widget, QMathPlotWidget()) self.finished.connect(lambda: self.deleteLater()) self.ui.smoothing_factor.valueChanged.connect(self.factor_valueChanged) self.ui.smoothing_degree.valueChanged.connect(lambda v: self.draw()) self.ui.smoothing_factor_auto.toggled.connect(lambda v: self.draw()) self.ui.smoothing_factor_auto.toggled.connect(lambda v: self.ui.smoothing_factor.setEnabled(not v)) self.restoreGeometry(settings.value('select_plotted_points_geometry', QByteArray())) self.finished.connect(lambda: settings.setValue('select_plotted_points_geometry', self.saveGeometry())) self.ui.x_coordinate.valueChanged.connect(self.set_point) QTimer.singleShot(100, self.draw)
def __init__(self): Instances.MainWindow = self font = QApplication.instance().font() rc('font', **{'family': 'serif', 'serif': [font.defaultFamily()]}) super(PySpectrumMainWindow, self).__init__() self.ui = Ui_PySpectrumMainWindow() self.database = sqlite3.connect(os.path.join('data', 'pyspectrum.db')) self.ui.setupUi(self) self.settings = QSettings("GuLinux", "PySpectrum") self.homepage = HomePage(self.settings, self.database) self.ui.stackedWidget.addWidget(self.homepage) self.windows_menu = QtCommons.addToolbarPopup( self.ui.toolBar, 'Windows', icon_file=':/bullet_list_20') self.actionClose = self.ui.toolBar.addAction(QIcon(':/close_20'), "Close") self.actionClose.setEnabled(False) self.actionClose.triggered.connect(self.close_widget) self.homepage.import_image.connect(self.open_image) self.homepage.calibrate.connect(self.calibrate) self.homepage.math.connect(self.plots_math) self.homepage.finish.connect(self.finish_spectrum) self.homepage.new_project.connect(self.__new_project) self.homepage.stack_images.connect(self.__stack_images) self.homepage.open_project.connect(self.__open_project) self.ui.stackedWidget.currentChanged.connect(self.current_changed) self.current_widget_toolbar = None self.restoreGeometry( self.settings.value('window_geometry', QByteArray())) self.widgets = [(self.homepage, "Home")] self.current_changed(self.ui.stackedWidget.indexOf(self.homepage)) def action_checked(actions, action): for a in actions: a.setChecked(a == action) self.windows_menu.menu().triggered.connect( lambda a: action_checked(self.windows_menu.menu().actions(), a)) self.__rebuild_windows_menu()
def __init__(self, data, min, max, settings, type): super(SelectPlottedPoints, self).__init__() self.ui = Ui_SelectPlottedPoints() self.ui.setupUi(self) self.type = type self.min = min self.y_axis = data[min:max] self.x_axis = np.arange(min, min + len(self.y_axis)) self.ui.x_coordinate.setRange(self.x_axis[0], self.x_axis[-1]) self.plot = QtCommons.nestWidget(self.ui.plot_widget, QMathPlotWidget()) self.finished.connect(lambda: self.deleteLater()) self.ui.smoothing_factor.valueChanged.connect(self.factor_valueChanged) self.ui.smoothing_degree.valueChanged.connect(lambda v: self.draw()) self.ui.smoothing_factor_auto.toggled.connect(lambda v: self.draw()) self.ui.smoothing_factor_auto.toggled.connect( lambda v: self.ui.smoothing_factor.setEnabled(not v)) self.restoreGeometry( settings.value('select_plotted_points_geometry', QByteArray())) self.finished.connect(lambda: settings.setValue( 'select_plotted_points_geometry', self.saveGeometry())) self.ui.x_coordinate.valueChanged.connect(self.set_point) QTimer.singleShot(100, self.draw)
def __init__(self, fits_file, settings, database, project=None): super(CalibrateSpectrum, self).__init__() self.project = project self.settings = settings self.fits_spectrum = FitsSpectrum(fits_file) self.fits_spectrum.spectrum.normalize_to_max() self.fits_file = fits_file self.ui = Ui_CalibrateSpectrum() self.ui.setupUi(self) self.toolbar = QToolBar('Calibration Toolbar') self.toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.ui.x_axis_pick.setMenu(QMenu()) self.ui.x_axis_pick.menu().addAction( "Maximum from range").triggered.connect( lambda: self.pick_from_range('maximum')) self.ui.x_axis_pick.menu().addAction( "Minimum from range").triggered.connect( lambda: self.pick_from_range('minimum')) self.ui.x_axis_pick.menu().addAction( "Central value from range").triggered.connect( lambda: self.pick_from_range('central')) self.ui.wavelength_pick.clicked.connect( lambda: self.lines_dialog.show()) save_action = self.toolbar.addAction(QIcon(':/save_20'), 'Save', self.save_spectrum) self.spectrum_plot = QtCommons.nestWidget(self.ui.spectrum_plot_widget, QMathPlotWidget()) self.reference_spectra_dialog = ReferenceSpectraDialog(database) self.reference_spectra_dialog.setup_menu(self.toolbar, self.spectrum_plot.axes, settings) self.object_properties = ObjectProperties(self.fits_file, project=project) self.object_properties_dialog = ObjectPropertiesDialog( settings, self.object_properties) self.toolbar.addAction("Object properties", self.object_properties_dialog.show) self.calibration_model = QStandardItemModel() self.calibration_model.setHorizontalHeaderLabels( ["x-axis", "wavelength", "error"]) self.ui.calibration_points.setModel(self.calibration_model) self.ui.calibration_points.selectionModel().selectionChanged.connect( lambda selected, deselected: self.ui.remove_calibration_point. setEnabled(len(selected.indexes()) > 0)) self.ui.add_calibration_point.clicked.connect( self.add_calibration_point) self.ui.remove_calibration_point.setEnabled(False) self.ui.remove_calibration_point.clicked.connect( self.remove_calibration_point) if project and project.avg_dispersion(): self.ui.set_dispersion.setMenu(QMenu()) self.ui.set_dispersion.menu().addAction('From input value', self.calculate_calibration) self.ui.set_dispersion.menu().addAction( 'From Project', lambda: self.calculate_calibration(project.avg_dispersion())) else: self.ui.set_dispersion.clicked.connect(self.calculate_calibration) self.ui.point_is_star.toggled.connect( lambda checked: self.ui.wavelength_pick.setEnabled(not checked)) self.ui.point_is_star.toggled.connect( lambda checked: self.ui.point_wavelength.setEnabled(not checked)) self.fits_spectrum.plot_to(self.spectrum_plot.axes) self.toolbar.addSeparator() self.toolbar.addAction("Zoom", self.spectrum_plot.select_zoom) self.toolbar.addAction( "Reset Zoom", lambda: self.spectrum_plot.reset_zoom( self.fits_spectrum.spectrum.wavelengths, self.fits_spectrum.spectrum.fluxes.min(), self.fits_spectrum.spectrum.fluxes.max())) self.toolbar.addSeparator() self.lines_dialog = LinesDialog(database, settings, self.spectrum_plot, enable_picker=False, selection_mode='single') self.lines_dialog.lines.connect(self.picked_line) hdu_calibration_points = [ h for h in self.fits_file if h.name == FitsSpectrum.CALIBRATION_DATA ] if len(hdu_calibration_points) > 0: for point in hdu_calibration_points[-1].data: self.add_calibration_point_data(point[0], point[1]) self.calculate_calibration()
def __init__(self, settings, database): QWidget.__init__(self) last_files_list = LastFilesList(settings) self.settings = settings self.database = database self.ui = Ui_HomePage() self.ui.setupUi(self) self.toolbar = QToolBar() welcome_text = "{} {}".format( QApplication.instance().applicationName(), QApplication.instance().applicationVersion()) self.ui.welcome_label.setText( self.ui.welcome_label.text().format(welcome_text)) file_action = QtCommons.addToolbarPopup(self.toolbar, 'File', icon_file=':/file_20') project_action = QtCommons.addToolbarPopup(self.toolbar, 'Project', icon_file=':/project_20') #file_action.menu().addAction(QIcon(':/stack_20'), 'Stack Images', lambda: open_file_sticky('Open Reference FITS Image',FITS_IMG_EXTS, lambda f: self.stack_images.emit(f[0]), settings, IMPORT_IMG )) import_image_action = lambda: ImportImage.pick( lambda f: self.import_image.emit(f[0]), settings) file_action.menu().addAction(ImportImage.icon(), ImportImage.ACTION_TEXT, import_image_action) self.ui.import_image.clicked.connect(import_image_action) file_action.menu().addAction( QIcon(':/plot_20'), 'Calibrate Spectrum', lambda: open_file_sticky( 'Open raw FITS Spectrum', FITS_EXTS, lambda f: self.calibrate. emit(f[0]), settings, RAW_PROFILE, [IMPORT_IMG])) file_action.menu().addAction(QIcon(':/math_20'), 'Spectra Math', lambda: self.math.emit(None)) file_action.menu().addAction( QIcon(':/done_20'), 'Finish Spectrum', lambda: open_file_sticky( 'Open FITS Spectrum', FITS_EXTS, lambda f: self.finish.emit(f[ 0]), settings, CALIBRATED_PROFILE, [RAW_PROFILE, IMPORT_IMG])) project_action.menu().addAction(QIcon(':/project_new_20'), 'New', lambda: self.new_project.emit()) pick_project = lambda: open_directory_sticky( 'Open Project', self.__project_picked, settings, PROJECTS) self.ui.pick_project.clicked.connect(pick_project) project_action.menu().addAction(QIcon(':/new_open_20'), 'Open...', pick_project) self.recent_raw_model = QStandardItemModel() self.recent_calibrated_model = QStandardItemModel() self.recent_projects_model = QStandardItemModel() self.ui.recent_raw_list.setModel(self.recent_raw_model) self.ui.recent_calibrated_list.setModel(self.recent_calibrated_model) self.ui.recent_projects.setModel(self.recent_projects_model) for widget in [ self.ui.recent_raw_list, self.ui.recent_calibrated_list, self.ui.recent_projects ]: widget.horizontalHeader().setSectionResizeMode( QHeaderView.ResizeToContents) LastFilesList.instance().files_changed.connect(self.__populate_lists) selected_path = lambda model, view: model.item(view.selectionModel( ).selectedRows()[0].row()).data() button_enable = lambda view, button: view.selectionModel( ).selectionChanged.connect(lambda sel, desel: button.setEnabled( len(sel.indexes()))) button_enable(self.ui.recent_raw_list, self.ui.calibrate) button_enable(self.ui.recent_calibrated_list, self.ui.math) button_enable(self.ui.recent_calibrated_list, self.ui.finish) button_enable(self.ui.recent_projects, self.ui.open_recent_project) self.ui.calibrate.clicked.connect(lambda: self.calibrate.emit( selected_path(self.recent_raw_model, self.ui.recent_raw_list))) self.ui.math.clicked.connect(lambda: self.math.emit( selected_path(self.recent_calibrated_model, self.ui. recent_calibrated_list))) self.ui.finish.clicked.connect(lambda: self.finish.emit( selected_path(self.recent_calibrated_model, self.ui. recent_calibrated_list))) self.ui.open_recent_project.clicked.connect( lambda: self.open_project.emit( selected_path(self.recent_projects_model, self.ui. recent_projects))) self.ui.new_project.clicked.connect(self.new_project.emit) self.reference_catalogues = ReferenceCatalogues(database) self.ui.download_catalogs.clicked.connect(self.download_catalogs) self.__populate_lists()