Skip to content

Commit 66d7ea2

Browse files
committed
Merge branch '54-make-the-compact-theme-the-default-for-new-applications' into 'main'
Make the compact theme the default for new applications Closes #54 See merge request ndip/project-templates/nova-application-template!45
2 parents 4a48b49 + 5b53f71 commit 66d7ea2

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

template_sources/{% if application_type != 'Minimal' %}src{% endif %}/{% include 'package_folder_slug.j2' %}/{% if application_type in ['Nova Application', 'Tutorial'] %}app{% endif %}/view_models/main_view_model.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,31 @@
33
from typing import Any, Dict
44

55
from nova.mvvm.interface import BindingInterface
6+
from pydantic import BaseModel, Field
67

78
from ..models.main_model import MainModel
89

910

11+
class ViewState(BaseModel):
12+
"""View state for the application."""
13+
14+
active_tab: str = Field(default="0")
15+
16+
1017
class MainViewModel:
1118
"""Viewmodel class, used to create data<->view binding and react on changes from GUI."""
1219

1320
def __init__(self, model: MainModel, binding: BindingInterface):
1421
self.model = model
22+
self.view_state = ViewState()
1523

1624
# here we create a bind that connects ViewModel with View. It returns a communicator object,
1725
# that allows to update View from ViewModel (by calling update_view).
1826
# self.model will be updated automatically on changes of connected fields in View,
1927
# but one also can provide a callback function if they want to react to those events
2028
# and/or process errors.
2129
self.config_bind = binding.new_bind(self.model, callback_after_update=self.change_callback)
30+
self.view_state_bind = binding.new_bind(self.view_state)
2231

2332
def change_callback(self, results: Dict[str, Any]) -> None:
2433
if results["error"]:

template_sources/{% if application_type != 'Minimal' %}src{% endif %}/{% include 'package_folder_slug.j2' %}/{% if application_type in ['Nova Application', 'Tutorial'] %}app{% endif %}/views/{% if framework=="Trame" %}main_view.py{% endif %}.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MainApp(ThemedApp):
2525
{%- if multitabs %}
2626
"""Main application view class. Calls rendering of nested UI elements."""
2727
{%- else %}
28-
"""Main application view class. Renders all UI elements on the mainn page."""
28+
"""Main application view class. Renders all UI elements on the main page."""
2929
{%- endif %}
3030

3131
def __init__(self) -> None:
@@ -41,6 +41,7 @@ class MainApp(ThemedApp):
4141
self.create_ui()
4242

4343
def create_ui(self) -> None:
44+
self.set_theme("CompactTheme")
4445
self.state.trame__title = "{{ project_name }}"
4546

4647
with super().create_ui() as layout:

template_sources/{% if application_type != 'Minimal' %}src{% endif %}/{% include 'package_folder_slug.j2' %}/{% if application_type in ['Nova Application', 'Tutorial'] %}app{% endif %}/views/{% if multitabs %}sample_tab_1.py{% endif %}

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Module for the Sample Tab 1."""
22

33
from nova.trame.view.components import InputField
4+
from nova.trame.view.layouts import VBoxLayout
45

56

67
class SampleTab1:
@@ -10,4 +11,5 @@ class SampleTab1:
1011
self.create_ui()
1112

1213
def create_ui(self) -> None:
13-
InputField(v_model="config.username")
14+
with VBoxLayout():
15+
InputField(v_model="config.username")

template_sources/{% if application_type != 'Minimal' %}src{% endif %}/{% include 'package_folder_slug.j2' %}/{% if application_type in ['Nova Application', 'Tutorial'] %}app{% endif %}/views/{% if multitabs %}sample_tab_2.py{% endif %}

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Module for the Sample Tab 2."""
22

33
from nova.trame.view.components import InputField
4+
from nova.trame.view.layouts import VBoxLayout
45

56

67
class SampleTab2:
@@ -10,4 +11,5 @@ class SampleTab2:
1011
self.create_ui()
1112

1213
def create_ui(self) -> None:
13-
InputField(v_model="config.password")
14+
with VBoxLayout():
15+
InputField(v_model="config.password")

template_sources/{% if application_type != 'Minimal' %}src{% endif %}/{% include 'package_folder_slug.j2' %}/{% if application_type in ['Nova Application', 'Tutorial'] %}app{% endif %}/views/{% if multitabs %}tab_content_panel.py{% endif %}

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Module for the Tab Content panel."""
22

3-
from trame.widgets import vuetify3 as vuetify
3+
from nova.trame.view.layouts import VBoxLayout
44
from trame_server import Server
55

66
from ..view_models.main_view_model import MainViewModel
@@ -18,8 +18,7 @@ class TabContentPanel:
1818
self.create_ui()
1919

2020
def create_ui(self) -> None:
21-
with vuetify.VWindow(v_model="active_tab"):
22-
with vuetify.VWindowItem(value=1):
23-
SampleTab1()
24-
with vuetify.VWindowItem(value=2):
25-
SampleTab2()
21+
with VBoxLayout(v_show="view_state.active_tab == 0", stretch=True):
22+
SampleTab1()
23+
with VBoxLayout(v_show="view_state.active_tab == 1", stretch=True):
24+
SampleTab2()

template_sources/{% if application_type != 'Minimal' %}src{% endif %}/{% include 'package_folder_slug.j2' %}/{% if application_type in ['Nova Application', 'Tutorial'] %}app{% endif %}/views/{% if multitabs %}tabs_panel.py{% endif %}

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Module for the Tab panel."""
22

3+
from trame.widgets import client
34
from trame.widgets import vuetify3 as vuetify
45

56
from ..view_models.main_view_model import MainViewModel
@@ -11,9 +12,11 @@ class TabsPanel:
1112
def __init__(self, view_model: MainViewModel):
1213
self.view_model = view_model
1314
self.view_model.config_bind.connect("config")
15+
self.view_model.view_state_bind.connect("view_state")
1416
self.create_ui()
1517

1618
def create_ui(self) -> None:
17-
with vuetify.VTabs(v_model=("active_tab", 0), classes="pl-5"):
18-
vuetify.VTab("Sample Tab 1", value=1)
19-
vuetify.VTab("Sample Tab 2", value=2)
19+
with client.DeepReactive("view_state"):
20+
with vuetify.VTabs(v_model="view_state.active_tab", classes="pl-5"):
21+
vuetify.VTab("Sample Tab 1", value=0)
22+
vuetify.VTab("Sample Tab 2", value=1)

0 commit comments

Comments
 (0)