From 5426eb6471c55b64422f5bf77f05768e96b78240 Mon Sep 17 00:00:00 2001 From: Marcin Orlowski Date: Tue, 8 Oct 2024 22:48:56 +0200 Subject: [PATCH 1/7] Added --version switch --- websiteapp/utils.py | 2 ++ websiteapp/webapp.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/websiteapp/utils.py b/websiteapp/utils.py index 1e9c50f..40ada02 100644 --- a/websiteapp/utils.py +++ b/websiteapp/utils.py @@ -102,6 +102,8 @@ def handle_args(): help='Starts app minimized to system tray.') parser.add_argument('--allow-multiple', '-a', action='store_true', help='Allows multiple instances of the app to run on the same profile') + parser.add_argument('--version', '-v', action='store_true', + help='Prints the version of the app and exits') parser.add_argument('--debug', '-d', action='store_true', help='Makes app print more debug messages during execution') diff --git a/websiteapp/webapp.py b/websiteapp/webapp.py index b7cf481..6a2e9e3 100644 --- a/websiteapp/webapp.py +++ b/websiteapp/webapp.py @@ -36,6 +36,11 @@ class WebApp(QMainWindow): def __init__(self): super().__init__() + # Check for --version before full argument parsing + if '--version' in sys.argv: + print(f'{Const.APP_NAME} {Const.APP_VERSION}') + sys.exit(0) + self.app = QApplication.instance() self.args = Utils.handle_args() From 1e05d65429a8dd3a4dc66b07b5341da9cf10e66b Mon Sep 17 00:00:00 2001 From: Marcin Orlowski Date: Tue, 8 Oct 2024 22:49:13 +0200 Subject: [PATCH 2/7] Removed dead code --- websiteapp/webapp.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/websiteapp/webapp.py b/websiteapp/webapp.py index 6a2e9e3..2c0da70 100644 --- a/websiteapp/webapp.py +++ b/websiteapp/webapp.py @@ -217,16 +217,6 @@ def toggle_window(self) -> None: """ self.hide() if self.isVisible() else self.show() - - # def on_tray_icon_activated(self, reason): - # if reason == QSystemTrayIcon.ActivationReason.Trigger: - # if self.isVisible(): - # self.hide() - # else: - # self.show() - # self.activateWindow() - - # ############################################################################################ # def dbug(self, msg: str) -> None: From 44ba4372422ebb472765dae9e8b4465fa29913c7 Mon Sep 17 00:00:00 2001 From: Marcin Orlowski Date: Tue, 8 Oct 2024 22:49:29 +0200 Subject: [PATCH 3/7] Added support for file downloads --- websiteapp/webapp.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/websiteapp/webapp.py b/websiteapp/webapp.py index 2c0da70..eaf3caa 100644 --- a/websiteapp/webapp.py +++ b/websiteapp/webapp.py @@ -16,12 +16,12 @@ from typing import Optional import fasteners -from PySide6.QtCore import QUrl, QFileSystemWatcher +from PySide6.QtCore import QUrl, QFileSystemWatcher, QStandardPaths, Qt from PySide6.QtGui import QAction from PySide6.QtWebEngineCore import QWebEngineProfile, QWebEnginePage, QWebEngineSettings from PySide6.QtWebEngineWidgets import QWebEngineView from PySide6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QSystemTrayIcon, \ - QMenu + QMenu, QFileDialog from websiteapp.about import About from websiteapp.const import Const @@ -69,6 +69,9 @@ def __init__(self): self.profile = QWebEngineProfile(self.args.profile, self) self.page = QWebEnginePage(self.profile, self) + # Handle downloads + self.profile.downloadRequested.connect(self.on_download_requested) + self.browser = QWebEngineView(self) web_settings = self.browser.settings() web_settings.setAttribute( @@ -77,6 +80,10 @@ def __init__(self): self.browser.setPage(self.page) self.browser.setZoomFactor(self.args.zoom) + # Ensure the browser widget can receive focus and key events + self.browser.setFocusPolicy(Qt.StrongFocus) + self.browser.setFocus() + self.dbug(f'URL: {self.args.url}') self.browser.setUrl(QUrl(self.args.url)) @@ -254,3 +261,19 @@ def run() -> None: window.lock = None sys.exit(exit_code) + + def on_download_requested(self, download): + """ + Handles file download requests from the web page. + """ + print('on_download_requested') + # Prompt the user to select a download location + suggested_filename = download.downloadFileName() + options = QFileDialog.Options() + path, _ = QFileDialog.getSaveFileName(self, "Save File", suggested_filename, options=options) + if path: + download.setDownloadFileName(os.path.basename(path)) + download.setDownloadDirectory(os.path.dirname(path)) + download.accept() + else: + download.cancel() From 32b0c9255c2266fde323406a8a9591262d00b839 Mon Sep 17 00:00:00 2001 From: Marcin Orlowski Date: Tue, 8 Oct 2024 22:50:24 +0200 Subject: [PATCH 4/7] Reworded docs --- README.md | 28 +++++++++++++++++++--------- docs/README.md | 28 +++++++++++++++++++--------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 3281dc8..d2fba61 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,25 @@ Run any website as standalone desktop application --- -Small Python script opening any web page in dedicated window, using embedded QT WebEngine. There are -no visible browser's UI etc., so the that can be useful to turn any website into standalone desktop -application. This is useful if you, as me, would like to have a website run as standalone app, -independently of your main browser which can be beneficial as it gives you separate entry in -window manager or task switcher etc. - -> **IMPORTANT:** This tool is **NOT** turning websites into OFFLINE apps! It's about separating -> each of your key websites i.e. from each other, or gazzilions of your browser's tabs. But you -> still MUST be connected to the Internet for the apps (websites) to work as previously. +This Python script offers a unique approach to web browsing by opening any webpage in a dedicated +window using the embedded QT WebEngine. By removing the typical browser UI elements, it effectively +turns websites into standalone desktop applications. This can be particularly useful if you've ever +wished to run a frequently used website as a separate app, independent from your main browser. + +The tool provides a practical solution for those who find themselves juggling numerous browser tabs +or wanting a clearer separation between work and personal web applications. With each website +running as its own "app", you gain the benefit of individual entries in your window manager or task +switcher, potentially improving your workflow organization and efficiency. + +Whether you're looking to streamline your digital workspace or simply curious about alternative +ways to interact with web content, this script presents an interesting concept that might just +solve a problem you didn't know you had. + +**IMPORTANT:** It's worth pointing out however, that this tool doesn't transform websites into +offline applications. Rather, it focuses on separating your key websites from each other and from +the multitude of browser tabs you might typically have open. While this approach offers improved +organization and workflow, it's crucial to understand that an internet connection is still required +for these "apps" (websites) to function as they normally would in a traditional browser environment. ## Installation diff --git a/docs/README.md b/docs/README.md index b21ed5d..f34965c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,15 +6,25 @@ Run any website as standalone desktop application --- -Small Python script opening any web page in dedicated window, using embedded QT WebEngine. There are -no visible browser's UI etc., so the that can be useful to turn any website into standalone desktop -application. This is useful if you, as me, would like to have a website run as standalone app, -independently of your main browser which can be beneficial as it gives you separate entry in -window manager or task switcher etc. - -> **IMPORTANT:** This tool is **NOT** turning websites into OFFLINE apps! It's about separating -> each of your key websites i.e. from each other, or gazzilions of your browser's tabs. But you -> still MUST be connected to the Internet for the apps (websites) to work as previously. +This Python script offers a unique approach to web browsing by opening any webpage in a dedicated +window using the embedded QT WebEngine. By removing the typical browser UI elements, it effectively +turns websites into standalone desktop applications. This can be particularly useful if you've ever +wished to run a frequently used website as a separate app, independent from your main browser. + +The tool provides a practical solution for those who find themselves juggling numerous browser tabs +or wanting a clearer separation between work and personal web applications. With each website +running as its own "app", you gain the benefit of individual entries in your window manager or task +switcher, potentially improving your workflow organization and efficiency. + +Whether you're looking to streamline your digital workspace or simply curious about alternative +ways to interact with web content, this script presents an interesting concept that might just +solve a problem you didn't know you had. + +**IMPORTANT:** It's worth pointing out however, that this tool doesn't transform websites into +offline applications. Rather, it focuses on separating your key websites from each other and from +the multitude of browser tabs you might typically have open. While this approach offers improved +organization and workflow, it's crucial to understand that an internet connection is still required +for these "apps" (websites) to function as they normally would in a traditional browser environment. --- From 0dd412886b0135f94d54a86f637a174894109644 Mon Sep 17 00:00:00 2001 From: Marcin Orlowski Date: Tue, 8 Oct 2024 22:50:38 +0200 Subject: [PATCH 5/7] Changes logged --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 914fdd2..78a31ed 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,10 @@ --- +* 1.2.0-dev (2024-10-09) + * Added support for downloading files. + * Added `--version` switch. + * 1.1.1 (2024-10-06) * Fixed setup script missing runtime dependency. From a2506ce4c914360ad69d02fdfa95baef2eda320b Mon Sep 17 00:00:00 2001 From: Marcin Orlowski Date: Tue, 8 Oct 2024 22:50:58 +0200 Subject: [PATCH 6/7] Version bump --- websiteapp/const.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/websiteapp/const.py b/websiteapp/const.py index ad41d46..7429585 100644 --- a/websiteapp/const.py +++ b/websiteapp/const.py @@ -18,8 +18,8 @@ class Version(Enum): MAJOR = 1 - MINOR = 1 - PATCH = 1 + MINOR = 2 + PATCH = 0 @classmethod def as_string(cls) -> str: From 9686c339b587522eed704958e540c7411f09d536 Mon Sep 17 00:00:00 2001 From: Marcin Orlowski Date: Tue, 8 Oct 2024 22:52:09 +0200 Subject: [PATCH 7/7] Updated .gitignore file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 1ea574d..e3ac576 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ *.bak *.swp +/*.sh + # Linters