-
Notifications
You must be signed in to change notification settings - Fork 3
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
slight tidy #129
slight tidy #129
Changes from 1 commit
92d1332
94f172e
d6d2cc6
73f419c
ccdf0fa
05ff037
53104e8
e6d7b1e
58b4fa3
de75f65
5786f3b
e18171d
4cf969b
6570d9a
bf59656
c90c4ec
340e956
535c4c3
cbe7b0b
836fe59
741399d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,6 @@ class UIFormWidget: | |
| | | ||
+----------------------------------------------------------+ | ||
''' | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
def createForm(self): | ||
# Add vertical layout to dock contents | ||
verticalLayout = QtWidgets.QVBoxLayout(self) | ||
|
@@ -71,7 +68,7 @@ def insertWidget(self, row, name, qwidget, qlabel=None): | |
The position in the form where the widget is added. | ||
name : str | ||
The string associated to the qwidget and qlabel. | ||
qwidget : widget | ||
qwidget : QWidget | ||
The widget to be added on the right hand side of the form or as a spanning widget. | ||
qlabel : qlabel widget or str | ||
The qlabel widget, or a str from which a qlabel widget is created, to be added | ||
|
@@ -91,7 +88,6 @@ def insertWidget(self, row, name, qwidget, qlabel=None): | |
formLayout.insertRow(row, qlabel, qwidget) | ||
self.widgets[f'{name}_label'] = qlabel | ||
self.default_widget_states[f'{name}_label'] = self.getWidgetState(name, 'label') | ||
|
||
else: | ||
formLayout.insertRow(row, qwidget) | ||
|
||
|
@@ -140,7 +136,7 @@ def addWidget(self, qwidget, qlabel, name): | |
|
||
Parameters | ||
---------- | ||
qwidget : widget | ||
qwidget : QWidget | ||
The widget to be added on the right hand side of the form. | ||
qlabel : qlabel widget or str | ||
The qlabel widget, or a str from which a qlabel widget is created, to be added | ||
|
@@ -272,10 +268,7 @@ def getAllWidgetStates(self): | |
e.g. {'widget1': {'value': 1, 'enabled': True, 'visible': True, 'widget_row': 0}, | ||
'widget2': {'value': 2, 'enabled': False, 'visible': False, 'widget_row': 1}}. | ||
''' | ||
all_widget_states = {} | ||
for key, widget in self.widgets.items(): | ||
all_widget_states[key] = self.getWidgetState(widget) | ||
return all_widget_states | ||
return {key: self.getWidgetState(widget) for key, widget in self.widgets.items()} | ||
|
||
def getWidgetState(self, widget, role=None): | ||
''' | ||
|
@@ -317,9 +310,9 @@ def getWidgetState(self, widget, role=None): | |
raise KeyError(f'No widget associated with the dictionary key `{name_role}`.') | ||
else: | ||
name, role = self._getNameAndRoleFromWidget(widget) | ||
widget_state = {} | ||
widget_state['enabled'] = widget.isEnabled() | ||
widget_state['visible'] = widget.isVisible() | ||
widget_state = { | ||
'enabled': widget.isEnabled(), 'visible': widget.isVisible(), | ||
'widget_row': self.getWidgetRow(name, role)} | ||
|
||
if isinstance(widget, QtWidgets.QLabel): | ||
widget_state['value'] = widget.text() | ||
|
@@ -337,8 +330,6 @@ def getWidgetState(self, widget, role=None): | |
widget_state['value'] = widget.isChecked() | ||
elif isinstance(widget, (QtWidgets.QTextEdit, QtWidgets.QPlainTextEdit)): | ||
widget_state['value'] = widget.toPlainText() | ||
|
||
widget_state['widget_row'] = self.getWidgetRow(name, role) | ||
return widget_state | ||
|
||
def _getNameAndRoleFromKey(self, key): | ||
|
@@ -352,15 +343,10 @@ def _getNameAndRoleFromKey(self, key): | |
Format: name or name_field or name_label | ||
''' | ||
if key.endswith('_field'): | ||
name = key.removesuffix('_field') | ||
role = 'field' | ||
return key.removesuffix('_field'), 'field' | ||
elif key.endswith('_label'): | ||
name = key.removesuffix('_label') | ||
role = 'label' | ||
else: | ||
name = key | ||
role = 'field' | ||
return name, role | ||
return key.removesuffix('_label'), 'label' | ||
return key, 'field' | ||
|
||
def _getNameAndRoleFromWidget(self, widget): | ||
''' | ||
|
@@ -392,18 +378,15 @@ def applyWidgetState(self, name, state, role=None): | |
e.g. {'value': 1, 'enabled': True, 'visible': True, 'widget_row' : 0}. | ||
''' | ||
if role is not None: | ||
if role in ['label', 'field']: | ||
if role in ('label', 'field'): | ||
name_role = name + '_' + role | ||
else: | ||
raise ValueError(f'Role must be either "label", "field" or None. Got {role}.') | ||
else: | ||
name_role = f'{name}_field' | ||
|
||
# retrieve widget | ||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we removing this KeyError? |
||
widget = self.widgets[name_role] | ||
except KeyError: | ||
raise KeyError(f'No widget associated with the dictionary key `{name_role}`.') | ||
widget = self.widgets[name_role] | ||
# apply state | ||
for key, value in state.items(): | ||
if key == 'enabled': | ||
|
@@ -446,7 +429,7 @@ def applyWidgetStates(self, states): | |
'widget2': {'value': 2, 'enabled': False, 'visible': False, 'widget_row': 1}}. | ||
''' | ||
if set(self.widgets) != set(states): | ||
raise KeyError("states={set(states)} do not match form widgets ({set(self.widgets)})") | ||
raise KeyError(f"states={set(states)} do not match form widgets ({set(self.widgets)})") | ||
for key, widget_state in states.items(): | ||
name, role = self._getNameAndRoleFromKey(key) | ||
self.applyWidgetState(name, widget_state, role) | ||
|
@@ -488,10 +471,10 @@ def __init__(self, parent=None): | |
|
||
|
||
class FormDockWidget(QtWidgets.QDockWidget): | ||
def __init__(self, parent=None, title=None): | ||
def __init__(self, parent=None, title=''): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this default and accept There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. honestly I'd prefer removing the lines below: if title is None:
title = '' but I left them in just for backwards compatibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
we added these lines in https://github.com/TomographicImaging/eqt/pull/102/files |
||
if title is None: | ||
title = '' | ||
QtWidgets.QDockWidget.__init__(self, title, parent) | ||
super().__init__(self, title, parent) | ||
widget = FormWidget(parent) | ||
self.setWidget(widget) | ||
if title is not None: | ||
|
@@ -542,7 +525,7 @@ def insertWidget(self, row, name, qwidget, qlabel=None): | |
The position in the form where the widget is added. | ||
name : str | ||
The string associated to the qwidget and qlabel. | ||
qwidget : widget | ||
qwidget : QWidget | ||
The widget to be added on the right hand side of the form or as a spanning widget. | ||
qlabel : qlabel widget or str | ||
The qlabel widget, or a str from which a qlabel widget is created, to be added | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new changes are not passing the tests, could you fix this before we look at it? (101 fail, 36 pass on my local machine)