Skip to content

Commit

Permalink
Merge pull request #3 from MarcinOrlowski/dev
Browse files Browse the repository at this point in the history
Relase 1.2.0
  • Loading branch information
MarcinOrlowski authored Oct 11, 2024
2 parents 7e0daab + 9686c33 commit ec111c1
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*.bak
*.swp

/*.sh



# Linters
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 19 additions & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
4 changes: 2 additions & 2 deletions websiteapp/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

class Version(Enum):
MAJOR = 1
MINOR = 1
PATCH = 1
MINOR = 2
PATCH = 0

@classmethod
def as_string(cls) -> str:
Expand Down
2 changes: 2 additions & 0 deletions websiteapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
42 changes: 30 additions & 12 deletions websiteapp/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -64,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(
Expand All @@ -72,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))

Expand Down Expand Up @@ -212,16 +224,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:
Expand Down Expand Up @@ -259,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()

0 comments on commit ec111c1

Please sign in to comment.