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

Add right click menu and styling #29

Merged
merged 14 commits into from
Jul 8, 2024
Merged

Conversation

K-Meech
Copy link
Contributor

@K-Meech K-Meech commented Jul 4, 2024

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?
Currently there are no right click menu options + the visibility of layers can't be toggled

What does this PR do?

  • Adds a right click context menu via group_layer_delegate and group_layer_actions
  • This delegate also handles rendering thumbnails / icons on each of the items in the tree
  • Additional styles are added from .qss, copied to match styles of QtListView and QtLayerList from napari - this enables the visibility toggles (eye icons) to be rendered correctly
  • Allows toggling of layer visibility by clicking on 'eye' icons on each row, or via the right click menu options
  • Adds fixes for selection in trees e.g. making sure that selection on the root node propagates to any child groups

References

For #10
Closes #11

How has this PR been tested?

Tests have been added covering new functionality

Is this a breaking change?

No

Does this PR require an update to the documentation?

No

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality (unit & integration)
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

@K-Meech K-Meech requested a review from willGraham01 July 4, 2024 10:11
Copy link

codecov bot commented Jul 4, 2024

Codecov Report

Attention: Patch coverage is 80.62500% with 31 lines in your changes missing coverage. Please review.

Project coverage is 89.36%. Comparing base (b67d4ed) to head (dfc0eb5).
Report is 1 commits behind head on ARC-dev-branch.

Files Patch % Lines
src/napari_experimental/group_layer_delegate.py 67.27% 18 Missing ⚠️
src/napari_experimental/group_layer_qt.py 80.48% 8 Missing ⚠️
src/napari_experimental/group_layer_actions.py 88.37% 5 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##           ARC-dev-branch      #29      +/-   ##
==================================================
- Coverage           93.69%   89.36%   -4.33%     
==================================================
  Files                   6        8       +2     
  Lines                 317      470     +153     
==================================================
+ Hits                  297      420     +123     
- Misses                 20       50      +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@K-Meech
Copy link
Contributor Author

K-Meech commented Jul 4, 2024

Seems that the tests that use qtbot.mouseClick() to simulate double or right clicks are failing on ubuntu (but passing elsewhere).

@willGraham01 willGraham01 mentioned this pull request Jul 5, 2024
6 tasks
Copy link
Contributor

@willGraham01 willGraham01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of things seem to have crept in from Qt that I'm not particularly sure why/if we need them. But otherwise all seems well 🚀

Comment on lines 40 to 43
for item in self.group_layers.selection:
if not item.is_group():
visibility = item.layer.visible
item.layer.visible = not visibility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for item in self.group_layers.selection:
if not item.is_group():
visibility = item.layer.visible
item.layer.visible = not visibility
for node in [item for item in self.group_layers.selection if not item.is_group()]:
visibility = node.layer.visible
node.layer.visible = not visibility

Personally I've been going with this when I only want to iterate though either nodes or groups - "item" is generic and can refer to either nodes or groups but here we really are just using the nodes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Although now I've merged the km/group-vis-toggle branch, it needs to iterate through both groups and nodes to set visibility on both

Comment on lines 19 to 20
logger = logging.getLogger(__name__)
ThumbnailRole = Qt.UserRole + 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we've been using the logger up to this point - is it necessary for us to start using it here? (If so we should probably introduce it across our plugin in one go, rather than just here).

Also not sure what the ThumbnailRole is doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! The logger was left over from some code I copied, so I've removed this now. I've also removed the ThumbnailRole and I'm instead importing this value directly from napari

* toggle visiblity for group layers

* add tests for visiblity

* update docstrings

* fix failing tests
@K-Meech
Copy link
Contributor Author

K-Meech commented Jul 5, 2024

@willGraham01 I think this PR is ready to go in now - could you give it a look over? Thanks!

@K-Meech
Copy link
Contributor Author

K-Meech commented Jul 5, 2024

Ah wait - I found one more small bug. The viewer controls don't display correctly if you select a group followed directly by a layer. Should be a quick fix - I'll look at this now.

@K-Meech
Copy link
Contributor Author

K-Meech commented Jul 5, 2024

Ok - fixed! The issue was it was still listening for changes in the active selection at every level of the tree. Now that selection is handled properly after drag and drop + this propagates down the tree, it only needs to listen to the root.

Copy link
Contributor

@willGraham01 willGraham01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fab - I think most of the new changes I've already implicitly approved in my review of #30 🥳

@willGraham01 willGraham01 merged commit 42acf51 into ARC-dev-branch Jul 8, 2024
14 of 16 checks passed
@willGraham01 willGraham01 deleted the km/right-click branch July 8, 2024 08:19
alessandrofelder added a commit that referenced this pull request Jul 10, 2024
* Pull sample blobs code

* Strip away everything except the open-able widget

* Some basic structures that track the existing layers

* BROKEN: Image layers don't play nice but I did combine the emitter objects

* HACK: Napari will now load up, but this hasn't really fixed the naming issue. I've just hacked in a missing attribute to all of the GroupLayer children - they need to have a Node mixin to behave properly

* I can see when layers are added, and have some kind of list. Still get SEG-faults or index errors when moving groups within groups, particularly empty group into empty group.

* Recognises add/remove layers from viewer and auto-adds to the group layers view. Still seg-fault bug when nesting two empty group layers

* Rename classes to be closer to development language

* Rename and move items to break things up

