diff --git a/notebooks/Connectivity.ipynb b/notebooks/Connectivity.ipynb index d543edd..e7b4a60 100644 --- a/notebooks/Connectivity.ipynb +++ b/notebooks/Connectivity.ipynb @@ -14,33 +14,17 @@ "tags": [] }, "outputs": [], - "source": [ - "from tvbwidgets.api import ConnectivityWidgetReact\n", - "from tvb.datatypes.connectivity import Connectivity\n", - "\n", - "connectivity = Connectivity.from_file() # defaults to connectivy_76.zip\n", - "\n", - "\n", - "wid = ConnectivityWidgetReact(connectivity=connectivity)\n", - "wid" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], "source": [ "from tvbwidgets.api import ConnectivityWidget\n", "from tvb.datatypes.connectivity import Connectivity\n", "import pyvista as pv\n", "import numpy as np\n", - "pv.set_jupyter_backend('pythreejs')\n", + "pv.set_jupyter_backend(\"pythreejs\")\n", "\n", "conn = Connectivity.from_file() # defaults to connectivy_76.zip\n", "conn.configure()\n", "\n", - "wid = ConnectivityWidget(conn, default_active_tab='viewers') # default_active_tab can be any value between 'viewers'|'operations'|'both'\n", + "wid = ConnectivityWidget(conn, default_active_tab='viewers', width=500, height=500) # default_active_tab can be any value between 'viewers'|'operations'|'both'\n", "\n", "display(wid)" ] @@ -63,7 +47,20 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# Using the React Connectivity widget may lead to Jupyter Lab freezing or crashing.\n", + "# If you choose to use it, we recommend to run it in Mozilla Firefox web browser.\n", + "\n", + "\n", + "# from tvbwidgets.api import ConnectivityWidgetReact\n", + "# from tvb.datatypes.connectivity import Connectivity\n", + "\n", + "# connectivity = Connectivity.from_file() # defaults to connectivy_76.zip\n", + "\n", + "\n", + "# wid = ConnectivityWidgetReact(connectivity=connectivity)\n", + "# wid" + ] } ], "metadata": { @@ -82,7 +79,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.9.18" } }, "nbformat": 4, diff --git a/tvbwidgets/ui/connectivity_ipy/connectivity_widget.py b/tvbwidgets/ui/connectivity_ipy/connectivity_widget.py index 55b836f..e171ad6 100644 --- a/tvbwidgets/ui/connectivity_ipy/connectivity_widget.py +++ b/tvbwidgets/ui/connectivity_ipy/connectivity_widget.py @@ -109,8 +109,10 @@ def on_ctx_change(value): class Connectivity3DViewer(ipywidgets.VBox): - def __init__(self, **kwargs): + def __init__(self, width, height, **kwargs): self.output = PyVistaOutput() + self.output.plotter.window_size = [width, height] + self.output.plotter.set_background("darkgrey") super(Connectivity3DViewer, self).__init__([self.output], *kwargs) @@ -120,7 +122,7 @@ def __init__(self, **kwargs): def __init_view_connectivity(self): self.output.plotter.clear() points, edges = self.__add_actors() - points_toggle, edges_toggle, labels_toggle = self.__init_controls() + points_toggle, edges_toggle = self.__init_controls() def on_change_points(change): if change['new']: @@ -140,12 +142,10 @@ def on_change_edges(change): edges_toggle.observe(on_change_edges, 'value') - window_controls = self.output.get_window_controls() self.children = [ ipywidgets.HBox(children=( - points_toggle, edges_toggle, labels_toggle)), - window_controls, + points_toggle, edges_toggle)), self.output] self.output.display_actor(points) self.output.display_actor(edges) @@ -159,9 +159,7 @@ def __init_controls(self): description='Edges', ) - labels_toggle = ipywidgets.ToggleButton(value=False, - description='Labels') - return points_toggle, edges_toggle, labels_toggle + return points_toggle, edges_toggle def __add_actors(self): plotter = self.output.plotter @@ -197,11 +195,11 @@ def __extract_edges(self): class ConnectivityViewers(ipywidgets.Accordion): - def __init__(self, **kwargs): + def __init__(self, width, height, **kwargs): super().__init__(**kwargs) self.children = [ Connectivity2DViewer(), - Connectivity3DViewer() + Connectivity3DViewer(width, height) ] self.set_title(0, '2D Connectivity Matrix viewer') self.set_title(1, '3D Connectivity viewer') @@ -235,7 +233,7 @@ def get_connectivity(self, gid=None): return None return conn[0] - def __init__(self, connectivity, default_active_tab='both', **kwargs): + def __init__(self, connectivity, default_active_tab='both', width=500, height=500, **kwargs): style = self.DEFAULT_BORDER super().__init__(**kwargs, layout=style) @@ -246,7 +244,7 @@ def __init__(self, connectivity, default_active_tab='both', **kwargs): viewers_visible = default_active_tab in ['both', 'viewers'] operations_visible = default_active_tab in ['both', 'operations'] - self.viewers_tab = ConnectivityViewers() + self.viewers_tab = ConnectivityViewers(width, height) self.viewers_tab.layout.display = viewers_visible and 'inline-block' or 'none' self.operations_tab = ConnectivityOperations() self.operations_tab.layout.display = operations_visible and 'inline-block' or 'none' diff --git a/tvbwidgets/ui/connectivity_ipy/outputs_3d.py b/tvbwidgets/ui/connectivity_ipy/outputs_3d.py index 68e330d..7babe95 100644 --- a/tvbwidgets/ui/connectivity_ipy/outputs_3d.py +++ b/tvbwidgets/ui/connectivity_ipy/outputs_3d.py @@ -4,7 +4,6 @@ # # (c) 2022-2023, TVB Widgets Team # -import ipywidgets from tvbwidgets.ui.connectivity_ipy.config import ConnectivityConfig from tvbwidgets.ui.connectivity_ipy.exceptions import UnknownOutputException @@ -42,40 +41,6 @@ def update_plot(self): self.clear_output(wait=True) self.plotter.show() - def get_window_controls(self): - height = ipywidgets.IntSlider( - value=self.CONFIG.size[1], - min=50, - max=1500, - step=1, - orientation='horizontal', - description='Plot height', - continuous_update=False, - ) - width = ipywidgets.IntSlider( - value=self.CONFIG.size[0], - min=50, - max=1500, - step=1, - orientation='horizontal', - description='Plot width', - continuous_update=False, - ) - - self.plotter.window_size = [width.value, height.value] - - def on_change_height(value): - self.plotter.window_size = [width.value, value['new']] - self.update_plot() - - def on_change_width(value): - self.plotter.window_size = [value['new'], height.value] - self.update_plot() - - height.observe(on_change_height, 'value') - width.observe(on_change_width, 'value') - return ipywidgets.HBox(children=(width, height)) - def output_3d_factory(output_type): """Factory function for a custom 3d output"""