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

Enhance cell focus and zoom functionality via table #28

Merged
merged 1 commit into from
Jan 27, 2025
Merged
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
26 changes: 18 additions & 8 deletions src/napari_swc_editor/_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ def _set_table(self):
].reset_index()
)
table.native.setEditTriggers(table.native.NoEditTriggers)
table.native.clicked.connect(self._table_clicked)
table.native.doubleClicked.connect(self._table_double_clicked)
table.native.clicked.connect(self._focus_on_current_cell)
table.native.doubleClicked.connect(self._zoom_and_focus_on_current_cell)
table.native.currentCellChanged.connect(self._focus_on_current_cell)

self._point_layer_combo.value.selected_data.events._current.connect(
self._change_current_cell
Expand All @@ -91,7 +92,12 @@ def _set_table(self):
self._viewer.window.add_dock_widget(
self._table.native, area="right"
)
self._point_layer_combo.value.events.data.connect(self._set_table)
else:
self._point_layer_combo.value.selected_data.events._current.connect(
self._change_current_cell
)
self._point_layer_combo.value.events.data.connect(self._set_table)
self._table.value = self._point_layer_combo.value.metadata[
"swc_data"
].reset_index()
Expand All @@ -117,16 +123,20 @@ def _get_layer_data(self):
)
self._link_previous_node_checkbox.enabled = True
self._show_table_button.enabled = True
layer.events.data.connect(self._set_table)
# layer.events.data.connect(self._set_table)

def _set_link_previous_node(self, value):
layer = self._point_layer_combo.value
if layer is None:
return
layer.metadata["widget_link_activated"] = value

def _table_clicked(self, event):
row = event.row()
def _focus_on_current_cell(self, event):

if type(event) != int:
row = event.row()
else:
row = event
x = self._table["x"][row]
y = self._table["y"][row]
z = self._table["z"][row]
Expand All @@ -153,7 +163,7 @@ def _table_clicked(self, event):

self._point_layer_combo.value.selected_data = [row]

def _table_double_clicked(self, event):
def _zoom_and_focus_on_current_cell(self, event):
# same as clicking on the table but zoom
self._table_clicked(event)
self._viewer.camera.zoom = 80
self._focus_on_current_cell(event) # focus on the cell
self._viewer.camera.zoom = 80 # zoom
Loading