quicknxs.interfaces.event_handlers package

Qt Event Handlers.

Submodules

quicknxs.interfaces.event_handlers.configuration_handler module

class quicknxs.interfaces.event_handlers.configuration_handler.ConfigurationHandler(main_window)[source]

Bases: object

Handles events upon changes in the configuration.

Configuration state that is global to all runs is stored as class variables in the class Configuration. This class handles updating the configuration state upon changes in the UI configuration elements, as well as triggering any recalculation and replotting needed as a consequence of the changed configuration.

config_setter_factory(qwidget: QWidget, config_name: str)[source]

Factory function to create configuration setters.

Generates anonymous functions to serve as callback when any of the global configurations (Configuration class variables) are updated in the UI.

Each callback will be associated to one configuration parameter. Upon invoked, the Configuration class variable value will be updated.

Parameters:
  • qwidget (QWidget) – UI widget

  • config_name (str) – Name of the Configuration variable to update

connect_config_events()[source]

Connect configuration widget events.

global_reflectivity_updater()[source]

Recalculate and replot reflectivity upon change in global reflectivity configuration.

quicknxs.interfaces.event_handlers.main_handler module

Manage file-related and UI events.

class quicknxs.interfaces.event_handlers.main_handler.MainHandler(main_window)[source]

Bases: object

Event handler for the main application window.

DIRECT_BEAM_TAB_INDEX = 0
MAIN_DATA_TAB_INDEX = 1
active_cross_section_changed()[source]

Update UI metadata and plots after the active cross section is changed.

active_data_changed()[source]

Actions to be taken once the active data set has changed.

add_direct_beam(silent=False)[source]

Add dataset to the direct beam table.

add_reflectivity(silent=False)[source]

Collect information about the current extraction settings and store them in the list of reduction items.

Returns:

True if everything is ok, false otherwise.

Return type:

bool

ask_question(message: str) bool[source]

Display a popup dialog with a message and choices “Ok” and “Cancel”.

automated_file_selection()[source]

Automatically select files in the current directory based on incident angle.

Go through the files in the current in order of run numbers, and load files until the incident angle is no longer increasing.

change_log_level(level: str)[source]

Update all handlers + root logger to new level.

check_region_values_changed()[source]

Return true if any of the parameters tied to a particular slot has changed.

Some parameters are tied to the changeRegionValues() slot. There are time-consuming actions that we only want to take if those values actually changed, as opposed to the use simply clicking outside the box.

Some parameters don’t require a recalculation but simply a refreshing of the plots. Those are parameters such as scaling factors or the number of points clipped.

Returns:

-1 = no valid change,

0 = replot needed, 1 = recalculation needed

Return type:

int

clear_direct_beams()[source]

Remove all items from the direct beam list.

clear_reflectivity()[source]

Remove all items from the reduction lists.

compute_gisans_on_change(force=False, active_only=True)[source]

Compute GISANS as needed.

compute_offspec_on_change(force=False)[source]

Compute off-specular as needed.

property direct_beam_table: QTableWidget

Returns the direct beam table widget.

direct_beam_table_changed(item: QTableWidgetItem)[source]

Perform action upon change in direct beam list.

empty_cache()[source]

Empty the data cache.

file_loaded()[source]

Update UI after a file is loaded.

file_open_dialog()[source]

GUI callback for backend MainHandler._file_open_dialog.

file_open_sum_dialog()[source]

GUI callback for backend MainHandler._file_open_sum_dialog.

get_configuration_from_ui() Configuration[source]

Gather the reduction options.

Retrieve the reduction options either from the active cross section, or from the current settings in the graphical interface.

Note that some options are global (static members of Configuration class), while others are per-cross-section (members of Configuration instance). This is because some options are applied to all cross-sections (e.g. whether to use a ROI or not), while others are specific to each cross-section (e.g. the peak position and width).

get_log_level()[source]

Return current root logger level as a string for GUI dropdown.

