-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Fix #14 #142
Fix #14 #142
Conversation
exopy/utils/widgets/tree_nodes.py
Outdated
@@ -177,7 +177,10 @@ def exit_rename(self, obj, label): | |||
|
|||
""" | |||
label_name = self.label | |||
if label_name[:1] != '=': |
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.
This is not from my point of view the way to do it. It is better to override exit_rename in the task tree nodes (declared in the measure_editor). Those function exist to allow such customizations.
exit_rename => (obj, label): | ||
forbidden_names = obj.root.get_used_names() | ||
if label not in forbidden_names: | ||
obj.name = label |
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.
We could consider showing a popup explaining why renaming failed... But do not bother with this, opening an issue will be enough.
Codecov Report
@@ Coverage Diff @@
## master #142 +/- ##
==========================================
- Coverage 98.38% 98.37% -0.02%
==========================================
Files 157 157
Lines 12292 12335 +43
==========================================
+ Hits 12093 12134 +41
- Misses 199 201 +2 |
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.
I realized (a bit late) that this deviates a bit from my initial design. I would prefer to work with the direct parent rather than the root and to be future-proof it would be interesting to also pass the future index of the task in its parent. Sorry for the noticing so late.
@@ -783,8 +783,7 @@ def _on_nid_changed(self, nid, col): | |||
if new_label != old_label: | |||
if new_label != '': | |||
node.exit_rename(obj, new_label) | |||
else: | |||
self._set_label(nid, old_label) | |||
self._set_label(nid, node.get_label(obj)) |
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.
Why this change ?
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.
When the new name is invalid (because it's not unique), exit_rename doesn't set obj.name to new_label. The issue is, without this patch, the name displayed in the tree would be stuck on the new_label, even though it's invalid and doesn't reflect the actual name.
The systematic call to _set_label syncs up the two.
exopy/tasks/tasks/base_views.enaml
Outdated
@@ -88,13 +88,11 @@ enamldef RootTaskView(BaseTaskView): main: | |||
BaseTaskView.refresh(self) | |||
editor.refresh() | |||
|
|||
# TODO pass the future parent task so that config can do name inspections | |||
# and avoid duplicate names. | |||
func create_new_task(): |
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.
Looking at the full diff, I realized I would prefer to follow more closely what I was suggesting in this TODO and pass the future parent rather than the node in case we decide to ever use a different validation or need it for specific config.
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.
I don't want to pass the future parent because I want the names to be unique in the entire tree. This makes moving nodes in the tree easier.
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.
You can easily get the root from the parent and having the parent offer more possibilities.
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.
Ok, makes sense, I am reworking the PR.
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.
Ok let me know if you need help with anything.
exopy/tasks/configs/base_configs.py
Outdated
@@ -47,15 +50,15 @@ class BaseTaskConfig(Atom): | |||
|
|||
def __init__(self, **kwargs): | |||
super(BaseTaskConfig, self).__init__(**kwargs) | |||
# Force check to ensure that the possible default value of task_name | |||
# is tested. | |||
self.check_parameters() |
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.
From my point of view this could be problematic in subclasses if we need to validate something else than the name. It is not the job of the default value builder to validate the name.
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.
I needed to remove the check_parameters to prevent an infinite loop. I can't exactly remember why it happened but moving the check from __init__
to _default_task_name
solved the issue.
I can look at this more closely if you want.
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.
It seems that reworking the PR fixed the issue so I am putting the check_parameters
back.
@@ -78,7 +81,10 @@ def _post_setattr_task_name(self, old, new): | |||
def _default_task_name(self): | |||
names = self.manager.auto_task_names | |||
if names: | |||
return random.choice(names) | |||
name = random.choice(names) |
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.
See my above comment.
exopy/tasks/configs/base_configs.py
Outdated
names = [] | ||
if self.root: | ||
names = self.root.get_used_names() | ||
self.ready = self.task_name != "" and self.task_name not in names |
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.
To help the user, it would be nice if the UI could provide some feedback (such as a red background for the name). This would require to be able to only validate the name (not hard since you can store the name on the config to make the check cheap).
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.
Alternatively you can add a valid_name Bool member.
exopy/tasks/widgets/building.enaml
Outdated
@@ -38,6 +38,8 @@ enamldef BuilderView(Dialog): dial: | |||
#: Reference to the task manager. | |||
alias manager : selector.manager | |||
|
|||
attr root |
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.
This would be nicer with a comment.
- Replace the root attribute in the task configuration window by a future_parent attribute which contains the future parent of the task being created. - Add visual feedback when the name is not valid (this information is also stored in the config object) - Readd the check_parameters call in the BaseConfig constructor.
The tests fail on Python 3.5. It seems that |
No you can't since keywords arguments are not ordered. I will look at this either tomorrow or Monday. |
Please note that this issue doesn't apply to the actual code of exopy but only to the tests. Indeed, in the code, the |
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.
I made a small that should allow tests to always pass. I left two minor comments but otherwise this is good to go I believe.
@@ -34,6 +35,7 @@ enamldef BaseConfigView(Container): | |||
Field: t_f: | |||
text := config.task_name | |||
submit_triggers = ['lost_focus', 'return_pressed', 'auto_sync'] | |||
background << parse_color("#FFFFFF") if config.name_valid else parse_color("#FF000030") |
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.
I believe that 'white'
and 'red'
would have been fine too (and easier to read).
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.
I used some transparency to make the red softer and I used the HTML notation for the white for constency.
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.
Ok
exopy/tasks/configs/base_configs.py
Outdated
def __init__(self, **kwargs): | ||
super(BaseTaskConfig, self).__init__(**kwargs) | ||
# Force check to ensure that the possible default value of task_name | ||
# is tested. |
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.
Could you put those two lines back ?
I added two blank space by editing on Github (loop_cofig) Can you remove them along the other minor edits ? |
Thanks @rassouly I will try to review one last time before merging but I believe that this is good to go if Travis comes back green. |
I read through again and it looks good, but I will try to test directly before merging. |
Thanks @rassouly |
Known issues:
PasteAction
(inqt_tree_menu.enaml
) is not overridable. EDIT: Found a hacky solution. EDIT2: Found a nicer solution.Comment are welcome.