spyder-ide / spyder-notebook

Jupyter notebook integration with Spyder
Other
520 stars 129 forks source link

Notebook pane grouped in upper right after changing layout #265

Open ikeszvpvb9ye opened 4 years ago

ikeszvpvb9ye commented 4 years ago

Spyder 4.1.2 the dock panel of the Notebook panel is automatically in the right panel if you select View -> Windows layout -> Spyder Default Layout

What steps will reproduce the problem?

Continuing the task https://github.com/spyder-ide/spyder-notebook/issues/245

  1. Install Anaconda, Spyder4.1.2 and Notebook
  2. Enable Notebook pane through the menu View -> Panes -> Notebook.
  3. We observe the Notebook pane in the pane group on the left, it is grouped with the python script pane
  4. Select the menu View -> Windows layout -> Spyder Default Layout
  5. Enable Notebook pane through the menu View -> Panes -> Notebook
  6. We observe Notebook pane in the pane group on the right, it is grouped with Variable Explorer, Plot, File panes

What is the expected output? What do you see instead? After choosing View -> Windows layout -> Spyder Default Layout and View -> Panes -> Notebook, the Notebook pane is grouped in the pane group on the left next to the python script pane

Versions and main components

Dependencies

Please go to the menu entry Help > Optional Dependencies (or Help > Dependencies), press the button Copy to clipboard and paste the contents below:

atomicwrites >=1.2.0 : 1.3.0 (OK) chardet >=2.0.0 : 3.0.4 (OK) cloudpickle >=0.5.0 : 1.3.0 (OK) diff_match_patch >=20181111 : 20181111 (OK) intervaltree : None (OK) IPython >=4.0 : 7.13.0 (OK) jedi =0.15.2 : 0.15.2 (OK) nbconvert >=4.0 : 5.6.1 (OK) numpydoc >=0.6.0 : 0.9.2 (OK) paramiko >=2.4.0 : 2.7.1 (OK) parso =0.5.2 : 0.5.2 (OK) pexpect >=4.4.0 : 4.8.0 (OK) pickleshare >=0.4 : 0.7.5 (OK) psutil >=5.3 : 5.7.0 (OK) pygments >=2.0 : 2.6.1 (OK) pylint >=0.25 : 2.4.4 (OK) pyls >=0.31.9;<0.32.0 : 0.31.9 (OK) qdarkstyle >=2.8 : 2.8.1 (OK) qtawesome >=0.5.7 : 0.7.0 (OK) qtconsole >=4.6.0 : 4.7.2 (OK) qtpy >=1.5.0 : 1.9.0 (OK) rtree >=0.8.3 : 0.9.4 (OK) sphinx >=0.6.6 : 3.0.1 (OK) spyder_kernels >=1.9.0;<1.10.0 : 1.9.0 (OK) watchdog : None (OK) zmq >=17 : 19.0.0 (OK) cython >=0.21 : 0.29.16 (OK) matplotlib >=2.0.0 : 3.2.1 (OK) numpy >=1.7 : 1.18.1 (OK) pandas >=0.13.1 : 1.0.3 (OK) scipy >=0.17.0 : 1.4.1 (OK) sympy >=0.7.3 : 1.5.1 (OK) spyder_line_profiler : 0.2.0 (OK) spyder_memory_profiler : 0.2.0 (OK) spyder_notebook : 0.2.3 (OK) spyder_terminal : 0.3.0 (OK) spyder_unittest : 0.4.0 (OK)

ikeszvpvb9ye commented 4 years ago

The same goes for other presets in View -> Windows layout. It seems logical that the Notebook pane should dock in the same group as the pane with a python script

jitseniesen commented 4 years ago

I can confirm. This is indeed a bug, either in the plugin or Spyder itself, though perhaps not of the greatest importance.

jitseniesen commented 4 years ago

This is still an issue with Syder 4.1.4 and Spyder-notebook 0.3.0. I think we need to wait for the new plugin API in Spyder 5 before we can solve this.

ccordoba12 commented 4 years ago

@goanpeca, I think there's no API entry in master to tell Spyder where it should put external plugins when using our layouts, right?

goanpeca commented 4 years ago

I think there's no API entry in master to tell Spyder where it should put external plugins when using our layouts, right?

No, we need to define the concept of LOCATIONS on the default layouts, so we can tell plugins to be placed in a given area.

Matlab has 6 areas:

Screen Shot 2020-08-04 at 11 26 37

RStudio has 4 areas:

Screen Shot 2020-08-04 at 11 27 24

Horizontal split has 2

Screen Shot 2020-08-04 at 11 30 07

Vertical split has 2

Screen Shot 2020-08-04 at 11 28 56

Spyder Default has 5

Screen Shot 2020-08-04 at 11 28 20

What to do?

To be able to handle this properly, those areas need some names, then the Layout renderer will place them accordingly on those zones, and the pre-defined Layouts do not define the hard-coded locations for docks, but place the dock on a given LOCATION

These locations need to probably be named based on the global functionality, like:

Etc...

If you can define these things I can make a PR to use this.

ccordoba12 commented 4 years ago

If you can define these things I can make a PR to use this.

Great! Thanks a lot @goanpeca!

@jitseniesen, could you give a hand here? I think the names should be spatial locations (e.g. TOP_RIGHT, BOTTOM_RIGHT, etc), instead of functionality-based, because we shouldn't constrain where developers can put their third-party plugins.

goanpeca commented 4 years ago

@jitseniesen, could you give a hand here? I think the names should be spatial locations (e.g. TOP_RIGHT, BOTTOM_RIGHT, etc), instead of functionality-based, because we shouldn't constrain where developers can put their third-party plugins.

