Skip to content

Commit 8be7fab

Browse files
author
lindakladivova
committed
type notations and smaller refactoring, creating some global variables
1 parent e8d3c9a commit 8be7fab

File tree

10 files changed

+256
-153
lines changed

10 files changed

+256
-153
lines changed

gui/wxpython/jupyter_notebook/dialogs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
from pathlib import Path
1818
import wx
1919

20-
from .utils import get_project_jupyter_storage
21-
from .storage import WELCOME_NOTEBOOK_NAME
20+
from .storage import WELCOME_NOTEBOOK_NAME, get_project_jupyter_storage
2221

2322

2423
class JupyterStartDialog(wx.Dialog):

gui/wxpython/jupyter_notebook/environment.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,50 +22,63 @@
2222

2323

2424
class JupyterEnvironment:
25-
"""Orchestrates storage manager and Jupyter server lifecycle.
25+
"""Orchestrates storage manager and Jupyter server lifecycle."""
2626

27-
:param storage: Storage for notebooks
28-
:param create_template: Whether to create template notebooks
29-
"""
27+
def __init__(self, storage: Path | None, create_template: bool) -> None:
28+
"""Initialize Jupyter environment.
3029
31-
def __init__(self, storage, create_template):
30+
:param storage: Storage path for notebooks
31+
:param create_template: Whether to create template notebooks
32+
"""
3233
self.storage_manager = JupyterStorageManager(storage, create_template)
3334
self.server = JupyterServerInstance(storage)
3435

35-
def setup(self):
36+
def setup(self) -> None:
3637
"""Prepare files and start server."""
3738
# Prepare files
3839
self.storage_manager.prepare_files()
3940

4041
# Start server
4142
self.server.start_server()
4243

43-
def stop(self):
44+
def stop(self) -> None:
4445
"""Stop server and unregister it."""
4546
self.server.stop_server()
4647
JupyterServerRegistry.get().unregister(self.server)
4748

4849
@classmethod
49-
def stop_all(cls):
50+
def stop_all(cls) -> None:
5051
"""Stop all running Jupyter servers and unregister them."""
5152
JupyterServerRegistry.get().stop_all_servers()
5253

5354
@property
54-
def server_url(self):
55-
"""Get server URL."""
55+
def server_url(self) -> str | None:
56+
"""Get server URL.
57+
58+
:return: Server URL or None if server is not available
59+
"""
5660
return self.server.server_url if self.server else None
5761

5862
@property
59-
def pid(self):
60-
"""Get server process ID."""
63+
def pid(self) -> int | None:
64+
"""Get server process ID.
65+
66+
:return: Process ID or None if server is not running
67+
"""
6168
return self.server.pid if self.server else None
6269

6370
@property
64-
def storage(self):
65-
"""Get Jupyter notebook storage."""
71+
def storage(self) -> Path | None:
72+
"""Get Jupyter notebook storage path.
73+
74+
:return: Storage path or None if storage manager is not available
75+
"""
6676
return self.storage_manager.storage if self.storage_manager else None
6777

6878
@property
6979
def files(self) -> list[Path]:
70-
"""Return list of notebook files."""
80+
"""Return list of notebook files.
81+
82+
:return: List of notebook file paths
83+
"""
7184
return self.storage_manager.files if self.storage_manager else []

gui/wxpython/jupyter_notebook/frame.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,26 @@ class JupyterFrame(wx.Frame):
3030

3131
def __init__(
3232
self,
33-
parent,
33+
parent: wx.Window,
3434
giface,
35-
action="integrated",
36-
storage=None,
37-
create_template=False,
38-
id=wx.ID_ANY,
39-
title=_("Jupyter Notebook"),
35+
action: str = "integrated",
36+
storage: Path | None = None,
37+
create_template: bool = False,
38+
id: int = wx.ID_ANY,
39+
title: str = _("Jupyter Notebook"),
4040
**kwargs,
41-
):
41+
) -> None:
42+
"""Initialize Jupyter frame.
43+
44+
:param parent: Parent window
45+
:param giface: GRASS interface
46+
:param action: Mode - "integrated" or "browser"
47+
:param storage: Storage path for notebooks
48+
:param create_template: Whether to create template notebooks
49+
:param id: Window ID
50+
:param title: Frame title
51+
:param kwargs: Additional arguments passed to wx.Frame
52+
"""
4253
super().__init__(parent=parent, id=id, title=title, **kwargs)
4354

