Skip to content
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

Fix dot_seq5b reset #678

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/hubbleds/pages/03-distance-measurements/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ def turn_on_guard():

solara.use_effect(turn_on_guard, [use_guard])

def reset_canvas():
def _reset_canvas():
logger.info('resetting canvas')
widget = cast(DistanceTool,solara.get_widget(tool))
widget.reset_canvas()


solara.use_effect(reset_canvas, [reset_canvas])
solara.use_effect(_reset_canvas, [reset_canvas])

def _define_callbacks():
widget = cast(DistanceTool,solara.get_widget(tool))
Expand Down Expand Up @@ -441,7 +441,6 @@ def _on_marker_updated(marker_new, marker_old):

if marker_new == Marker.dot_seq5:
# clear the canvas before we get to the second measurement.
COMPONENT_STATE.value.show_ruler = False
reset_canvas.set(reset_canvas.value + 1)


Expand Down Expand Up @@ -545,11 +544,10 @@ def on_example_galaxy_marker():

@solara.lab.computed
def current_galaxy():
galaxy = COMPONENT_STATE.value.selected_galaxy
example_galaxy = COMPONENT_STATE.value.selected_example_galaxy
gal = example_galaxy if on_example_galaxy_marker.value else galaxy
logger.info(f'current_galaxy: {gal}')
return gal
if on_example_galaxy_marker.value:
return COMPONENT_STATE.value.selected_example_galaxy
else:
return COMPONENT_STATE.value.selected_galaxy

@solara.lab.computed
def current_data():
Expand Down Expand Up @@ -608,7 +606,8 @@ def _distance_cb(theta):
def _get_ruler_clicks_cb(count):
ruler_click_count = Ref(COMPONENT_STATE.fields.ruler_click_count)
ruler_click_count.set(count)


# solara.Button("Reset Canvas", on_click=lambda: reset_canvas.set(reset_canvas.value + 1))
DistanceToolComponent(
galaxy=current_galaxy.value,
show_ruler=COMPONENT_STATE.value.show_ruler,
Expand All @@ -617,7 +616,7 @@ def _get_ruler_clicks_cb(count):
bad_measurement_callback=_bad_measurement_cb,
use_guard=True,
brightness_callback=lambda b: logger.info(f'Update Brightness: {b}'),
reset_canvas=reset_canvas
reset_canvas=reset_canvas.value
)

if COMPONENT_STATE.value.bad_measurement:
Expand Down Expand Up @@ -822,6 +821,13 @@ def update_galaxy(galaxy):
value = galaxy["item"]["galaxy"] if flag else None
selected_galaxy = Ref(COMPONENT_STATE.fields.selected_galaxy)
selected_galaxy.set(value)

@solara.lab.computed
def selected_galaxy_index():
try:
return [LOCAL_STATE.value.get_measurement_index(COMPONENT_STATE.value.selected_galaxy["id"])]
except:
return []

@solara.lab.computed
def table_kwargs():
Expand All @@ -833,6 +839,7 @@ def table_kwargs():
"items": table_data,
"highlighted": False, # TODO: Set the markers for this,
"event_on_row_selected": update_galaxy,
"selected_indices": selected_galaxy_index.value,
"show_select": True,
"button_icon": "mdi-tape-measure",
"show_button": COMPONENT_STATE.value.current_step_at_or_after(Marker.fil_rem1),
Expand Down
5 changes: 5 additions & 0 deletions src/hubbleds/widgets/distance_tool/distance_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self, *args, **kwargs):
self._rt = RepeatedTimer(self.UPDATE_TIME, self._update_wwt_state)
self._rt.start()
self.update_text()
self.resetting = False
super().__init__(*args, **kwargs)

def __del__(self):
Expand All @@ -76,6 +77,7 @@ def _setup_widget(self):
instant=True)

def reset_canvas(self):
self.resetting = True
self.send({"method": "reset", "args": []})

def update_text(self):
Expand All @@ -100,6 +102,9 @@ def vue_toggle_measuring(self, _args=None):

@observe('measuredDistance')
def _on_measured_distance_changed(self, change):
if self.resetting:
self.resetting = False
return
fov = self.widget.get_fov()
widget_height = self._height_from_pixel_str(self.widget.layout.height)
ang_size = Angle(((change["new"] / widget_height) * fov))
Expand Down