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

Hide or Destroy dock widgets #3331

Merged
merged 13 commits into from
Sep 28, 2021
Merged

Conversation

ppwadhwa
Copy link
Contributor

@ppwadhwa ppwadhwa commented Sep 3, 2021

This PR adds the options to hide or destroy a dock widget from the title bar.

See #3101

Screen.Recording.2021-09-03.at.1.21.22.AM.mov

@github-actions github-actions bot added design Design discussion qt Relates to qt labels Sep 3, 2021
@tlambert03
Copy link
Contributor

love it! will have a look soon

@ppwadhwa
Copy link
Contributor Author

ppwadhwa commented Sep 5, 2021

@tlambert03 I'm glad to hear this response. :) I still need to do a little more work on it. Got some direction from @goanpeca on some trouble I was having with it, so will make a few changes and request a review from you soon!

@codecov
Copy link

codecov bot commented Sep 5, 2021

Codecov Report

Merging #3331 (50ce25b) into main (c4c987c) will increase coverage by 0.03%.
The diff coverage is 91.04%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3331      +/-   ##
==========================================
+ Coverage   82.65%   82.68%   +0.03%     
==========================================
  Files         549      549              
  Lines       45690    45691       +1     
==========================================
+ Hits        37763    37780      +17     
+ Misses       7927     7911      -16     
Impacted Files Coverage Δ
napari/_qt/widgets/qt_viewer_dock_widget.py 94.73% <88.23%> (-1.80%) ⬇️
napari/_qt/menus/plugins_menu.py 92.30% <91.66%> (+23.95%) ⬆️
napari/_qt/qt_main_window.py 74.30% <92.85%> (-1.86%) ⬇️
napari/_qt/_tests/test_plugin_widgets.py 99.02% <100.00%> (+0.06%) ⬆️
napari/_qt/widgets/_tests/test_qt_dock_widget.py 100.00% <100.00%> (ø)
napari/_qt/perf/qt_performance.py 97.10% <0.00%> (+7.24%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4c987c...50ce25b. Read the comment docs.

@ppwadhwa ppwadhwa changed the title WIP: Hide or Destroy dock widgets Hide or Destroy dock widgets Sep 6, 2021
@ppwadhwa ppwadhwa marked this pull request as ready for review September 6, 2021 04:44
@ppwadhwa
Copy link
Contributor Author

ppwadhwa commented Sep 6, 2021

@tlambert03 I am ready for your review. One of the last things I did was to only include a "hide" dock widget option for every non-plugin dock widget. For the console, layer list, etc., it seemed a bit complicated if that widget was destroyed and then recreated if a user selected it from the menu. I decided to leave that for another time if that is wanted. This means, though, that those dock widgets have an "eye" symbol and not and 'x'. Let me know if this is OK, or if should use different symbols.

cc @goanpeca

Copy link
Contributor

@tlambert03 tlambert03 left a comment

Choose a reason for hiding this comment

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

the functionality is great. I really want us to be "killing" plugin dock widgets more readily, and this accomplishes that, so happy to have this go in (once tests have been added that assert that when you close a plugin dock widget, it does indeed get destroyed, and it gets removed from window._dock_widgets, and stuff)

I feel like the code itself is starting to get a little messy ... we're starting to spread and mix together the logic for various concerns (plugin widgets, builtin dock widgets, etc...), and methods are getting longer and harder to test. everywhere that comments "check to see if this is a plugin" should ideally be in a section that knows it it's a plugin widget. (remember, all of these widgets were added at one point with either add_dock_widget or add_plugin_dock_widget... so that information was known at one point in the function chain... )

I'm fine with this going in as is, but it would be a good target for a future refactor

if dock_widget.isVisible():
dock_widget.hide()
else:
dock_widget.show()
Copy link
Contributor

Choose a reason for hiding this comment

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

can you comment on this? it feels weird to me that someone would ever call add_plugin_dock_widget(...) and the result would be to hide the widget (even if it already existed). i.e. add_plugin_dock_widget is not a "toggle dock widget" method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was something I added when I was trying to get the behavior to work properly when a widget was undocked and then you toggled the widget from the menu. Right now, it will call add_plugin_dock_widget when an action is toggled. I suppose I should change that?

self.window_menu.addAction(action)

def _toggle_dock_visibility(self, dock_widget=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

can't see where this is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it looks to be left over from an old idea. thanks for catching this.

@@ -59,6 +59,9 @@ class QtViewerDockWidget(QDockWidget):
them distribute across the vertical space). By default, True.
"""

closed = Signal()
Copy link
Contributor

Choose a reason for hiding this comment

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

really don't like creating new signals and involving other widgets (here the QMainWindow) in the business of "managing" other widgets if it's at all possible to have that other widget manage itself. In this case, it looks like you're creating new signals so that you can check and uncheck the menu action when this gets hidden and shown... but don't you already have a handle to that action below (around line 275)? do we need the main window to do this?

)
else:
add_close = False
except AttributeError:
Copy link
Contributor

Choose a reason for hiding this comment

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

what causes the attribute error here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will fail on start up. I think QtCustomTitleBar is called for the layer list and layer controls before the plugins menu is created.

@ppwadhwa
Copy link
Contributor Author

ppwadhwa commented Sep 7, 2021

thanks @tlambert03 ! I will make some changes based on your comments. I want to get it right, so I'm happy to work on it some more. I may ask for help if I can't get something to work.

@ppwadhwa
Copy link
Contributor Author

ppwadhwa commented Sep 14, 2021

quick update---I've addressed some of the comments above, but still need to add some tests.

Also, I think I should re-work this part of code:

          def _add_widget(*args, key=key, hook_type=hook_type):
                if hook_type == 'dock':
                    self._win.add_plugin_dock_widget(*key)
                else:
                    self._win._add_plugin_function_widget(*key)

            action.setCheckable(True)
            # check that this wasn't added to the menu already
            actions = [a.text() for a in menu.actions()]
            if action.text() not in actions:
                menu.addAction(action)
            action.triggered.connect(_add_widget)

I am treating add_plugin_dock_widget and _add_plugin_function_widget as toggle functions. We don't want that, right @tlambert03 ?

@tlambert03
Copy link
Contributor

I am treating add_plugin_dock_widget and _add_plugin_function_widget as toggle functions. We don't want that, right @tlambert03 ?

correct. i know we probably need the concept of "toggle" somewhere in there, but the actual add_plugin_dock_widget function itself should not be the "toggler".

@github-actions github-actions bot added the tests Something related to our tests label Sep 15, 2021
@ppwadhwa
Copy link
Contributor Author

@tlambert03 I'm ready for you to take a look again! thank you!

@ppwadhwa ppwadhwa force-pushed the dock_widgets_options branch 2 times, most recently from 87bdc0f to 6f83301 Compare September 21, 2021 16:48
Copy link
Contributor

@goanpeca goanpeca left a comment

Choose a reason for hiding this comment

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

LGTM @ppwadhwa, thanks!

Copy link
Contributor

@tlambert03 tlambert03 left a comment

Choose a reason for hiding this comment

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

good stuff!

Copy link
Contributor

@sofroniewn sofroniewn left a comment

Choose a reason for hiding this comment

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

LGTM! Nice work

@sofroniewn sofroniewn merged commit 64195e2 into napari:main Sep 28, 2021
@ppwadhwa ppwadhwa deleted the dock_widgets_options branch September 28, 2021 03:41
Czaki added a commit that referenced this pull request Mar 7, 2023
# Description
<!-- What does this pull request (PR) do? Why is it necessary? -->
<!-- Tell us about your new feature, improvement, or fix! -->
<!-- If your change includes user interface changes, please add an
image, or an animation "An image is worth a thousand words!" -->
<!-- You can use https://www.cockos.com/licecap/ or similar to create
animations -->

It removes the `setVisible` call triggered during minimalization of
napari window

## Type of change
<!-- Please delete options that are not relevant. -->
- [x] Bug-fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

# References
<!-- What resources, documentation, and guides were used in the creation
of this PR? -->
<!-- If this is a bug-fix or otherwise resolves an issue, reference it
here with "closes #(issue)" -->

closes #5576

# How has this been tested?
<!-- Please describe the tests that you ran to verify your changes. -->
- [ ] example: the test suite for my feature covers cases x, y, and z
- [ ] example: all tests pass with my change
- [ ] example: I check if my changes works with both PySide and PyQt
backends
      as there are small differences between the two Qt bindings.  

## Final checklist:
- [ ] My PR is the minimum possible work for the desired functionality
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] If I included new strings, I have used `trans.` to make them
localizable.
For more information see our [translations
guide](https://napari.org/developers/translations.html).

@ppwadhwa You add this in #3331. Maybe I missed some use case and this
need to be called in some scenarios.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Czaki added a commit that referenced this pull request Jun 18, 2023
# Description
<!-- What does this pull request (PR) do? Why is it necessary? -->
<!-- Tell us about your new feature, improvement, or fix! -->
<!-- If your change includes user interface changes, please add an
image, or an animation "An image is worth a thousand words!" -->
<!-- You can use https://www.cockos.com/licecap/ or similar to create
animations -->

It removes the `setVisible` call triggered during minimalization of
napari window

## Type of change
<!-- Please delete options that are not relevant. -->
- [x] Bug-fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

# References
<!-- What resources, documentation, and guides were used in the creation
of this PR? -->
<!-- If this is a bug-fix or otherwise resolves an issue, reference it
here with "closes #(issue)" -->

closes #5576

# How has this been tested?
<!-- Please describe the tests that you ran to verify your changes. -->
- [ ] example: the test suite for my feature covers cases x, y, and z
- [ ] example: all tests pass with my change
- [ ] example: I check if my changes works with both PySide and PyQt
backends
      as there are small differences between the two Qt bindings.  

## Final checklist:
- [ ] My PR is the minimum possible work for the desired functionality
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] If I included new strings, I have used `trans.` to make them
localizable.
For more information see our [translations
guide](https://napari.org/developers/translations.html).

@ppwadhwa You add this in #3331. Maybe I missed some use case and this
need to be called in some scenarios.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Czaki added a commit that referenced this pull request Jun 19, 2023
# Description
<!-- What does this pull request (PR) do? Why is it necessary? -->
<!-- Tell us about your new feature, improvement, or fix! -->
<!-- If your change includes user interface changes, please add an
image, or an animation "An image is worth a thousand words!" -->
<!-- You can use https://www.cockos.com/licecap/ or similar to create
animations -->

It removes the `setVisible` call triggered during minimalization of
napari window

## Type of change
<!-- Please delete options that are not relevant. -->
- [x] Bug-fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

# References
<!-- What resources, documentation, and guides were used in the creation
of this PR? -->
<!-- If this is a bug-fix or otherwise resolves an issue, reference it
here with "closes #(issue)" -->

closes #5576

# How has this been tested?
<!-- Please describe the tests that you ran to verify your changes. -->
- [ ] example: the test suite for my feature covers cases x, y, and z
- [ ] example: all tests pass with my change
- [ ] example: I check if my changes works with both PySide and PyQt
backends
      as there are small differences between the two Qt bindings.  

## Final checklist:
- [ ] My PR is the minimum possible work for the desired functionality
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] If I included new strings, I have used `trans.` to make them
localizable.
For more information see our [translations
guide](https://napari.org/developers/translations.html).

@ppwadhwa You add this in #3331. Maybe I missed some use case and this
need to be called in some scenarios.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Czaki added a commit that referenced this pull request Jun 21, 2023
# Description
<!-- What does this pull request (PR) do? Why is it necessary? -->
<!-- Tell us about your new feature, improvement, or fix! -->
<!-- If your change includes user interface changes, please add an
image, or an animation "An image is worth a thousand words!" -->
<!-- You can use https://www.cockos.com/licecap/ or similar to create
animations -->

It removes the `setVisible` call triggered during minimalization of
napari window

## Type of change
<!-- Please delete options that are not relevant. -->
- [x] Bug-fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

# References
<!-- What resources, documentation, and guides were used in the creation
of this PR? -->
<!-- If this is a bug-fix or otherwise resolves an issue, reference it
here with "closes #(issue)" -->

closes #5576

# How has this been tested?
<!-- Please describe the tests that you ran to verify your changes. -->
- [ ] example: the test suite for my feature covers cases x, y, and z
- [ ] example: all tests pass with my change
- [ ] example: I check if my changes works with both PySide and PyQt
backends
      as there are small differences between the two Qt bindings.  

## Final checklist:
- [ ] My PR is the minimum possible work for the desired functionality
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] If I included new strings, I have used `trans.` to make them
localizable.
For more information see our [translations
guide](https://napari.org/developers/translations.html).

@ppwadhwa You add this in #3331. Maybe I missed some use case and this
need to be called in some scenarios.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Czaki added a commit that referenced this pull request Jun 21, 2023
# Description
<!-- What does this pull request (PR) do? Why is it necessary? -->
<!-- Tell us about your new feature, improvement, or fix! -->
<!-- If your change includes user interface changes, please add an
image, or an animation "An image is worth a thousand words!" -->
<!-- You can use https://www.cockos.com/licecap/ or similar to create
animations -->

It removes the `setVisible` call triggered during minimalization of
napari window

## Type of change
<!-- Please delete options that are not relevant. -->
- [x] Bug-fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

# References
<!-- What resources, documentation, and guides were used in the creation
of this PR? -->
<!-- If this is a bug-fix or otherwise resolves an issue, reference it
here with "closes #(issue)" -->

closes #5576

# How has this been tested?
<!-- Please describe the tests that you ran to verify your changes. -->
- [ ] example: the test suite for my feature covers cases x, y, and z
- [ ] example: all tests pass with my change
- [ ] example: I check if my changes works with both PySide and PyQt
backends
      as there are small differences between the two Qt bindings.  

## Final checklist:
- [ ] My PR is the minimum possible work for the desired functionality
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] If I included new strings, I have used `trans.` to make them
localizable.
For more information see our [translations
guide](https://napari.org/developers/translations.html).

@ppwadhwa You add this in #3331. Maybe I missed some use case and this
need to be called in some scenarios.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Czaki added a commit that referenced this pull request Jun 21, 2023
# Description
<!-- What does this pull request (PR) do? Why is it necessary? -->
<!-- Tell us about your new feature, improvement, or fix! -->
<!-- If your change includes user interface changes, please add an
image, or an animation "An image is worth a thousand words!" -->
<!-- You can use https://www.cockos.com/licecap/ or similar to create
animations -->

It removes the `setVisible` call triggered during minimalization of
napari window

## Type of change
<!-- Please delete options that are not relevant. -->
- [x] Bug-fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

# References
<!-- What resources, documentation, and guides were used in the creation
of this PR? -->
<!-- If this is a bug-fix or otherwise resolves an issue, reference it
here with "closes #(issue)" -->

closes #5576

# How has this been tested?
<!-- Please describe the tests that you ran to verify your changes. -->
- [ ] example: the test suite for my feature covers cases x, y, and z
- [ ] example: all tests pass with my change
- [ ] example: I check if my changes works with both PySide and PyQt
backends
      as there are small differences between the two Qt bindings.  

## Final checklist:
- [ ] My PR is the minimum possible work for the desired functionality
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] If I included new strings, I have used `trans.` to make them
localizable.
For more information see our [translations
guide](https://napari.org/developers/translations.html).

@ppwadhwa You add this in #3331. Maybe I missed some use case and this
need to be called in some scenarios.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design discussion qt Relates to qt tests Something related to our tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants