Skip to content

Commit 6517b51

Browse files
fauenclaude
andcommitted
Hide scrollbars and persist cookies for left panel
Injects CSS to suppress scrollbars on all loaded pages, and uses a persistent QWebEngineProfile for the left view so cookies/session survive restarts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a3605a9 commit 6517b51

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

split-screen/split_screen.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget, QHBoxLayout
66
from PyQt6.QtWebEngineWidgets import QWebEngineView
7-
from PyQt6.QtWebEngineCore import QWebEngineSettings
7+
from PyQt6.QtWebEngineCore import QWebEngineSettings, QWebEngineScript, QWebEngineProfile, QWebEnginePage
88
from PyQt6.QtCore import QUrl, Qt
99
from PyQt6.QtGui import QShortcut, QKeySequence
1010

@@ -24,13 +24,36 @@ def load_config() -> dict:
2424
return json.load(f)
2525

2626

27-
def make_view(url: str) -> QWebEngineView:
27+
NO_SCROLLBAR_CSS = """
28+
(function() {
29+
var style = document.createElement('style');
30+
style.textContent = '::-webkit-scrollbar { display: none; } * { scrollbar-width: none; }';
31+
document.documentElement.appendChild(style);
32+
})();
33+
"""
34+
35+
36+
def _add_no_scrollbar_script(page: QWebEnginePage) -> None:
37+
script = QWebEngineScript()
38+
script.setName("no-scrollbar")
39+
script.setSourceCode(NO_SCROLLBAR_CSS)
40+
script.setInjectionPoint(QWebEngineScript.InjectionPoint.DocumentReady)
41+
script.setWorldId(QWebEngineScript.ScriptWorldId.MainWorld)
42+
script.setRunsOnSubFrames(True)
43+
page.scripts().insert(script)
44+
45+
46+
def make_view(url: str, profile: QWebEngineProfile | None = None) -> QWebEngineView:
2847
view = QWebEngineView()
48+
if profile is not None:
49+
page = QWebEnginePage(profile, view)
50+
view.setPage(page)
2951
settings = view.settings()
3052
settings.setAttribute(QWebEngineSettings.WebAttribute.JavascriptEnabled, True)
3153
settings.setAttribute(QWebEngineSettings.WebAttribute.LocalStorageEnabled, True)
3254
settings.setAttribute(QWebEngineSettings.WebAttribute.FullScreenSupportEnabled, True)
3355
view.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu)
56+
_add_no_scrollbar_script(view.page())
3457
view.load(QUrl(url))
3558
return view
3659

@@ -46,7 +69,14 @@ def __init__(self, left_url: str, right_url: str):
4669
layout.setContentsMargins(0, 0, 0, 0)
4770
layout.setSpacing(0)
4871

49-
layout.addWidget(make_view(left_url), stretch=1)
72+
profile_dir = str(Path(__file__).parent / "profiles" / "left")
73+
left_profile = QWebEngineProfile("left", self)
74+
left_profile.setPersistentStoragePath(profile_dir)
75+
left_profile.setPersistentCookiesPolicy(
76+
QWebEngineProfile.PersistentCookiesPolicy.ForcePersistentCookies
77+
)
78+
79+
layout.addWidget(make_view(left_url, left_profile), stretch=1)
5080
layout.addWidget(make_view(right_url), stretch=1)
5181

5282
QShortcut(QKeySequence("Escape"), self, self.close)

0 commit comments

Comments
 (0)