-
Notifications
You must be signed in to change notification settings - Fork 4
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 the bugs by using Dict for the selected_elements #14
Conversation
@giovannipizzi |
Sphinx.warn() was deprecated since 1.6 and removed at 2.0.
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.
Great with some updates on this widget! :)
Although I still have some issues using it to its fullest potential.
@@ -81,25 +81,24 @@ class MCPTableView extends DOMWidgetView { | |||
// http://codebeerstartups.com/2012/12/how-to-improve-templates-in-backbone-js-learning-backbone-js/ | |||
tableTemplate = _.template( '<% for (let elementRow of elementTable)'+ | |||
' { print("<div class=\'periodic-table-row\'>"); for (let elementName of elementRow)'+ | |||
' { if ( (elementName === "") || (elementName == "*" ) ) { %>' + | |||
' { if ( (elementName === "") || (elementName == "*" ) || (elementName == "#" ) ) { %>' + |
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 guess *
is not needed anymore due to the change above from *
-> #
?
' { if ( (elementName === "") || (elementName == "*" ) || (elementName == "#" ) ) { %>' + | |
' { if ( (elementName == "") || (elementName == "#" ) ) { %>' + |
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 both "#" and "*" to separate lanthanides and actinides group.
// 'title="state: <% if (selectedElements.includes(elementName)) { i = selectedElements.indexOf(elementName); print(selectedStates[i]);} '+ | ||
// 'else if (disabledElements.includes(elementName)){print("disabled");} else {print("unselected");} %>" ><% '+ |
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 the commenting out?
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.
Giovanni suggested to remove the tooltips from the periodic table.
src/widget.ts
Outdated
// I have to make some changes, since there is some issue | ||
// for Dict in Traitlets, which cannot triggle the update |
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 believe this is true. I think you just need to set a default value of {}
for the traitlet or something, right?
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 think the problem is that if it was already {}
, no message is sent back.
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.
No only for empty dict. For example newStateList was {"H":1, "O": 2} then
newSateList = {"H": 3, "O": 1}
will not trigger the update in the python end PTable.selected_elements will show {"H":1, "O": 2}
this.model.set('selected_states', newStatesList); | ||
// I have to make some changes, since there is some issue | ||
// for Dict in Traitlets, which cannot triggle the update | ||
this.model.set('selected_elements', {"Du": 0}); |
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? Shouldn't it be set to the actually selected elements?
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 a dirty trick to force the update for the PTable.selected_elements as mentioned above.
// while (newSelectedElements.length > newSelectedStates.length){ | ||
// newSelectedStates.push(0); | ||
// }; |
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 the commenting out?
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 for previous code, when using list for the selected_elements and selected_states. For the dictionary, it does not need anymore.
self.selected_colors = self.selected_colors[:states] | ||
|
||
|
||
def set_element_state(self, elementName, state): |
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 think this function is ever used. Hence the functionality of the widget is non-existing at the moment.
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 function is import to set the element states.
For example:
PTable.selected_elements["H"] = 2
will not work.
On can use this function to set individual element's state.
@dou-du you can assign people for review on the right hand side of this page (the "Reviewers" section). |
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.
Minor comments.
I couldn't check the code in detail, though. Can I check it on binder already, I guess?
examples/introduction.ipynb
Outdated
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"execution_count": 10, |
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.
Are you committing on purpose a run notebook?
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 just commit to save all change. This is not needed to be committed. I will change it back.
@@ -1,6 +1,6 @@ | |||
#!/bin/bash | |||
jupyter labextension install @jupyter-widgets/jupyterlab-manager | |||
pip install -i https://test.pypi.org/simple/ widget-periodictable |
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.
Do you want to suggest to install from test-pypi?
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 just use it to test the widget-periodictable package. I have released a new version at PyPi. I will change it to PyPi.
src/widget.ts
Outdated
// I have to make some changes, since there is some issue | ||
// for Dict in Traitlets, which cannot triggle the update |
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 think the problem is that if it was already {}
, no message is sent back.
I checked on Binder, seems to be working fine! I think it would be also useful to have a function tmp = widget.selected_elements.copy()
tmp.pop(elementName)
widget.selected_elements = tmp |
Co-authored-by: Casper Welzel Andersen <[email protected]>
Co-authored-by: Casper Welzel Andersen <[email protected]>
Thanks @CasperWA and @giovannipizzi I will have a final checking about the code and approve the pull request. |
In order to fix the bugs mentioned in issue #4 , I decide to use a Dict (traitlets) for the selected_elements.
However, there is a issue for the Dict.