* Link up group layer selection with layer tab

* Reliable testing framework

* Fix our failing test suite (#13)

* Edit file name to be specific to our use case

* Rename single test

* Add checks on napari `main` (#18)

* Add workflow step to run tests on head of napari

* Add optional dependency on napari-latest which fetches napari from the git repo directly

* Create an optional install that uses HEAD of napari, add it to list of tests

* Add note that napari-latest install is available to README

* Update README.md

Co-authored-by: Alessandro Felder <[email protected]>

---------

Co-authored-by: Alessandro Felder <[email protected]>

* Add conftest and some fixtures for testing (#15)

* Add conftest.py for shared fixtures and do a quick model check for our QtGroupLayerModel

* Typehints don't carry through fixtures

* Allow renaming of layers / group layers (#19)

* allow renaming of groups and layers

* keep prefix for group layers and update setRoot

* remove unused tree_model

* add initial tests for renaming

* add test for editing state on double click

* move tests into test_group_layer_widget

* Correctly Subclass our `GroupLayer` (#20)

* Ensure GroupLayer subclasses from our own subclass of Node

* Define ambiguously inherited attributes (IE ensure I don't break KM's tests)

* Actually use the nested structure fixture so ruff doesn't get angry

* Reorganise the test suite fixture layout since it's starting to get bloated

* Basic tests to check is_group and strict typing

* Self-review

* Allow _check_if_already_tracking to be optionally recursive. Write test for method.

* Update src/napari_experimental/group_layer.py

Co-authored-by: Kimberly Meechan <[email protected]>

* Dammit linter

---------

Co-authored-by: Kimberly Meechan <[email protected]>

* Adds independent layer controls to widget (#22)

* add group layer controls

* fix controls for latest changes to group layer

* remove syncing of selection

* add tests for group layer controls

* fix TypeError

* expand docstrings

* react to sub-groups

* add overview and todo sections to readme (#31)

* Sync GroupLayer and Main Viewer layer orders (#26)

* Allow group_layer to return a flat index

* Enforce layer order updates through the GroupLayer events

* Rework how items are added to GroupLayers to make things more explicit

* Remove unused function

* Docstring Tidy (#27)

* Some docstrings for _widget

* Docstrings for GroupLayerNode class

* docstrings for group_layer_qt

* Docstrings for group_layer.py

* Add attributes and methods to classes where necessary

* Missed a rename

* Add tests for widget activity

* Test for layer deletion sync

* Ruff for 3.9 disagrees with 3.11

* strict keyword not in Py3.9

* Update test_and_deploy.yml (#32) (#33)

* Fix Errors when Moving Layers (#28)

* Allow group_layer to return a flat index

* Enforce layer order updates through the GroupLayer events

* Rework how items are added to GroupLayers to make things more explicit

* Remove unused function

* Docstring Tidy (#27)

* Some docstrings for _widget

* Docstrings for GroupLayerNode class

* docstrings for group_layer_qt

* Docstrings for group_layer.py

* Add attributes and methods to classes where necessary

* Missed a rename

* Write method that fixes the min failing example

* Hey look, a docstring!

* Remove double-counting of positions after destination

* Test revise index method, remove redundant variable passed

* Maybe this is correct if I have a flat index sort a priori

* Fix ordering issue and allow for Groups to be assigned a flatindex

* Add 2nd test to check moving items out of different subgroups still tracks order correctly

* Remove un-necessary variable

* Remove commented-out experimental code

* Apply suggestions from @K-Meech code review

* Add `Implementation` section to README (#34)

* MDLint + alessandrofelder -> brainglobe in README

* Create implementation deatils section

* Group and Node subclassing explanations

* Notes on indexing conventions

* Update README.md

Co-authored-by: Kimberly Meechan <[email protected]>

---------

Co-authored-by: Kimberly Meechan <[email protected]>

* Add right click menu and styling (#29)

* add group layer delegate

* rename group layer delegate

* add context for right click menu

* working minimal right click menu

* fix syncing of selection

* update docstrings and remove unused functions

* fix double click edit

* simplify right click actions and context to fix tests

* update docstrings

* Force widget in tests to have a parent (#35)

* Allows toggling visibility of group layers (#30)

* toggle visiblity for group layers

* add tests for visiblity

* update docstrings

* fix failing tests

* remove logger and thumbnail role

* fix view controls when switching from group to layer

---------

Co-authored-by: Will Graham <[email protected]>

* `main` and `ARC-dev-branch` merge commit reconcile (#37)

* Fix bugs relating to empty `GroupLayers` (#38)

* Fix seg-faults and broken drag-and-drop via overwriting index method

* Switch to unique ID trackers over reimplementing method. Allows safe overwride of __eq__ and __hash__

* Remove one bug from the README broken features section

---------

Co-authored-by: Alessandro Felder <[email protected]>

* Add docs build and populate content (#39)

* Basic Sphinx build and docs structure

* Workflow to publish docs on pushes to main

* Separate sphinx requirements from package requirements

* Add building the docs section

* Reorganise group_layers docs

* Docs API for Groups & Nodes, some source docstring updates for text rendering

* Placeholder for widget docs

* Write widget docs page

* Add note on hashing things

* expand docs for group layers, delegates and context menu (#40)

---------

Co-authored-by: Kimberly Meechan <[email protected]>

---------

Co-authored-by: Alessandro Felder <[email protected]>
Co-authored-by: Kimberly Meechan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants