Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighting master table columns #231

Merged
merged 32 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c021465
Fixed bug by increasing the number of digits of the random number whe…
JeanBilheux Apr 15, 2019
9144288
Fixed import (missing and non used ones). This refs #226
JeanBilheux Apr 15, 2019
909471c
Added list of columns to check for matching infos to highlight entire…
JeanBilheux Apr 15, 2019
b96bf32
Renamed last column, Align and Focus Args.
JeanBilheux Apr 15, 2019
83361be
Brought back import to make icons visible
JeanBilheux Apr 15, 2019
6039062
Created class that will take care of checking the columns hightlights
JeanBilheux Apr 15, 2019
ccc96f7
Simplify ui by removing useless column initialization of tables. this…
JeanBilheux Apr 15, 2019
c43b771
Started to connect item event with code that will check if all the va…
JeanBilheux Apr 15, 2019
bbbfe2f
Chemical formula change will triger the column highlight check
JeanBilheux Apr 15, 2019
fb8d76d
Mass density changes trigers the column highlights code
JeanBilheux Apr 15, 2019
8d5336c
shape change triggers the column highlight script
JeanBilheux Apr 15, 2019
f54f804
changing geometry triggers column hightlights
JeanBilheux Apr 15, 2019
cc45170
All correction now trigger the column highlight code
JeanBilheux Apr 15, 2019
ae804e5
Align and focus args now check the columns highlights
JeanBilheux Apr 15, 2019
845c10c
Prototypes background cells color for items and widgets (just one of …
JeanBilheux Apr 15, 2019
f1b1faf
Framework of checking for column identical values is in place
JeanBilheux Apr 15, 2019
62b1bc4
Centralized where the color of the columns is defined
JeanBilheux Apr 15, 2019
6e811f6
Checking the item columns works
JeanBilheux Apr 15, 2019
5411876
Checking chemical formula. this refs #134
JeanBilheux Apr 16, 2019
fceb529
mass density column checked. This refs #134
JeanBilheux Apr 16, 2019
1182c08
Implemented shape column. This refs #134
JeanBilheux Apr 16, 2019
e47494b
Geometry dimensions are now checked as well. This refs #134
JeanBilheux Apr 16, 2019
cb06295
inelastic correction column is now checked. This refs #134
JeanBilheux Apr 16, 2019
bf96425
checking keys and value args column. This refs #134
JeanBilheux Apr 16, 2019
14d48e4
Added code that will check the entire table for same column data or n…
JeanBilheux Apr 16, 2019
c56d64a
Insert row, remove row, duplicate row... check all the columns for hi…
JeanBilheux Apr 16, 2019
4daf64c
checking highlights for any combinaison. This refs #134
JeanBilheux Apr 16, 2019
1163b46
Fixed flake8 issues
JeanBilheux Apr 16, 2019
f910136
Revert "Fixed flake8 issues"
JeanBilheux Apr 16, 2019
3390d38
Blocking item events signals when checking cells. this refs #231
JeanBilheux Apr 17, 2019
608b6d2
Found and fixed bug that did not change the color of the current cell…
JeanBilheux Apr 17, 2019
3a11650
Fixed flake8. this refs #231
JeanBilheux Apr 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30,086 changes: 15,043 additions & 15,043 deletions addie/icons/icons_rc.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions addie/initialization/events/processing_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ def run(main_window=None):
main_window.processing_ui.browse_calibration_button.clicked.connect(main_window.browse_calibration_clicked)
main_window.processing_ui.make_calibration_button.clicked.connect(main_window.make_calibration_clicked)
main_window.processing_ui.h3_table.customContextMenuRequested.connect(main_window.h3_table_right_click)
main_window.processing_ui.h3_table.cellChanged.connect(main_window.check_master_table_column_highlighting)
main_window.processing_ui.pushButton_launchReduction.clicked.connect(main_window.run_mantid)
10 changes: 10 additions & 0 deletions addie/processing/mantid/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from addie.processing.mantid.master_table.import_from_database.load_into_master_table import LoadIntoMasterTable
from addie.processing.mantid.make_calibration_handler.make_calibration import MakeCalibrationLauncher
from addie.processing.mantid.master_table.reduction_configuration_handler import ReductionConfigurationHandler
from addie.processing.mantid.master_table.master_table_loader import AsciiLoader

try:
from addie.processing.mantid.master_table.import_from_database.import_from_database_handler import ImportFromDatabaseHandler
Expand All @@ -18,6 +19,8 @@
print('pyoncat module not found. Functionality disabled')
ONCAT_ENABLED = False

from addie.processing.mantid.master_table.tree_definition import INDEX_OF_COLUMNS_WITH_MASS_DENSITY


def personalization_table_clicked(main_window):
_ = TableTreeHandler(parent=main_window)
Expand Down Expand Up @@ -209,6 +212,7 @@ def sample_mass_density_button_pressed(main_window, key):
def sample_mass_density_line_edit_entered(main_window, key):
o_table = TableRowHandler(main_window=main_window)
o_table.transfer_widget_states(from_key=key, data_type='sample')
main_window.check_master_table_column_highlighting(column=INDEX_OF_COLUMNS_WITH_MASS_DENSITY[0])


def sample_shape_changed(main_window, index, key):
Expand Down Expand Up @@ -258,6 +262,7 @@ def normalization_mass_density_button_pressed(main_window, key):
def normalization_mass_density_line_edit_entered(main_window, key):
o_table = TableRowHandler(main_window=main_window)
o_table.transfer_widget_states(from_key=key, data_type='normalization')
main_window.check_master_table_column_highlighting(column=INDEX_OF_COLUMNS_WITH_MASS_DENSITY[1])


def normalization_shape_changed(main_window, text, key):
Expand Down Expand Up @@ -326,3 +331,8 @@ def from_oncat_to_master_table(main_window, json=None, with_conflict=False, igno

def reduction_configuration_button_clicked(main_window):
ReductionConfigurationHandler(parent=main_window)


def load_ascii(main_window, filename=""):
o_ascii_loader = AsciiLoader(parent=main_window, filename=filename)
o_ascii_loader.load()
2 changes: 2 additions & 0 deletions addie/processing/mantid/master_table/align_and_focus_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from qtpy.QtWidgets import QMainWindow, QTableWidgetItem

from addie.utilities import load_ui
from addie.processing.mantid.master_table.tree_definition import LIST_COLUMNS_TO_SEARCH_FOR_FULL_HIGHLIGTHING

COLUMNS_WIDTH = [150, 150]

Expand Down Expand Up @@ -47,6 +48,7 @@ def _get_previous_key_value_dict(self):

def ok_clicked(self):
self._save_key_value_infos()
self.main_window.check_master_table_column_highlighting(column=LIST_COLUMNS_TO_SEARCH_FOR_FULL_HIGHLIGTHING[-1])
self.close()

def _save_key_value_infos(self):
Expand Down
303 changes: 303 additions & 0 deletions addie/processing/mantid/master_table/column_highlighting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
import numpy as np
from qtpy import QtGui

from addie.processing.mantid.master_table.utilities import Utilities

from addie.processing.mantid.master_table.tree_definition import (INDEX_OF_COLUMNS_SEARCHABLE,
INDEX_OF_COLUMNS_WITH_CHEMICAL_FORMULA,
INDEX_OF_COLUMNS_WITH_MASS_DENSITY,
INDEX_OF_COLUMNS_SHAPE,
INDEX_OF_COLUMNS_WITH_GEOMETRY_INFOS,
INDEX_OF_ABS_CORRECTION,
INDEX_OF_MULTI_SCATTERING_CORRECTION,
INDEX_OF_INELASTIC_CORRECTION,
LIST_COLUMNS_TO_SEARCH_FOR_FULL_HIGHLIGTHING)
from addie.processing.mantid.master_table.tree_definition import (COLUMNS_IDENTICAL_VALUES_COLOR,
COLUMNS_DIFFERENT_VALUES_COLOR)
from addie.processing.mantid.master_table.tree_definition import INDEX_NORMALIZATION_START


class ColumnHighlighting:

data_type = 'sample'
column = -1

def __init__(self, main_window=None):
self.main_window = main_window
self.nbr_row = self.get_nbr_row()

def set_data_type(self):
if self.column >= INDEX_NORMALIZATION_START:
self.data_type = 'normalization'

def get_nbr_row(self):
nbr_row = self.main_window.processing_ui.h3_table.rowCount()
return nbr_row

def get_nbr_column(self):
nbr_column = self.main_window.processing_ui.h3_table.columnCount()
return nbr_column

def check_all(self):
nbr_column = self.get_nbr_column()
for _col in np.arange(nbr_column):
self.check_column(column=_col)

def check_column(self, column=-1):
self.main_window.processing_ui.h3_table.blockSignals(True)

self.column = column
are_all_the_same = False

self.set_data_type()

if self.nbr_row > 1:

for _ in np.arange(self.nbr_row):

# item
if column in INDEX_OF_COLUMNS_SEARCHABLE:
are_all_the_same = self.are_cells_identical()

elif column in INDEX_OF_COLUMNS_WITH_CHEMICAL_FORMULA:
are_all_the_same = self.are_chemical_formula_identical()

elif column in INDEX_OF_COLUMNS_WITH_MASS_DENSITY:
are_all_the_same = self.are_mass_density_identical()

elif column in INDEX_OF_COLUMNS_SHAPE:
are_all_the_same = self.are_shape_identical()

elif column in INDEX_OF_COLUMNS_WITH_GEOMETRY_INFOS:
are_all_the_same = self.are_geometry_identical()

elif column in INDEX_OF_ABS_CORRECTION:
are_all_the_same = self.are_abs_correction_identical()

elif column in INDEX_OF_MULTI_SCATTERING_CORRECTION:
are_all_the_same = self.are_multi_correction_identical()

elif column in INDEX_OF_INELASTIC_CORRECTION:
are_all_the_same = self.are_inelastic_correction_identical()

elif column == LIST_COLUMNS_TO_SEARCH_FOR_FULL_HIGHLIGTHING[-1]:
are_all_the_same = self.are_align_and_focus_args_identical()

self.apply_cell_background(are_all_the_same=are_all_the_same)
self.main_window.processing_ui.h3_table.blockSignals(False)

def apply_cell_background(self, are_all_the_same=False):
if are_all_the_same:
background_color = QtGui.QColor(COLUMNS_IDENTICAL_VALUES_COLOR[0],
COLUMNS_IDENTICAL_VALUES_COLOR[1],
COLUMNS_IDENTICAL_VALUES_COLOR[2])
background_color_stylesheet = "rgb({}, {}, {})".format(COLUMNS_IDENTICAL_VALUES_COLOR[0],
COLUMNS_IDENTICAL_VALUES_COLOR[1],
COLUMNS_IDENTICAL_VALUES_COLOR[2])
else:
background_color = QtGui.QColor(COLUMNS_DIFFERENT_VALUES_COLOR[0],
COLUMNS_DIFFERENT_VALUES_COLOR[1],
COLUMNS_DIFFERENT_VALUES_COLOR[2])
background_color_stylesheet = "rgb({}, {}, {})".format(COLUMNS_DIFFERENT_VALUES_COLOR[0],
COLUMNS_DIFFERENT_VALUES_COLOR[1],
COLUMNS_DIFFERENT_VALUES_COLOR[2])

pen_color = "black"
selection_color = "white"
selection_background_color = "blue"

for _row in np.arange(self.nbr_row):

main_widget = self.main_window.processing_ui.h3_table.cellWidget(_row, self.column)

if main_widget:

if self.column in INDEX_OF_COLUMNS_SEARCHABLE:
self.main_window.processing_ui.h3_table.item(_row, self.column).setBackground(background_color)
else:
main_widget.setAutoFillBackground(True)
main_widget.setStyleSheet("color: {}; "
"background-color: {};"
"selection-color: {};"
"selection-background-color: {};".format(pen_color,
background_color_stylesheet,
selection_color,
selection_background_color))

else:
self.main_window.processing_ui.h3_table.item(_row, self.column).setBackground(background_color)

def are_cells_identical(self):
def _get_item_value(row=-1, column=-1):
return str(self.main_window.processing_ui.h3_table.item(row, column).text())

ref_value = _get_item_value(0, self.column)
for _row in np.arange(1, self.nbr_row):
_value = _get_item_value(row=_row, column=self.column)
if _value != ref_value:
return False
return True

def are_chemical_formula_identical(self):
ref_value = self._get_chemical_formula_widget_value(row=0)
for _row in np.arange(1, self.nbr_row):
_value = self._get_chemical_formula_widget_value(row=_row)
if _value != ref_value:
return False
return True

def are_mass_density_identical(self):
ref_value = self._get_mass_density_widget_value(row=0)
for _row in np.arange(1, self.nbr_row):
_value = self._get_mass_density_widget_value(row=_row)
if _value != ref_value:
return False
return True

def are_shape_identical(self):
ref_value = self._get_shape_value(row=0)
for _row in np.arange(1, self.nbr_row):
_value = self._get_shape_value(row=_row)
if _value != ref_value:
return False
return True

def are_geometry_identical(self):
if not self.are_shape_identical():
return False

shape_selected = self._get_shape_value(row=0)

# compare radius
if not self._are_radius_identical():
return False

# we are done for spherical geometry
if shape_selected.lower() == "spherical":
return True

if not self._are_height_identical():
return False

# we are done for cylindrical geometry
if shape_selected.lower() == "cylindrical":
return True

if not self._are_radius2_identical():
return False
return True

def are_abs_correction_identical(self):
ref_value = self._get_abs_correction_widget_value(row=0)
for _row in np.arange(1, self.nbr_row):
_value = self._get_abs_correction_widget_value(row=_row)
if _value != ref_value:
return False
return True

def are_multi_correction_identical(self):
ref_value = self._get_multi_correction_widget_value(row=0)
for _row in np.arange(1, self.nbr_row):
_value = self._get_multi_correction_widget_value(row=_row)
if _value != ref_value:
return False
return True

def are_inelastic_correction_identical(self):
ref_value = self._get_inelastic_correction_widget_value(row=0)
for _row in np.arange(1, self.nbr_row):
_value = self._get_inelastic_correction_widget_value(row=_row)
if _value != ref_value:
return False

# if placzek selected,
if ref_value.lower() == 'placzek':
ref_dict = self._get_placzek_infos(row=0)
for _row in np.arange(1, self.nbr_row):
_dict = self._get_placzek_infos(row=_row)
if _dict != ref_dict:
return False
return True

def are_align_and_focus_args_identical(self):
ref_value = self._get_align_and_focus_args_value(row=0)
for _row in np.arange(1, self.nbr_row):
_value = self._get_align_and_focus_args_value(row=_row)
if _value != ref_value:
return False
return True

def _get_master_table_list_ui_for_row(self, row=-1):
o_utilities = Utilities(parent=self.main_window)
key_from_row = o_utilities.get_row_key_from_row_index(row=row)
master_table_list_ui = self.main_window.master_table_list_ui[key_from_row]
return master_table_list_ui

def _get_chemical_formula_widget_value(self, row=-1):
master_table_list_ui_for_row = self._get_master_table_list_ui_for_row(row=row)
widget_ui = master_table_list_ui_for_row[self.data_type]['material']['text']
return str(widget_ui.text())

def _get_mass_density_widget_value(self, row=-1):
master_table_list_ui_for_row = self._get_master_table_list_ui_for_row(row=row)
widget_ui = master_table_list_ui_for_row[self.data_type]['mass_density']['text']
return str(widget_ui.text())

def _get_shape_value(self, row=-1):
master_table_list_ui_for_row = self._get_master_table_list_ui_for_row(row=row)
widget_ui = master_table_list_ui_for_row[self.data_type]['shape']
return str(widget_ui.currentText())

# geometry Dimensions column
def get_geometry_dimensions_widgets(self, row=-1):
master_table_list_ui_for_row = self._get_master_table_list_ui_for_row(row=row)
radius_ui = master_table_list_ui_for_row[self.data_type]['geometry']['radius']['value']
radius2_ui = master_table_list_ui_for_row[self.data_type]['geometry']['radius2']['value']
height_ui = master_table_list_ui_for_row[self.data_type]['geometry']['height']['value']
return {'radius': radius_ui,
'radius2': radius2_ui,
'height': height_ui}

def _are_radius_identical(self):
return self._are_geometry_value_identical(variable_name='radius')

def _are_height_identical(self):
return self._are_geometry_value_identical(variable_name='height')

def _are_radius2_identical(self):
return self._are_geometry_value_identical(variable_name='radius2')

def _are_geometry_value_identical(self, variable_name='radius'):
ref_widgets = self.get_geometry_dimensions_widgets(row=0)
ref_radius = str(ref_widgets[variable_name].text())
for _row in np.arange(1, self.nbr_row):
val_widgets = self.get_geometry_dimensions_widgets(row=_row)
_value = str(val_widgets[variable_name].text())
if _value != ref_radius:
return False
return True

def _get_abs_correction_widget_value(self, row=-1):
master_table_list_ui_for_row = self._get_master_table_list_ui_for_row(row=row)
widget_ui = master_table_list_ui_for_row[self.data_type]['abs_correction']
return str(widget_ui.currentText())

def _get_multi_correction_widget_value(self, row=-1):
master_table_list_ui_for_row = self._get_master_table_list_ui_for_row(row=row)
widget_ui = master_table_list_ui_for_row[self.data_type]['mult_scat_correction']
return str(widget_ui.currentText())

def _get_inelastic_correction_widget_value(self, row=-1):
master_table_list_ui_for_row = self._get_master_table_list_ui_for_row(row=row)
widget_ui = master_table_list_ui_for_row[self.data_type]['inelastic_correction']
return str(widget_ui.currentText())

def _get_placzek_infos(self, row=-1):
master_table_list_ui_for_row = self._get_master_table_list_ui_for_row(row=row)
dict = master_table_list_ui_for_row[self.data_type]['placzek_infos']
return dict

def _get_align_and_focus_args_value(self, row=-1):
master_table_list_ui_for_row = self._get_master_table_list_ui_for_row(row=row)
dict = master_table_list_ui_for_row['align_and_focus_args_infos']
return dict
Loading