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

get a list of active windows/panels #32

Open
harmvanderheijden opened this issue Feb 23, 2020 · 6 comments
Open

get a list of active windows/panels #32

harmvanderheijden opened this issue Feb 23, 2020 · 6 comments

Comments

@harmvanderheijden
Copy link

ipylab is very cool, have been experimenting with it a bit.

I'm trying to get a list of active windows (PhosphorJS panels? Not sure of the right jargon) from the jupyterlab framework, but I don't see how it's done. Looks like the app.shell.widgets dictionary contains a number of widgets that are related to the active panels, but I don't understand the structure.

Ideally I would like to be able to write in Python using ipywidgets a widget that I could place in the left panel (as you demonstrate in the widgets.ipynb example), and which could e.g. open and close windows in the main panel (and keep track of them, interact with them). Sort of how the standard javascript based file explorer in jupyterlab behaves. Is something like that at all possible with the current ipylab framework or should I look elsewhere?

@jtpio
Copy link
Owner

jtpio commented Feb 25, 2020

Thanks for trying it out!

I think it should already be possible to some extent, for example by creating new Panel widgets in Python with panel = Panel() and modify their children.

close windows in the main panel (and keep track of them, interact with them)

This part would probably require adding support for disposing the Phosphor / Lumino panels. What use cases do you have in mind?

@harmvanderheijden
Copy link
Author

Thanks for your reply! Here's what I have in mind:

I have to work with a 3rd party DMS which has a very basic document viewer built-in, rendering only one document at a time. I want to use the Jupyter Lab framework, in particular the Lumino panels, to view multiple documents from that DMS, side by side, allowing dynamic tabbing and resizing and all the other Lumino goodness.

Luckily the DMS has a REST API, so I can write Python code to get a list of available documents, download them, store them in a temporary location, and then somehow get Jupyter Lab to render them.

I want to write a file explorer-like widget in Python which, thanks to ipylab, I can now hook into the Jupyter Lab framework. as a left side panel, so that it could look and behave similar to the native Jupyter Lab file explorer.

But what I then still need is some way to launch a new panel, to switch to an existing panel (if the user clicks on a document that is already open), and to close an existing panel (if the user selects a close button in the widget).

I may be able to do some of that using the panel = Panel() approach, though it seems to me that I would then not be able to leverage Jupyter Lab's native file rendering plugins (I would like to use the standard PDF renderer, for example). It would also probably be easier and more robust if I could iterate, programmatically in python, over all Lumino panels and interrogate them as to which document they render. Hence my original question.

Hope this explanation helps, and that you can provide me with a few pointers on how to achieve this (or a brief explanation why it can't be done, period - that's useful information too). I'm fairly experienced with Python, but don't know much about Javascript/Typescript.

@jtpio
Copy link
Owner

jtpio commented Feb 27, 2020

Thanks for the detailed write-up!

What you describe here is pretty much the goal of ipylab: being able to build a UI with Python that leverages JupyterLab components and Jupyter Widgets.

It's built as a JupyterLab extension, but uses the Jupyter Widget protocol to forward messages from Python to JavaScript. Usually JupyterLab extensions can't interfere and remove things from other extensions, so I'm not sure it would technically be feasible to iterate through all the Lumino widgets and interact with them. However it should be possible to track the ones created from Python and have control over them (to be implemented).

Regarding the PDF example, it's already possible to use the docmanager:open command, and passing the right path to a document the notebook server has access to. This opens a new document in the main area and will use the right renderer based on the file type. Something like the following:

app.commands.execute('docmanager:open', {
    'path': './example.pdf'
})

With examples.pdf being at the root of the notebook server.

Ideally the best would be start building this more advanced application you describe, and see where the problems are and where it's blocking. Then we can start adding the missing bits to ipylab.

@jtpio
Copy link
Owner

jtpio commented Feb 28, 2020

@harmvanderheijden Maybe we could start by adding an example to this repo that builds a tree viewer using ipytree, put it in the left area, and when a leaf node is clicked it calls the docmanager:open command to open the file in the main area.

@harmvanderheijden
Copy link
Author

Sounds like a plan! I'm going to try to make something along those line. Will let you know when I have something.

@jtpio
Copy link
Owner

jtpio commented Feb 29, 2020

Nice!

Don't hesitate to open a PR if you want too add such example to the repo and discuss more.

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

No branches or pull requests

2 participants