The issue with that is:

Functionality (or another concept) based.

class SomePlugin(SpyderDockablePlugin):
    NAME= "some_plugin"
    LOCATION = Locations.Editors
    ....

If this way, Matlab, Rstudio, Spyder, Horizontal, Vertical, layouts will always work, since those locations are clearly defined for each layout, whereas a fixed position does not make any real sense across the different layout that Spyder bundles as defaults.

In horizontal split, Location.Editors will go on the left, and every other location goes on the right.

because we shouldn't constrain where developers can put their third-party plugins.

Could you elaborate on this, based on the above constraints @ccordoba12?

nerohmot commented 4 years ago

Personally I like the standard Eclipse/PyDev layout ...

image

but then ofcourse in spyder :rofl:

image

@goanpeca I like your idea about the Locations/Areas very much, because it goes a long way in the direction how Eclipse solved this issue in 'perspectives'!

With perspectives we cover all of the above use-cases and can cover any others that might appear in future easily without any change to Spyder! Here is how that would work:

Any plugin can define ONE perspective, named after the plugin, and why not with a nice icon if needed. In a perspective it is defined how many areas there are, where the areas are located, and which of the default 'panes' go in what area. One of the areas is designated as the 'default' area, and any 'pane' not recognized or not assigned an area will go in the default area.

Now what happens if you switch perspective? Things still work because of the 'default' area!

In Eclipse one can switch between the perspectives by clicking the desired 'perspective' button shown below in the red-marked area (top right):

image

In our case that would maybe take up too much space in the (already crowded) toolbar, but we could maybe put it under a 'hamburger' to the far right of the toolbar ?

goanpeca commented 4 years ago

Some pseudo-code for context:

class Locations:
    ExploreLocation = "explore_location"  # Files stuff?, project stuff?
    DocumentationLocation = "documentation_location"  # Help online help...?
    ViewerLocation = "viewer_location"  # Variables explorer, Plots
    EditingLocation = "editing_location"  # Editors
    ExecutionLocation = "execution_location"  # Consoles, Terminal...
    TheRestLocation = "the_rest_location"

# A base layout that defines some basic things
class LayoutType:
    LAYOUT = None
    DEFAULT_AREA = None
    VISIBLE_TOOLBARS = None
    VISIBLE_PANES = None

# 1 Example of how could be used (similar to what is currently done on the main window)
class VerticalSplitLayout(LayoutType):
    LAYOUT = [
        # A single row with two columns
        [
            # Column 1
            {"location": Locations.EditingLocation, "width_fraction": 0.4},
            # Column 2
            {"location": Locations.TheRestLocation, "width_fraction": 0.6},
        ]
    ]
    DEFAULT_AREA = Locations.TheRestLocation
    VISIBLE_TOOLBARS = []
    VISIBLE_PANES = []

# 2 If a global position based on a plugin is needed this could be done like this:
class VerticalSplitLayoutHardcodedPlugin(LayoutType):
    LAYOUT = [
        # A single row with two columns
        [
            # Column 1
            {"plugins": [Plugins.Console], "width_fraction": 0.4},
            # Column 2
            {"plugins": [Plugins.Editor], "width_fraction": 0.6},
        ]
    ]
    DEFAULT_AREA = Plugins.Editor
    VISIBLE_TOOLBARS = []
    VISIBLE_PANES = []

# I prefer the first one, but the second one could also be handled.

# --- a Bit on the new layout plugin
# ---------------------------
class LayoutPlugin(SpyderPluginV2):
    NAME = "layout_manager"

    def register_layout(self, layout_type):
        pass

# --- Some custom layout provided by a plugin
# ---------------------------
class MyCustomLayout(LayoutType):
    LAYOUT = [
        [
            # Row 1
            {"location": Locations.DocumentationLocation, "height_fraction": 0.25},
        ],
        [
            # Row 2
            {"location": Locations.EditingLocation, "height_fraction": 0.5},
        ],
        [
            # Row 3
            {"location": Locations.TheRestLocation, "height_fraction": 0.25},
        ]
    ]
    DEFAULT_AREA = Locations.TheRestLocation
    VISIBLE_TOOLBARS = []
    VISIBLE_PANES = []

# --- Some custom plugin
# ---------------------------

class SomeDockablePlugin(SpyderDockablePlugin):
    LOCATION = Locations.EditingLocation

    def register(self):
        layout_manager = self.get_plugin("layout_manager")
        layout_manager.register_layout(MyCustomLayout)

# Or

class SomeDockablePlugin(SpyderDockablePlugin):
    LOCATION = Plugins.Editor

    def register(self):
        layout_manager = self.get_plugin("layout_manager")
        layout_manager.register_layout(MyCustomLayout)
jitseniesen commented 4 years ago

there's no API entry in master to tell Spyder where it should put external plugins when using our layouts, right?

I thought that is the purpose of the SpyderDockablePlugin.TABIFY variable:

https://github.com/spyder-ide/spyder/blob/36ff0882cab7677c0ebe650de65b55a8b894a234/spyder/api/plugins.py#L1522-L1524

So, what does that variable do?

goanpeca commented 4 years ago

Yes @jitseniesen that is the purpose. Only that location might better name and it could be an area or s plugin. I worked out something yesterday. Will open a PR later today.

matthdu commented 2 years ago

I also had the problem of the Notebook tab showing up on the right with the Variable explorer, Help, and Files tabs.

I use Spyder 4.2.5, spyder-notebook 0.3.2, and macOS 10.14.16. I start Spyder from Terminal.

The problem was fixed after going to Preferences and clicking "Reset to defaults".