Skip to content

Commit

Permalink
More gardening.
Browse files Browse the repository at this point in the history
  • Loading branch information
mchilvers committed Apr 1, 2024
1 parent 9b67b87 commit 5b99d73
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/tools/builder/src/python/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pyscript.ffi import create_proxy

import invent
from invent.ui import AVAILABLE_COMPONENTS, create_component, export
from invent.ui import App, AVAILABLE_COMPONENTS, create_component, export, Page
from invent.ui.core import Column, Container, Component, Row, Widget, from_datastore
from invent.ui.page import Page

Expand All @@ -20,12 +20,7 @@ def __init__(self):
"""

# The Invent app that the builder is building.
self.app = invent.ui.App(
name="Invent Demo",
content=[
invent.ui.Page(name="Page 1")
]
)
self._app = None

# The JS-side of the Invent-Builder.
self._js_builder_model = None
Expand All @@ -38,6 +33,10 @@ def __init__(self):
# It will be one of "left", "right", "above", "below".
self._insertion_mode = None

# TODO: We might eventually open with an existing app, but here we just create
# one with a single, empty page.
self.app = App(name="Invent Demo", content=[Page(name="Page 1")])

def set_js_builder_model(self, js_builder_model):
"""
Connects the Python side of the view model to the JS side.
Expand All @@ -58,7 +57,12 @@ def app(self, app):
"""
Set the app that we are building.
"""
# Inject the JS handlers to make component selection and drag-and-drop work.
if self._app is not None:
# If there is a current app, remove all the JS event handlers from it.
self._remove_js_event_handlers_from_app(self._app)

# Inject the JS event handlers to make component selection and drag-and-drop
# work.
self._inject_js_event_handlers_into_app(app)

# The builder is now officially managing the rehydrated app!
Expand Down Expand Up @@ -513,6 +517,13 @@ def _on_drop_component(self, event, component):
print("Inserting after:", self._insertion_mode, insert_after)
self.insert_component_after(insert_after, new_component)

def _remove_js_event_handlers_from_app(self, app):
"""
Remove the JS event handlers from the specified app.
"""
for page in app.content:
self._remove_js_event_handlers_from_component(page)

def _remove_js_event_handlers_from_component(self, component):
"""
Remove the JS event handlers from the specified component.
Expand Down

0 comments on commit 5b99d73

Please sign in to comment.