get_reduction_table_by_index(tab_index: int) QTableWidget[source]

Return the QTableWidget for the data tab with the given index.

hide_data_table()[source]
hide_run_data()[source]
hide_sidebar()[source]
initialize_additional_reduction_table(tab_index: int)[source]

Initialize new reduction table from the main reduction table.

Parameters:

tab_index (int) – Index of the additional tab/peak

new_progress_reporter()[source]

Return a progress reporter.

open_file(file_path: str, force: bool = False, silent: bool = False) None[source]

Read one or more data files. If more than one, merge their data.

Parameters:
  • file_path – Absolute path to data files. If more than one file, paths are joined with the plus symbol ‘+’

  • force – if true, the file will be reloaded even if it was loaded previously

  • silent – if true, the plots currently shown in the interface will NOT be updated

open_reduced_file_dialog()[source]

Open a reduced file and all the data files needed to reproduce it.

open_run_number(number: List[int] | List[str] | int | str | None = None)[source]

Open a data file by typing a run number or a composite run number for merging data sets.

Example

“120:123+125+127:132” opens files with run numbers from 120 to 132 except 124 and 126

populate_from_configuration(configuration=None)[source]

Set reduction options in UI, usually after loading a reduced data set.

propagate_binning_options_to_run_config()[source]

Enable the selected binning type with the given Q-step for all runs in the active data tab.

Note: This function updates the UI and internal configuration state while blocking all signals. The caller is responsible for triggering recalculation and replotting.

property reduction_table: QTableWidget

Returns the active reduction table widget if one of the data tabs is active, else the first one.

reduction_table_binning_type_changed(combobox_index: int, row: int)[source]

Perform action upon change in binning type column in the UI reduction table.

Parameters:
  • combobox_index (int) – The selected index in the combobox

  • row (int) – The row in the reduction table to update.

reduction_table_cell_changed(refl: NexusData, recalculate: bool = True)[source]

Perform action upon change in UI reduction table.

Updates the internal configuration state and recalculates the reflectivity.

Parameters:
  • refl (NexusData) – The data set to update.

  • recalculate (bool, optional) – Whether to recalculate the reflectivity, by default True

reduction_table_changed(item: QTableWidgetItem)[source]

Perform action upon change in data reduction list.

Parameters:

item (QTableWidgetItem) – The changed table item

reduction_table_right_click(pos: QPoint, is_reduction_table: bool = True)[source]

Handle right-click on the reduction table.

Parameters:
  • pos – Mouse position

  • is_reduction_table – True if the reduction table is active, False if the direct beam table is active

reload_all_files()[source]

Reload all files upon change in loading configuration.

To speed up reloading, the file cache is first cleared of files that are not used in the reduction list or direct beam list.

remove_direct_beam()[source]

Remove one item from the direct beam list.

remove_reflectivity()[source]

Remove one item from the reduction list.

report_message(message: str, informative_message: str | None = None, detailed_message: str | None = None, pop_up: bool = False, is_error: bool = False)[source]

Report a message or error to the status bar at the bottom of the window.

If is_error is True, the message is also logged on the error channel.

save_run_data(nexus_data: NexusData)[source]

Save run data to file.

show_results()[source]

Pop up the result viewer.

stitch_reflectivity()[source]

Stitch the reflectivity parts and normalize to 1.

strip_overlap()[source]

Remove overlapping points in the reflectivity, cutting always from the lower Qz measurements.

trim_data_to_normalization()[source]

Cut the start and end of the active data set to 5% of its maximum intensity.

update_calculated_data()[source]

Update the calculated entries in the overview tab.

We should call this after the peak ranges change, or after a change is made that will affect the displayed results.

update_cross_section_info()[source]

Update cross section metadata shown in the overview tab.

update_daslog()[source]

Write parameters from all file daslogs to the table in the daslog tab.

update_direct_beam_table(idx: int, data: CrossSectionData) None[source]

Update a direct beam table entry with cross-section data.

Parameters:
  • idx – Row to update

  • data – Cross-section data

update_file_list(query_path: str | None = None) None[source]

Update the list of data files.

Parameters:

query_path – Full path of a directory, a Nexus file, or a list of Nexus files. If a list of files, their paths are joined by the plus symbol ‘+’.

update_info()[source]

Update metadata shown in the overview tab.

update_reduction_table(table_widget: QTableWidget, idx: int, data: CrossSectionData)[source]

Update the reduction table.

Parameters:
  • table_widget – Table widget of the table to update

  • idx – Row to update

  • data – Cross-section data

update_reduction_table_from_direct_beam(direct_beam: NexusData)[source]

Update all reflectivity runs that use the given direct beam.

Parameters:

direct_beam – Direct beam data

update_tables()[source]

Update a data set that may be in the reduction table or the direct beam table.

quicknxs.interfaces.event_handlers.plot_handler module

Event handlers for the main application window.

Most of those come straight from QuickNXS.

class quicknxs.interfaces.event_handlers.plot_handler.PlotHandler(main_window)[source]

Bases: object

Class to handle plotting events.

change_color_scale(*args, **kws)[source]

Wrap a function to slow it down.

change_offspec_colorscale()[source]

Modify color scale.

change_region_values()[source]

Called when the reflectivity extraction region has been changed.

Sets up a trigger to replot the reflectivity with a delay so a subsequent change can occur without several replots.

clip_offspec_colorscale()[source]

Modify color scale.

connect_plot_events()[source]

Connect matplotlib mouse events.

control_down = False
last_event = None
plot_mouse_event(event: MouseEvent)[source]

Show the mouse position of any plot in the main window status bar.

The single plot status indicator is only visible for larger plot toolbars.

plot_pick_x(*args, **kws)[source]

Wrap a function to slow it down.

plot_pick_xtof(event: MouseEvent)[source]

Plot for xtof-map has been clicked.

plot_pick_xy(event)[source]

Plot for xy-map has been clicked.

plot_pick_y(event: MouseEvent)[source]

Plot for y-projection has been clicked.

plot_release(event)[source]

Release the mouse button on a plot.

refl = None
quicknxs.interfaces.event_handlers.plot_handler.slow_down_events(fn)[source]

Decorator to slow down UI events.

Seems to be necessary since PyQt5 seems to be overactive with the UI events.

quicknxs.interfaces.event_handlers.progress_reporter module

Class used to report on progress.

It allows for sub-tasks and computes a meaningful progress status accordingly.

class quicknxs.interfaces.event_handlers.progress_reporter.ProgressReporter(max_value: int = 100, call_back: Callable | None = None, status_bar: StatusBarHandler | None = None, progress_bar: QProgressBar | None = None)[source]

Bases: object

Progress reporter class that allows for sub-tasks.

Initialize the progress reporter.

create_sub_task(max_value: int) ProgressReporter[source]

Create a sub-task, with max_value being its portion of the complete task.

Parameters:

max_value – The maximum value for the sub-task, representing its portion of the total task.

Returns:

A new ProgressReporter instance representing the sub-task, to be called by the worker to update the progress.

Return type:

ProgressReporter

reset()[source]

Reset the progress bar to show no progress

set_value(value: int, message: str = '', out_of: int | None = None)[source]

Set the value of a progress indicator.

update(message: str = '')[source]

Updates the progress status according to sub-tasks.

quicknxs.interfaces.event_handlers.widgets module

Zoo for customized simple widgets.

class quicknxs.interfaces.event_handlers.widgets.AcceptRejectDialog(parent=None, title='', message='')[source]

Bases: QDialog

Customized widget for user to accept or reject a state.

Refer to: https://www.mfitzp.com/tutorials/pyqt-dialogs/

accept(self)[source]
is_accepted()[source]
reject(self)[source]