hookspec for just doing something without providing a dock widget
See original GitHub issueš Feature
Hi all,
I would like to request for another hookspec that takes functions which are executed when a menu entry is clicked. Examples could be āReset Brightness & Contrastā or āCopy current layerā.
Motivation
Iād like to implement functions such as for resetting brightness contrast
def reset_brightness_contrast(image: Image):
image.contrast_limits = (image.data.min(), image.data.max())
At the moment, the user has to confirm the action in a dock widget which appears a bit cumbersome:
If the operation could just be executed on the current layer[s], that would be cooll. You find more examples here
Pitch
We could extend napari with easy-to-use single-click functions.
Alternatives
Additional context
At some point, we may also start collecting single-click functions such as āReset brightness & contrastā in a common repository.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
Expand DockWidget API and add hookspec? #1327 - GitHub
By making something a dock widget, it already can find the viewer (by just looking at the widget's parent). So pretty much the...
Read more >Docking a QDockWidget when application starts?
I have a class that constructs a widget that I am able to dock into my main application. This class inherits QDockWidget ....
Read more >QDockWidget Class | Qt Widgets 6.4.1
QDockWidget Class. The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-level window on the...
Read more >plotjuggler: ads::CDockWidget Class Reference
The QDockWidget class provides a widget that can be docked inside a CDockManager or floated as a top-level window on the desktop.
Read more >Can I remove the 'close' icon when I create a dock widget in ...
I want to add my own dock widget to the napari viewer. I do not want the user to be able to close...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
yep, now that #2556 is in, we need to think about how to expose these take-a-layer-and-do-something functions externally. This is all rather tightly connected to the concept of the action manager, which is coming along nicely as well. More generally, we can describe these single-click functions as callables that happen in response to an event (button click, mouse press, etc.) with some degree of contextual awareness (a specific layer type is selected, etcā¦)
We definitely plan on exposing such a mechanism, but probably need the action manager and context concept to mature just a bit.
Side note: āauto-scalingā definitely should just be easier to access in the gui. Itās the āresetā button in the contrast limits controller that you get when you right click (we agree itās not discoverable enough)
programmatically, you can use
layer.reset_contrast_limits()
⦠so donāt need a new function for that one (but if you want to add percentile to it, that would be a nice PR).yep, agreed⦠but that āif a labels layer is selectedā sentence there is exactly the sort of context I was referring to above when I said āthereās a lot of contextual stuff to take into considerationā. In other words: yes, itās very simple to say āhey, is a labelās layer selected?ā and satisfy your use case above. but what if someone wants their function to be called only if two images are selected? what if they want an image and a labels? what if they only want a 3D image, not a 2D image? These are the sorts of contextual things weāre trying to codify.
I definitely suggest taking a look through the concepts introduced in #2556, since I think thatās a promising way forward here. Specifically, have a look at the āavailable layerlist contextsā defined here, and how those context keys are used in the ā
enable_when
ā keys of these actions here. Those layer āactionsā are the equivalent of yourmake_labels_editable
command there and theenable_when
context allows us to know when itās a valid function to offer up to the user, and when itās not. for instance, now if you click on an RGB image, the āsplit RGBā action is available:whereas if you have three grayscale images of the same shape selected, you get āmerge to stackā
make sense? So, weāre close to being able to open up that sort of a ādo this simple action if this simple condition is metā⦠but I do think itās a touch more complicated than at first it may appear