-
Notifications
You must be signed in to change notification settings - Fork 55
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
[MRG] Update GUI to latest version of ipywidgets and voila #696
Changes from 29 commits
be01e85
266e789
bf70536
c10b708
d3ec97e
a7786ff
e81d247
94820fa
7ce1404
b7d45e9
bf3580c
0c0e877
a629787
4391b46
94576d9
a8e9ebb
c3a805b
261a025
ecd2e0e
c882122
1a9b287
01c758a
1dd4568
b54b656
e14da5f
2c38ba3
f91cbb2
96e4a6a
d49cad3
207de0c
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 |
---|---|---|
|
@@ -3,14 +3,18 @@ | |
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import pytest | ||
import traitlets | ||
|
||
from hnn_core import Dipole, Network, Params | ||
from hnn_core.gui import HNNGUI | ||
from hnn_core.gui._viz_manager import _idx2figname, _no_overlay_plot_types | ||
from hnn_core.gui._viz_manager import (_idx2figname, _no_overlay_plot_types, | ||
unlink_relink) | ||
from hnn_core.gui.gui import _init_network_from_widgets | ||
from hnn_core.network import pick_connection | ||
from hnn_core.network_models import jones_2009_model | ||
from hnn_core.parallel_backends import requires_mpi4py, requires_psutil | ||
from IPython.display import IFrame | ||
from ipywidgets import Tab, Text, link | ||
|
||
matplotlib.use('agg') | ||
|
||
|
@@ -413,3 +417,50 @@ def test_gui_adaptive_spectrogram(): | |
for attr in dir(gui.viz_manager.figs[figid])]) is False | ||
assert len(gui.viz_manager.figs[1].axes) == 2 | ||
plt.close('all') | ||
|
||
|
||
def test_unlink_relink_widget(): | ||
"""Tests the unlinking and relinking of widgets decorator.""" | ||
|
||
# Create a basic version of the VizManager class | ||
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 not use 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. It's mostly out of principle to make the test small and clear so that the scope of the test is just the functionality of the decorator, which makes it easier to detect if the a bug is coming from within the function vs externally. The full functionality tests of the VizManager like |
||
class MiniViz: | ||
def __init__(self): | ||
self.tab_group_1 = Tab() | ||
self.tab_group_2 = Tab() | ||
self.tab_link = link( | ||
(self.tab_group_1, 'selected_index'), | ||
(self.tab_group_2, 'selected_index'), | ||
) | ||
|
||
def add_child(self, to_add=1): | ||
n_tabs = len(self.tab_group_2.children) + to_add | ||
# Add tab and select latest tab | ||
self.tab_group_1.children = \ | ||
[Text(f'Test{s}') for s in np.arange(n_tabs)] | ||
self.tab_group_1.selected_index = n_tabs - 1 | ||
|
||
self.tab_group_2.children = \ | ||
[Text(f'Test{s}') for s in np.arange(n_tabs)] | ||
self.tab_group_2.selected_index = n_tabs - 1 | ||
|
||
@unlink_relink(attribute='tab_link') | ||
def add_child_decorated(self, to_add): | ||
self.add_child(to_add) | ||
|
||
# Check that widgets are linked. | ||
# Error from tab groups momentarily having a different number of children | ||
gui = MiniViz() | ||
with pytest.raises(traitlets.TraitError, match='.*index out of bounds.*'): | ||
gui.add_child(2) | ||
|
||
# Check decorator unlinks and is able to make a change | ||
gui = MiniViz() | ||
gui.add_child_decorated(2) | ||
assert len(gui.tab_group_1.children) == 2 | ||
assert gui.tab_group_1.selected_index == 1 | ||
assert len(gui.tab_group_2.children) == 2 | ||
assert gui.tab_group_2.selected_index == 1 | ||
|
||
# Check if the widgets are relinked, the selected index should be synced | ||
gui.tab_group_1.selected_index = 0 | ||
assert gui.tab_group_2.selected_index == 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ def run(self): | |
'h5io' | ||
], | ||
extras_require={ | ||
'gui': ['ipywidgets <=7.7.1', 'ipympl<0.9', 'voila<=0.3.6'], | ||
'gui': ['ipywidgets>=8.0.0', 'ipykernel', 'ipympl', 'voila'], | ||
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. I think you'll need to update README: https://jonescompneurolab.github.io/hnn-core/stable/index.html let me know once you fix it and I'll go ahead and merge @gtdang ! 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. Thanks! Updated! |
||
'opt': ['scikit-learn'] | ||
}, | ||
python_requires='>=3.8', | ||
|
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.
Need to think of one line comment on ipywidgets figure linking logic
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.
Perhaps: "Unlinks Tab objects to avoid index error from asynchronous addition of new tabs."
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.
sorry I missed the discussion on this, is it a bugfix or something related to the new version of ipywidgets?