def remove_backgrounds(self, specimens): """ Opens the 'remove background' dialog for the given specimens, raises a ValueError error if (one of) the specimens is not part of this project. """ def on_automated(dialog): for specimen in specimens: if not specimen in self.model.specimens: raise ValueError("Specimen `%s` is not part of this Project!" % specimen) else: specimen.experimental_pattern.bg_type = 0 # Linear see settings specimen.experimental_pattern.find_bg_position() specimen.experimental_pattern.remove_background() specimen.experimental_pattern.clear_bg_variables() def on_not_automated(dialog): for specimen in specimens: if not specimen in self.model.specimens: raise ValueError("Specimen `%s` is not part of this Project!" % specimen) else: bg_view = BackgroundView(parent=self.parent.view) BackgroundController(model=specimen.experimental_pattern, view=bg_view, parent=self) bg_view.present() # Ask user if he/she wants automation: DialogFactory.get_confirmation_dialog( "Do you want to perform an automated linear background subtraction?", parent=self.parent.view.get_top_widget() ).run(on_automated, on_not_automated)
def remove_backgrounds(self, specimens): """ Opens the 'remove background' dialog for the given specimens, raises a ValueError error if (one of) the specimens is not part of this project. """ def on_automated(dialog): for specimen in specimens: if not specimen in self.model.specimens: raise ValueError, "Specimen `%s` is not part of this Project!" % specimen else: specimen.experimental_pattern.bg_type = 0 # Linear see settings specimen.experimental_pattern.find_bg_position() specimen.experimental_pattern.remove_background() specimen.experimental_pattern.clear_bg_variables() def on_not_automated(dialog): for specimen in specimens: if not specimen in self.model.specimens: raise ValueError, "Specimen `%s` is not part of this Project!" % specimen else: bg_view = BackgroundView(parent=self.parent.view) BackgroundController(model=specimen.experimental_pattern, view=bg_view, parent=self) bg_view.present() # Ask user if he/she wants automation: DialogFactory.get_confirmation_dialog( "Do you want to perform an automated linear background subtraction?", parent=self.parent.view.get_top_widget()).run( on_automated, on_not_automated)
def on_find_peaks_clicked(self, widget): def after_cb(threshold): self.model.auto_add_peaks(threshold) sel_model = ThresholdSelector(parent=self.model) sel_view = DetectPeaksView(parent=self.view) sel_ctrl = ThresholdController(model=sel_model, view=sel_view, parent=self, callback=after_cb) #@UnusedVariable show_threshold_plot = DialogFactory.get_progress_dialog( action=sel_model.update_threshold_plot_data, complete_callback=lambda *a, **k: sel_view.present(), gui_message="Finding peaks {progress:.0f}%...", toplevel=self.view.get_top_widget() ) if len(self.model.markers) > 0: def on_accept(dialog): self.model.clear_markers() show_threshold_plot() def on_reject(dialog): show_threshold_plot() DialogFactory.get_confirmation_dialog( "Do you want to clear the current markers for this pattern?", parent=self.view.get_top_widget() ).run(on_accept, on_reject) else: show_threshold_plot()
def on_import_wavelength_distribution_clicked(self, widget, data=None): def on_confirm(dialog): def on_accept(dialog): filename = dialog.filename parser = dialog.parser message = "An unexpected error has occurred when trying to parse %s:\n\n<i>" % os.path.basename( filename) message += "{}</i>\n\n" message += "This is most likely caused by an invalid or unsupported file format." with DialogFactory.error_dialog_handler( message, parent=self.view.get_toplevel(), reraise=False): self.model.wavelength_distribution.load_data(parser, filename, clear=True) DialogFactory.get_load_dialog( title="Import wavelength distribution", parent=self.view.get_top_widget(), filters=wld_parsers.get_import_file_filters(), current_folder=settings.DATA_REG.get_directory_path( "DEFAULT_WL_DISTR")).run(on_accept) DialogFactory.get_confirmation_dialog( "Importing a wavelength distribution will erase all current data.\nAre you sure you want to continue?", parent=self.view.get_top_widget()).run(on_confirm)
def on_find_peaks_clicked(self, widget): def after_cb(threshold): self.model.auto_add_peaks(threshold) sel_model = ThresholdSelector(parent=self.model) sel_view = DetectPeaksView(parent=self.view) sel_ctrl = ThresholdController(model=sel_model, view=sel_view, parent=self, callback=after_cb) #@UnusedVariable sel_model.update_threshold_plot_data() if len(self.model.markers) > 0: def on_accept(dialog): self.model.clear_markers() sel_view.present() def on_reject(dialog): sel_view.present() DialogFactory.get_confirmation_dialog( "Do you want to clear the current markers for this pattern?", parent=self.view.get_top_widget()).run(on_accept, on_reject) else: sel_view.present()
def on_find_peaks_clicked(self, widget): def after_cb(threshold): self.model.auto_add_peaks(threshold) sel_model = ThresholdSelector(parent=self.model) sel_view = DetectPeaksView(parent=self.view) sel_ctrl = ThresholdController(model=sel_model, view=sel_view, parent=self, callback=after_cb) #@UnusedVariable show_threshold_plot = DialogFactory.get_progress_dialog( action=sel_model.update_threshold_plot_data, complete_callback=lambda *a, **k: sel_view.present(), gui_message="Finding peaks {progress:.0f}%...", toplevel=self.view.get_top_widget()) if len(self.model.markers) > 0: def on_accept(dialog): self.model.clear_markers() show_threshold_plot() def on_reject(dialog): show_threshold_plot() DialogFactory.get_confirmation_dialog( "Do you want to clear the current markers for this pattern?", parent=self.view.get_top_widget()).run(on_accept, on_reject) else: show_threshold_plot()
def on_import_exclusion_ranges_clicked(self, widget, data=None): def on_confirm(dialog): def on_accept(dialog): filename = dialog.filename parser = dialog.parser message = "An unexpected error has occured when trying to parse %s:\n\n<i>" % os.path.basename( filename) message += "{}</i>\n\n" message += "This is most likely caused by an invalid or unsupported file format." with DialogFactory.error_dialog_handler( message, parent=self.view.get_toplevel(), reraise=False): self.model.exclusion_ranges.load_data(parser, filename, clear=True) DialogFactory.get_load_dialog( title="Import exclusion ranges", parent=self.view.get_top_widget(), filters=exc_parsers.get_import_file_filters()).run(on_accept) DialogFactory.get_confirmation_dialog( "Importing exclusion ranges will erase all current data.\nAre you sure you want to continue?", parent=self.view.get_top_widget()).run(on_confirm)
def on_btn_import_raw_pattern_clicked(self, widget, data=None): def on_confirm(dialog): self.on_replace_raw_pattern() DialogFactory.get_confirmation_dialog( "Importing a new experimental file will erase all current data.\nAre you sure you want to continue?", parent=self.view.get_toplevel()).run(on_confirm) return True
def on_btn_import_experimental_data_clicked(self, widget, data=None): def on_confirm(dialog): self.on_replace_experimental_data() DialogFactory.get_confirmation_dialog( "Importing a new experimental file will erase all current data.\nAre you sure you want to continue?", parent=self.view.get_top_widget() ).run(on_confirm) return True
def on_load_object_clicked(self, widget, user_data=None): def import_layer(dialog): def on_accept(dialog): del self.treemodel_data[:] # clears the list Atom.get_from_csv(dialog.filename, self.treemodel_data.append, self.model) DialogFactory.get_load_dialog( "Import atoms", parent=self.view.get_toplevel(), filters=self.file_filters ).run(on_accept) DialogFactory.get_confirmation_dialog( message="Are you sure?\nImporting a layer file will clear the current list of atoms!", parent=self.view.get_toplevel() ).run(import_layer)
def delete_selected_specimens(self): """ Asks the user for confirmation and if positive deletes all the selected specimens. Does nothing when no specimens are selected. """ selection = self.get_selected_objects() if selection is not None and len(selection) >= 1: def delete_objects(dialog): for obj in selection: if obj is not None: self.model.specimens.remove(obj) DialogFactory.get_confirmation_dialog( message='Deleting a specimen is irreversible!\nAre You sure you want to continue?', parent=self.view.get_top_widget() ).run(delete_objects)
def on_cmb_import_gonio_changed(self, combobox, *args): model = combobox.get_model() itr = combobox.get_active_iter() if itr: # first column is the name, second column the path and third column # a flag indicating if this can be selected path = model.get_value(itr, 1) if path: def on_accept(dialog): self.model.reset_from_file(path) DialogFactory.get_confirmation_dialog( "Are you sure?\nYou will loose the current settings!", parent=self.view.get_toplevel()).run(on_accept) combobox.set_active(-1) # deselect
def accept_wrapper(self, *args, **kwargs): if self.model.check_for_changes(): return DialogFactory.get_confirmation_dialog( confirm_msg, parent=self.view.get_top_widget() ).run(lambda d: on_accept(self, *args, **kwargs), on_reject) else: return on_accept(self, *args, **kwargs)
def accept_wrapper(self, *args, **kwargs): if self.model.current_project and self.model.current_project.needs_saving: return DialogFactory.get_confirmation_dialog( confirm_msg, parent=self.view.get_top_widget() ).run(lambda d: on_accept(self, *args, **kwargs), on_reject) else: return on_accept(self, *args, **kwargs)
def on_del_object_clicked(self, event, del_callback=None, callback=None): tv = self.view.treeview selection = tv.get_selection() if selection.count_selected_rows() >= 1: def delete_objects(dialog): with self._multi_operation_context(): for obj in self.get_selected_objects(): if callable(del_callback): del_callback(obj) else: self.treemodel_data.remove(obj) if callable(callback): callback(obj) self.edit_object(None) parent = self.view.get_top_widget() if not isinstance(parent, Gtk.Window): # @UndefinedVariable parent = None DialogFactory.get_confirmation_dialog( message=self.delete_msg, parent=parent ).run(delete_objects)
def on_import_exclusion_ranges_clicked(self, widget, data=None): def on_confirm(dialog): def on_accept(dialog): filename = dialog.filename parser = dialog.parser message = "An unexpected error has occured when trying to parse %s:\n\n<i>" % os.path.basename(filename) message += "{}</i>\n\n" message += "This is most likely caused by an invalid or unsupported file format." with DialogFactory.error_dialog_handler(message, parent=self.view.get_toplevel(), reraise=False): self.model.exclusion_ranges.load_data(parser, filename, clear=True) DialogFactory.get_load_dialog( title="Import exclusion ranges", parent=self.view.get_top_widget(), filters=exc_parsers.get_import_file_filters() ).run(on_accept) DialogFactory.get_confirmation_dialog( "Importing exclusion ranges will erase all current data.\nAre you sure you want to continue?", parent=self.view.get_top_widget() ).run(on_confirm)