Skip to content

wxGUI: Initial support for Jupyter-based workflows #5901

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lindakarlovska
Copy link
Contributor

@lindakarlovska lindakarlovska commented Jun 17, 2025

This pull request introduces support for running Jupyter notebooks directly within the GUI. The key benefit is the ability to use pre-configured notebooks, allowing users to start working in a Jupyter environment immediately with minimal setup. It assumes the user has the Jupyter Notebook Python package installed and available in their system.

Welcome to GRASS Jupyter environment
Screenshot from 2025-06-17 13-37-29

Implementation Overview

  • python/grass/workflows/

    • directory.py
      Contains the JupyterDirectoryManager class, which manages Jupyter notebooks linked to the current mapset.
      Responsibilities include mainly: Import/export of .ipynb files and managing notebook templates (welcome.ipynb, new.ipynb).

    • server.py
      Provides two key classes: JupyterServerInstance which handles the lifecycle of an individual Jupyter server instance—installation check, port management, startup, shutdown, URL generation, etc. Also handles cleanup using atexit and signal handling to ensure servers are terminated when GRASS exits via GUI, exit, CTRL+C, or kill PID. Further, JupyterServerRegistry—a singleton that registers all active Jupyter server instances. It allows the global shutdown of all running servers when GRASS is closed from the GUI.

    • template_notebooks/
      welcome.ipynb: A welcome notebook created on first server startup in a working directory
      new.ipynb: A template used when the user creates a new notebook via GUI

  • gui/wxpython/jupyter_notebook/

    • panel.py - defines the JupyterPanel class, which creates the interactive panel inside the GUI. It includes: A toolbar and an AuiNotebook widget that lists and displays .ipynb files from the working directory

    • notebook.py
      Class JupyterAuiNotebook—Handles logic for adding AUI notebook tabs with JavaScript injection for hiding the Jupyter File menu and header.

    • toolbars.py
      Class JupyterToolbar—Implements the toolbar controls for notebook actions: Create new notebook, Import notebook, Export notebook, Dock/Undock, Quit
      Screenshot from 2025-06-17 13-39-39

New icons order in Main window tab
Icons are newly grouped based on the Worflow character:
Screenshot from 2025-06-17 13-43-27

Additional Notes
- Multiple Jupyter servers can run in a single GRASS session (one per panel)
- All servers are automatically stopped when the GUI is closed or the session ends, even forcefully
- If no notebook is present in the working directory, a default welcome notebook is shown
- Notebooks are pre-initialized with GRASS Jupyter environment and required imports for immediate use

Working Directory - Topic for discussion
A running Jupyter server requires a working directory. Currently, the server starts in the active mapset directory, where a notebooks subdirectory is automatically created. This approach is the simplest to implement, as the session mapset directory is always available and writable.

However, from a conceptual point, it's not ideal—grassdata dir is intended for spatial data, not for workflows. In the future, I would suggest introducing a default workflow directory such as ~/grass-workflows, which would host user notebooks independently of grassdata. This concept could be expanded with a Workflows panel offering simple view and management functionality of added workflow directories. The idea is further outlined in this presentation and I am going to set up the Discussion via Discussions on GitHub.

  • Provide link to the discussion about Workflows in GRASS GUI

Following steps

  • To have it accessible on Windows, we would need to add the Jupyter notebook library into builds. @landam Would it be possible for you to do it?
  • At some point, we should revisit the discussion about implementing a GRASS-specific Jupyter kernel — I still believe it makes sense (for example, ArcGIS Pro also provides its own). With such a kernel, users could run notebooks without needing manual initialization code. They could simply select the GRASS kernel and start working in the same way, no matter whether launching Jupyter from within the GUI or in a standalone browser session. Just noting this here for context — we’ve already talked about it briefly, but during the summit it felt too early to make a decision. Perhaps it still is (@petrasovaa, @landa, @wenzeslaus).

@lindakarlovska lindakarlovska force-pushed the new-jupyter-pane-in-gui branch from be55385 to 817795e Compare June 17, 2025 11:33
@github-actions github-actions bot added GUI wxGUI related Python Related code is in Python libraries docs notebook CMake labels Jun 17, 2025
@lindakarlovska
Copy link
Contributor Author

Just set up the discussion page for the notebook working directory topic and workflows topic in general: #5909.

@lindakarlovska lindakarlovska force-pushed the new-jupyter-pane-in-gui branch from 3a3b7e7 to 55974d3 Compare June 19, 2025 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CMake docs GUI wxGUI related libraries notebook Python Related code is in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant