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

MNT/BUG: Misc fixes #213

Merged
merged 7 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions atef/ui/config_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<property name="title">
<string>File</string>
</property>
<addaction name="action_welcome_tab"/>
<addaction name="separator"/>
<addaction name="action_new_file"/>
<addaction name="separator"/>
<addaction name="action_open_file"/>
Expand Down Expand Up @@ -120,6 +122,11 @@
<string>Find / Replace</string>
</property>
</action>
<action name="action_welcome_tab">
<property name="text">
<string>Welcome Tab</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down
26 changes: 24 additions & 2 deletions atef/widgets/config/data_passive.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,17 @@ def new_if_disc_combo(self, value: str) -> None:
self.bridge.if_disconnected.put(Severity[value])


def float_or_none(value):
"""
Returns a float, or if value is None, return None.
a "from_str" function for optional values
"""
if value in ('', None):
return None

return float(value)


class EqualsMixin:
"""
Utilities for atol/rtol style data widgets
Expand Down Expand Up @@ -679,13 +690,13 @@ def setup_equals_widget(self) -> None:
setup_line_edit_data(
line_edit=self.atol_edit,
value_obj=self.bridge.atol,
from_str=float,
from_str=float_or_none,
to_str=str,
)
setup_line_edit_data(
line_edit=self.rtol_edit,
value_obj=self.bridge.rtol,
from_str=float,
from_str=float_or_none,
to_str=str,
)
starting_value = self.bridge.value.get()
Expand Down Expand Up @@ -865,6 +876,12 @@ def setup_range_widget(self) -> None:
self.update_symbols(self.bridge.inclusive.get())
# One additional visual update on inversion
self.bridge.invert.changed_value.connect(self.update_visualization)

# update on value changes
self.bridge.low.changed_value.connect(self.update_visualization)
self.bridge.high.changed_value.connect(self.update_visualization)
self.bridge.warn_low.changed_value.connect(self.update_visualization)
self.bridge.warn_high.changed_value.connect(self.update_visualization)
# Make sure this was called at least once
self.update_visualization()

Expand Down Expand Up @@ -969,11 +986,16 @@ def update_visualization(self, *args, **kwargs) -> None:
self.vertical_line_3.show()
self.warn_low_label.show()
self.warn_high_label.show()
# update labels
self.warn_high_label.setText(str(warn_high_mark))
self.warn_low_label.setText(str(warn_low_mark))
# The yellow and green lines should be sized relative to each other
total_range = high_mark - low_mark
left_range = warn_low_mark - low_mark
mid_range = warn_high_mark - warn_low_mark
right_range = high_mark - warn_high_mark
self.low_label.setText(str(low_mark))
self.high_label.setText(str(high_mark))
self.left_yellow_line.setFixedWidth(int(
real_space * left_range/total_range
))
Expand Down
6 changes: 5 additions & 1 deletion atef/widgets/config/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ def replace_step(
if found_row is None:
return

step_row = ComparisonRowWidget(data=new_step)
step_row = ConfigurationGroupRowWidget(data=new_step)
self.setup_row_buttons(
row_widget=step_row,
item=comp_item,
Expand Down Expand Up @@ -1791,12 +1791,16 @@ def select_step_type(self, new_type_index: int) -> None:
return

step = cast_dataclass(data=self.data, new_type=new_type)
# Assumes self.parent_tree_item.widget: ProcedureGroupPage
# put another way, this assumes steps cannot be parent of other steps
self.parent_tree_item.widget.replace_step(
old_step=self.data,
new_step=step,
comp_item=self.tree_item,
)
self.tree_item.setText(1, new_type.__name__)
# remove old children, no longer needed.
self.tree_item.takeChildren()
self.new_step(step=step)
self.update_context()

Expand Down
9 changes: 9 additions & 0 deletions atef/widgets/config/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Window(DesignerDisplay, QMainWindow):
user_filename_ext = 'json'

tab_widget: QTabWidget
action_welcome_tab: QAction
action_new_file: QAction
action_open_file: QAction
action_save: QAction
Expand All @@ -72,6 +73,7 @@ class Window(DesignerDisplay, QMainWindow):
def __init__(self, *args, show_welcome: bool = True, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowTitle('atef config')
self.action_welcome_tab.triggered.connect(self.welcome_user)
self.action_new_file.triggered.connect(self.new_file)
self.action_open_file.triggered.connect(self.open_file)
self.action_save.triggered.connect(self.save)
Expand Down Expand Up @@ -234,6 +236,13 @@ def open_file(self, *args, filename: Optional[str] = None, **kwargs):
except ValidationError:
logger.error('failed to open file as either active '
'or passive checkout')
msg = QtWidgets.QMessageBox(parent=self)
msg.setIcon(QtWidgets.QMessageBox.Critical)
msg.setText('Failed to open file as either an active or passive '
'checkout. The file may be corrupted or malformed.')
msg.setWindowTitle('Could not open file')
msg.exec_()
return
self._new_tab(data=data, filename=filename)

def _new_tab(
Expand Down
27 changes: 27 additions & 0 deletions docs/source/upcoming_release_notes/213-mnt_bug_misc_fixes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
213 mnt_bug_misc_fixes
######################

API Breaks
----------
- N/A

Features
--------
- N/A

Bugfixes
--------
- `RangeWidget`'s visualizations update a bit more frequently, and also the label text actually updates. Closes #212
- Adds a menu option to open the welcome tab, since people like it. Closes #201
- Properly shows an error message box when a file can't be opened. Closes #202
- Removes child `AtefItem` from a ProcedureStep when it's changed from the specific-step-combobox. Closes #195
- Allow tolerances to be `None` in `Equals` comparison. Modifies the line-edit setup to allow null values (`''`, `None`) when casting the line edit value. Closes #128


Maintenance
-----------
- N/A

Contributors
------------
- tangkong