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

PR: Changed code that causes inconsistency in layouts #20141

Open
wants to merge 2 commits into
base: 5.x
Choose a base branch
from

Conversation

dan123456-eng
Copy link
Contributor

@dan123456-eng dan123456-eng commented Dec 1, 2022

Description of Changes

Change in the code that causes the problem
#20078.

Modified code:

plugin.blockSignals(True)
#plugin.dockwidget.show()
#plugin.toggle_view_action.setChecked(True)
plugin.blockSignals(False)`

Issue(s) Resolved

Fixes #20078

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Hey @dan123456-eng, thanks a lot for your contribution! I'm afraid this still needs more work (see below).

Comment on lines 509 to 510
plugin.dockwidget.show()
plugin.toggle_view_action.setChecked(True)
Copy link
Member

Choose a reason for hiding this comment

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

By commenting these two lines you're preventing external plugins to be shown when switching layouts, which is basically what this for loop is doing.

So, you need to find a better solution that preserves this functionality and fixes the bug you found.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @ccordoba12! I'm here working on a better solution that preserves things correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @ccordoba12 how are you? Is the purpose of this loop to keep the third panel (if checked to stay open), eg when I switch from Rstudio layout to Matlab layout?

Copy link
Member

@ccordoba12 ccordoba12 Dec 3, 2022

Choose a reason for hiding this comment

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

Exactly, that's the idea! The problem before I added this loop was that no third-party plugin was shown when switching between different layouts.

But the bug it introduced is that it's not respecting plugins that are declared as not visible in the layout declaration. That must preserved when switching layouts as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, that's exactly what I thought. I'll keep looking for a solution here and let you know. Tks!

Copy link
Contributor Author

@dan123456-eng dan123456-eng Dec 6, 2022

Choose a reason for hiding this comment

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

I fixed the bug. I'll update the PR soon.

@ccordoba12 ccordoba12 added this to the v5.4.1 milestone Dec 3, 2022
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

@dan123456-eng, I'm afraid this still needs more work (see below).

external_plugins_to_show.append(plugin.NAME)
if (plugin.NAME in PLUGIN_REGISTRY.external_plugins):
for plugin in dockable_plugins:
external_plugins_to_show.append(plugin.dockwidget.isVisible())
Copy link
Member

Choose a reason for hiding this comment

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

This list (i.e. external_plugins_to_show) needs to contain the plugin names that are going to be restored in the for loop below. However, now you're saving on it boolean values (i.e. True or False) according to the plugin's visibility.

This change doesn't generate an error because we're using

plugin = main_window.get_plugin(plugin_id, error=False)

in line 503, which simply returns None if there are any errors when trying to return the plugin instance from its name.

Copy link
Contributor Author

@dan123456-eng dan123456-eng Dec 12, 2022

Choose a reason for hiding this comment

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

Hi! I uploaded it this way because here using the "visible = False or True" part works correctly and keeps the plugins when switching Spyder layouts.

The way it was previously restored the panels by "plugin.NAME" no matter if it was "visible = False or True".

Now I will try to use "plugin.NAME" and check if it is "visible = False or True".

Sorry for the delay to answer you. I had to do some university stuff.

Copy link
Member

Choose a reason for hiding this comment

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

Now I will try to use "plugin.NAME" and check if it is "visible = False or True".

Ok, I think that idea could work.

Sorry for the delay to answer you. I had to do some university stuff.

No problem, I understand.

Copy link
Contributor Author

@dan123456-eng dan123456-eng Dec 19, 2022

Choose a reason for hiding this comment

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

Hello @ccordoba12 I did it as follows and tested it, everything worked correctly. When its can take a look and if everything is ok I'll go up to PR. Tks!

    `# Stores boolean values of panels
    external_plugins_value = []

    # External dockable plugins to show after the layout is applied
    external_plugins_to_show = []
    
    # Before applying a new layout all plugins need to be hidden
    for plugin in dockable_plugins:
        all_plugin_ids.append(plugin.NAME)

        # Save currently displayed external plugins
        if (plugin.NAME in PLUGIN_REGISTRY.external_plugins and plugin.dockwidget.isVisible()):
            for plugin in dockable_plugins:
                external_plugins_value.append(plugin.dockwidget.isVisible())
            
        plugin.toggle_view(False)
        
        # Checks if the value is true
        for value in external_plugins_value:
            if value == True == plugin.dockwidget.isVisible():
                external_plugins_to_show.append(plugin.NAME)

    plugin.toggle_view(False)`

Copy link
Member

Choose a reason for hiding this comment

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

There are some issues with the solution you proposed above:

  • This if statement

    if (plugin.NAME in PLUGIN_REGISTRY.external_plugins and plugin.dockwidget.isVisible()):
        for plugin in dockable_plugins:
            external_plugins_value.append(plugin.dockwidget.isVisible())

    is adding an entry per dockable plugin to the external_plugins_value list with its visibility state. My question is: why is it necessary to iterate over all dockable plugins here?

  • This for loop

    # Checks if the value is true
    for value in external_plugins_value:
        if value == True == plugin.dockwidget.isVisible():
            external_plugins_to_show.append(plugin.NAME)

    is not adding any plugin to external_plugins_to_show because before it you have the command plugin.toggle_view(False), which changes the visibility of plugin. In other words plugin.dockwidget.isVisible() will always return False in the line

    if value == True == plugin.dockwidget.isVisible():

So I don't think it'd work either, sorry.

Copy link
Contributor Author

@dan123456-eng dan123456-eng Dec 27, 2022

Choose a reason for hiding this comment

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

There are a few problems with the solution you proposed above:

  • This statementif

    if (plugin.NAME in PLUGIN_REGISTRY.external_plugins and plugin.dockwidget.isVisible()):
        for plugin in dockable_plugins:
            external_plugins_value.append(plugin.dockwidget.isVisible())

    is adding a plug-in entry that is in place to the list with its visibility state. My question is: why is it necessary to iterate over all the plugins that fit here?external_plugins_value

here i do the iteration to get all true and false values from external plugins and store in external_plugins_value.

Copy link
Contributor Author

@dan123456-eng dan123456-eng Dec 27, 2022

Choose a reason for hiding this comment

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

  • This loopfor

    # Checks if the value is true
    for value in external_plugins_value:
        if value == True == plugin.dockwidget.isVisible():
            external_plugins_to_show.append(plugin.NAME)

    is not adding any plugin for because before it you have the command , which changes the visibility of the . In other words, it will always return on the lineexternal_plugins_to_show``plugin.toggle_view(False)``plugin``plugin.dockwidget.isVisible()``False

    if value == True == plugin.dockwidget.isVisible():

So I don't think it would work either, sorry.

here I add plugin.NAME only if True ("if open") external_plugins_value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I don't think it would work either, sorry.

Thank you for your help and for your patience.

@ccordoba12
Copy link
Member

@dan123456-eng, could you better explain what you're trying to achieve in this pull request? I don't understand it very well but I think if I did, I think I could give you better guidance.

@ccordoba12 ccordoba12 modified the milestones: v5.4.1, v5.4.2 Dec 26, 2022
@dan123456-eng
Copy link
Contributor Author

dan123456-eng commented Dec 27, 2022

@dan123456-eng, could you better explain what you're trying to achieve in this pull request? I don't understand it very well but I think if I did, I think I could give you better guidance.

In this PR I'm trying to add in "external_plugins_to_show.append(plugin.NAME)" only plugin.NAME that visible==True.

        if (
            plugin.NAME in PLUGIN_REGISTRY.external_plugins
            and plugin.dockwidget.isVisible()
        ):
            external_plugins_to_show.append(plugin.NAME)

In the code above "plugin.NAME" is added in "external_plugins_to_show.append(plugin.NAME)" both visible=True and visible=False.

@ccordoba12 ccordoba12 modified the milestones: v5.4.2, v5.4.3 Jan 5, 2023
@ccordoba12 ccordoba12 modified the milestones: v5.4.3, v5.4.4 Mar 22, 2023
@ccordoba12 ccordoba12 modified the milestones: v5.4.4, v5.5.0 Jun 22, 2023
@ccordoba12 ccordoba12 modified the milestones: v5.5.0, v6.0alpha3 Oct 20, 2023
@ccordoba12 ccordoba12 modified the milestones: v6.0alpha3, v6.0beta1 Nov 17, 2023
@ccordoba12 ccordoba12 modified the milestones: v6.0alpha4, v6.0beta1 Feb 6, 2024
@ccordoba12 ccordoba12 modified the milestones: v6.0alpha5, v6.0beta1 Mar 12, 2024
@ccordoba12 ccordoba12 modified the milestones: v6.0beta1, v6.1.0 May 6, 2024
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