4455
self.SetName("JupyterFrame")
@@ -110,7 +121,8 @@ def __init__(
110121

111122
self._layout()
112123

113-
def _layout(self):
124+
def _layout(self) -> None:
125+
"""Setup frame layout and size."""
114126
if self.panel:
115127
sizer = wx.BoxSizer(wx.VERTICAL)
116128
sizer.Add(self.panel, 1, wx.EXPAND)
@@ -120,7 +132,11 @@ def _layout(self):
120132

121133
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
122134

123-
def OnCloseWindow(self, event):
135+
def OnCloseWindow(self, event: wx.CloseEvent) -> None:
136+
"""Handle window close event.
137+
138+
:param event: Close event
139+
"""
124140
if self.panel and hasattr(self.panel, "OnCloseWindow"):
125141
self.panel.OnCloseWindow(event)
126142

gui/wxpython/jupyter_notebook/notebook.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ class JupyterAuiNotebook(aui.AuiNotebook):
3939

4040
def __init__(
4141
self,
42-
parent,
43-
agwStyle=aui.AUI_NB_DEFAULT_STYLE
42+
parent: wx.Window,
43+
agwStyle: int = aui.AUI_NB_DEFAULT_STYLE
4444
| aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
4545
| aui.AUI_NB_TAB_EXTERNAL_MOVE
4646
| aui.AUI_NB_BOTTOM
4747
| wx.NO_BORDER,
48-
):
49-
"""
50-
Wrapper for the notebook widget that manages notebook pages.
48+
) -> None:
49+
"""Initialize AUI notebook for Jupyter with WebView tabs.
5150
51+
:param parent: Parent window
52+
:param agwStyle: AUI notebook style flags
5253
:raises ImportError: If wx.html2 is not available
5354
"""
54-
5555
if not WX_HTML2_AVAILABLE:
5656
msg = "wx.html2 is not available"
5757
raise ImportError(msg)
@@ -64,9 +64,8 @@ def __init__(
6464

6565
self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnPageClose)
6666

67-
def _hide_top_ui(self, event):
68-
"""
69-
Inject CSS via JS into the Jupyter page to hide top UI elements.
67+
def _hide_top_ui(self, event: html.WebViewEvent) -> None:
68+
"""Inject CSS via JS into the Jupyter page to hide top UI elements.
7069
7170
Works for both:
7271
- Jupyter Notebook 6 and older (classic interface)
@@ -76,6 +75,8 @@ def _hide_top_ui(self, event):
7675
Some UI elements may be created dynamically after page load,
7776
so the script ensures the CSS/JS is applied once elements exist.
7877
Duplicate injection is prevented by checking for a unique style ID.
78+
79+
:param event: WebView loaded event
7980
"""
8081
webview = event.GetEventObject()
8182

@@ -112,21 +113,23 @@ def _hide_top_ui(self, event):
112113

113114
webview.RunScript(js)
114115

115-
def AddPage(self, url, title):
116-
"""
117-
Add a new aui notebook page with a Jupyter WebView.
118-
:param url: URL of the Jupyter file (str).
119-
:param title: Tab title (str).
116+
def AddPage(self, url: str, title: str) -> None:
117+
"""Add a new AUI notebook page with a Jupyter WebView.
120118
119+
:param url: URL of the Jupyter file
120+
:param title: Tab title
121121
:raises NotImplementedError: If wx.html2.WebView is not functional on this system
122122
"""
123123
browser = html.WebView.New(self)
124124
wx.CallAfter(browser.LoadURL, url)
125125
wx.CallAfter(browser.Bind, html.EVT_WEBVIEW_LOADED, self._hide_top_ui)
126126
super().AddPage(browser, title)
127127

128-
def OnPageClose(self, event):
129-
"""Close the aui notebook page with confirmation dialog."""
128+
def OnPageClose(self, event: aui.AuiNotebookEvent) -> None:
129+
"""Close the AUI notebook page with confirmation dialog.
130+
131+
:param event: Notebook page close event
132+
"""
130133
index = event.GetSelection()
131134
title = self.GetPageText(index)
132135

0 commit comments

Comments
 (0)