quicknxs.interfaces.event_handlers package

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]

Generate 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_channel_changed()[source]

Update UI metadata and plots after the active channel is changed

active_data_changed()[source]

Actions to be taken once the active data set has changed

add_direct_beam(silent=False)[source]

Add / remove dataset to the available normalizations or clear the normalization list.

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.

ask_question(message)[source]

Display a popup dialog with a message and choices “Ok” and “Cancel” :param str message: question to ask :returns: bool

automated_file_selection()[source]

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

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.

Return values:
-1 = no valid change

0 = replot needed 1 = recalculation needed

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

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() Configuration[source]

@brief Gather the reduction options. @details Retrieve the reduction options either from the active channel or from the current settings in the graphical interface.

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 | None = False, silent: bool | None = False) None[source]

@brief Read one or more data files. If more than one, merge their data. @param file_path: absolute path to data files. If more than one file, paths are joined with the plus symbol ‘+’ @param force: if true, the file will be reloaded even if it was loaded previously @param 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=None)[source]

@brief Open a data file by typing a run number or a composite run number for merging data sets @details 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.

property reduction_table

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

Return type:

QTableWidget

reduction_table_changed(item)[source]

Perform action upon change in data reduction list.

reduction_table_right_click(pos, is_reduction_table=True)[source]

Handle right-click on the reduction table. :param QPoint pos: mouse position :param bool 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, informative_message=None, detailed_message=None, pop_up=False, is_error=False)[source]

Report a message or error to the status bar at the bottom of the window. :param str message: message string to be reported :param str informative_message: extra information :param str detailed_message: detailed message for the log :param bool pop_up: if True, a dialog will pop up :param bool is_error: if True, the message is logged on the error channel

save_run_data(nexus_data: NexusData)[source]

Save run data to file :param NexusData nexus_data: run data object

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.

toggle_final_rebin_global(state)[source]

When the global rebin checkbox is toggled, update the run rebin checkbox so that only one of them can be checked at a time.

toggle_final_rebin_run(state)[source]

When the run rebin checkbox is toggled, update the global rebin checkbox so that only one of them can be checked at a time.

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_channel_info()[source]

Update channel 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, d)[source]

Update a direct beam table entry :param int idx: row index :param CrossSectionData d: data object

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

@brief Update the list of data files @param 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, d: CrossSectionData)[source]

Update the reduction table

Parameters:
  • table_widget (QtWidgets.QTableWidget) – Table widget of the table to update

  • idx (int) – Row to update

  • d (CrossSectionData) – Cross-section 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)[source]

Show the mouse position of any plot in the main window status bar, as the single plot status indicator is only visible for larger plot toolbars. :param event: event object

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

Wrap a function to slow it down

plot_pick_xtof(event)[source]
Parameters:

event – event object

plot_pick_xy(event)[source]

Plot for xy-map has been clicked. :param self QMainWindow: main window object :param event: event object

plot_pick_y(event)[source]

Plot for y-projection has been clicked. :param self QMainWindow: main window object :param event: event object

plot_release(event)[source]
Parameters:

event – event object

refl = None
scale_on_plot(*args, **kws)[source]

Wrap a function to slow it down

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

Decorator to slow down UI events 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=100, call_back=None, status_bar=None, progress_bar=None)[source]

Bases: object

Progress reporter class that allows for sub-tasks.

create_sub_task(max_value)[source]

Create a sub-task, with max_value being its portion of the complete task. Returns a call-back function to be called by the worker to update the progress.

Parameters:

max_value (int) – portion of the task

set_value(value, message='', out_of=None)[source]

Set the value of a progress indicator :param int value: completion value, as a percentage

update(message='')[source]

Updates the progress status according to sub-tasks.

Parameters:

message (str) – message to be displayed

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]