Skip to content

Commit

Permalink
feat(ui): Add virtual node ui manager with server
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Jun 4, 2022
1 parent 9d73f24 commit 6956009
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/api/source/core.server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ server

core.state
core.controller
core.vn_manager
5 changes: 5 additions & 0 deletions docs/api/source/core.vn_manager.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ui
=====

.. autoclass:: trame_server.ui.VirtualNodeManager
:members:
4 changes: 2 additions & 2 deletions examples/05_charts/Plotly/01_plotly-charts-resizable.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def create_streamline_fig(width=100, height=100, **kwargs):
x = np.linspace(-3, 3, 100)
y = np.linspace(-3, 3, 100)
Y, X = np.meshgrid(x, y)
u = -1 - X**2 + Y
v = 1 + X - Y**2
u = -1 - X ** 2 + Y
v = 1 + X - Y ** 2

# Create streamline figure
fig = ff.create_streamline(
Expand Down
84 changes: 84 additions & 0 deletions examples/validation/core/19_virtual_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from trame.app import get_server
from trame.widgets import vtk, vuetify
from trame.ui.vuetify import SinglePageLayout

# -----------------------------------------------------------------------------
# trame
# -----------------------------------------------------------------------------

server = get_server(
# log_network="/Users/sebastien.jourdain/Documents/code/open-source/Web/trame-next/test-examples/logs",
)
state, ui = server.state, server.ui

state.toolbar_version = 0

# -----------------------------------------------------------------------------
# Methods
# -----------------------------------------------------------------------------


@state.change("toolbar_version")
def udpate_toolbar(toolbar_version=0, **kwargs):
if toolbar_version == 1:
toolbar_2()
elif toolbar_version == 2:
toolbar_3()
else:
toolbar_1()


# -----------------------------------------------------------------------------
# GUI (VirtualNodes)
# -----------------------------------------------------------------------------


def toolbar_1():
with ui.toolbar as tb:
tb.clear()
tb.add_child("Toolbar 1")
vuetify.VSpacer()
ui.toolbar_selector()


def toolbar_2():
with ui.toolbar as tb:
tb.clear()
tb.add_child("Toolbar 2")
vuetify.VSpacer()
ui.toolbar_selector()


def toolbar_3():
with ui.toolbar as tb:
tb.clear()
tb.add_child("Toolbar 3")
vuetify.VSpacer()
ui.toolbar_selector()


with ui.toolbar_selector:
with vuetify.VBtnToggle(v_model="toolbar_version"):
with vuetify.VBtn():
vuetify.VIcon("mdi-numeric-1-circle")
with vuetify.VBtn():
vuetify.VIcon("mdi-numeric-2-circle")
with vuetify.VBtn():
vuetify.VIcon("mdi-numeric-3-circle")


# -----------------------------------------------------------------------------
# GUI (Layout)
# -----------------------------------------------------------------------------

with SinglePageLayout(server) as layout:
with layout.toolbar as tb:
tb.clear()
ui.toolbar(layout)

# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------

if __name__ == "__main__":
server.start()
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ keywords =
packages = find:
include_package_data = True
install_requires =
trame-client
trame-client>=2.1.0
trame-components
trame-deckgl
trame-markdown
trame-matplotlib
trame-plotly
trame-router
trame-server
trame-server>=2.1.0
trame-vega
trame-vtk
trame-vuetify
Expand Down
3 changes: 2 additions & 1 deletion trame/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from trame_server import Server
from trame_client import module
from trame_client.widgets.core import VirtualNode

DEFAULT_NAME = "trame"
AVAILABLE_SERVERS = {}
Expand Down Expand Up @@ -33,7 +34,7 @@ def get_server(name=None, create_if_missing=True, **kwargs):
return AVAILABLE_SERVERS[name]

if create_if_missing:
server = Server(name, **kwargs)
server = Server(name, VirtualNode, **kwargs)
server.enable_module(module) # Always load html module first
AVAILABLE_SERVERS[name] = server
return server
Expand Down

0 comments on commit 6956009

Please sign in to comment.