question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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: image

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:open
  • Created 2 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
tlambert03commented, Jul 10, 2021

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)

Untitled

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).

1reaction
tlambert03commented, Jul 11, 2021

If a labels layer is selected, this could just be executed

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 your make_labels_editable command there and the enable_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:

Untitled

whereas if you have three grayscale images of the same shape selected, you get ā€œmerge to stackā€

Untitled3

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found