Compare commits

..

1 Commits

Author SHA1 Message Date
f488106a4c Update WebAppify to the latest tech
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
- Migrate to Hatch
- Migrate to Woodpecker CI
- Migrate to only Python 3
2022-06-10 11:42:03 -07:00
2 changed files with 8 additions and 36 deletions

View File

@ -1,8 +0,0 @@
root = true
[*]
max_line_length = 120
[*.py]
indent_style = space
indent_size = 4

View File

@ -21,7 +21,6 @@ This will create a window with the website, using the icon provided.
If your site needs Flash Player, you'll need the appropriate Flash Player plugin installed system-wide. For QtWebKit If your site needs Flash Player, you'll need the appropriate Flash Player plugin installed system-wide. For QtWebKit
you will need the NPAPI plugin, and for QtWebEngine you will need the PPAPI plugin. you will need the NPAPI plugin, and for QtWebEngine you will need the PPAPI plugin.
""" """
import logging
import sys import sys
import platform import platform
@ -32,25 +31,8 @@ SETTINGS = [
QtWebEngineWidgets.QWebEngineSettings.JavascriptCanAccessClipboard, QtWebEngineWidgets.QWebEngineSettings.JavascriptCanAccessClipboard,
QtWebEngineWidgets.QWebEngineSettings.LocalContentCanAccessRemoteUrls QtWebEngineWidgets.QWebEngineSettings.LocalContentCanAccessRemoteUrls
] ]
LOG_LEVELS = {
QtWebEngineWidgets.QWebEnginePage.InfoMessageLevel: logging.INFO,
QtWebEngineWidgets.QWebEnginePage.WarningMessageLevel: logging.WARNING,
QtWebEngineWidgets.QWebEnginePage.ErrorMessageLevel: logging.ERROR
}
log = logging.getLogger(__name__) # WebView = QtWebEngineWidgets.QWebEngineView
class WebPage(QtWebEngineWidgets.QWebEnginePage):
"""
A custom QWebEnginePage which logs JS console messages to the Python logging system
"""
def javaScriptConsoleMessage(self, level, message, line_number, source_id):
"""
Custom logger to log console messages to the Python logging system
"""
log.log(LOG_LEVELS[level], f'{source_id}:{line_number} {message}')
print(message)
class WebWindow(QtWidgets.QWidget): class WebWindow(QtWidgets.QWidget):
@ -71,8 +53,7 @@ class WebWindow(QtWidgets.QWidget):
self.setContentsMargins(0, 0, 0, 0) self.setContentsMargins(0, 0, 0, 0)
self.layout = QtWidgets.QVBoxLayout(self) self.layout = QtWidgets.QVBoxLayout(self)
self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setContentsMargins(0, 0, 0, 0)
self.webview = QtWebEngineWidgets.QWebEngineView(self) self.webview = WebView(self)
self.webview.setPage(WebPage(self.webview))
for setting in SETTINGS: for setting in SETTINGS:
self.webview.settings().setAttribute(setting, True) self.webview.settings().setAttribute(setting, True)
self.webview.setUrl(QtCore.QUrl(url)) self.webview.setUrl(QtCore.QUrl(url))
@ -83,11 +64,11 @@ class WebWindow(QtWidgets.QWidget):
""" """
Show a balloon message to inform the user that the app is minimized Show a balloon message to inform the user that the app is minimized
""" """
if not self._has_shown_warning: if not self.has_shown_warning:
self.tray_icon.showMessage(self.windowTitle(), 'This program will continue running in the system tray. ' self.tray_icon.showMessage(self.windowTitle(), 'This program will continue running in the system tray. '
'To close the program, choose <b>Quit</b> in the context menu of the system ' 'To close the program, choose <b>Quit</b> in the context menu of the system '
'tray icon.', QtWidgets.QSystemTrayIcon.Information, 5000) 'tray icon.', QtWidgets.QSystemTrayIcon.Information, 5000)
self._has_shown_warning = True self.has_shown_warning = True
def _update_tray_menu(self): def _update_tray_menu(self):
""" """
@ -121,11 +102,11 @@ class WebWindow(QtWidgets.QWidget):
""" """
# Create the actions for the menu # Create the actions for the menu
self.restore_action = QtWidgets.QAction('&Restore', self) self.restore_action = QtWidgets.QAction('&Restore', self)
self.restore_action.triggered.connect(self._restore_window) self.restore_action.triggered.connect(self._restoreWindow)
self.minimize_action = QtWidgets.QAction('Mi&nimize', self) self.minimize_action = QtWidgets.QAction('Mi&nimize', self)
self.minimize_action.triggered.connect(self.close) self.minimize_action.triggered.connect(self.close)
self.maximize_action = QtWidgets.QAction('Ma&ximize', self) self.maximize_action = QtWidgets.QAction('Ma&ximize', self)
self.maximize_action.triggered.connect(self._maximize_window) self.maximize_action.triggered.connect(self._maximizeWindow)
self.quit_action = QtWidgets.QAction('&Quit', self) self.quit_action = QtWidgets.QAction('&Quit', self)
self.quit_action.triggered.connect(self.app.quit) self.quit_action.triggered.connect(self.app.quit)
# Create the menu and add the actions # Create the menu and add the actions
@ -211,7 +192,7 @@ class WebApp(QtWidgets.QApplication):
""" """
A generic application to open a web page in a desktop app A generic application to open a web page in a desktop app
""" """
def __init__(self, title, url, icon, can_minimize_to_tray=False, canMinimizeToTray=False): def __init__(self, title, url, icon, canMinimizeToTray=False):
""" """
Create an application which loads a URL into a window Create an application which loads a URL into a window
""" """
@ -221,8 +202,7 @@ class WebApp(QtWidgets.QApplication):
self.title = title self.title = title
self.url = url self.url = url
self.icon = icon self.icon = icon
self.can_minimize_to_tray = QtWidgets.QSystemTrayIcon.isSystemTrayAvailable() and \ self.can_minimize_to_tray = QtWidgets.QSystemTrayIcon.isSystemTrayAvailable() and can_minimize_to_tray
(can_minimize_to_tray or canMinimizeToTray)
if self.can_minimize_to_tray: if self.can_minimize_to_tray:
self.setQuitOnLastWindowClosed(False) self.setQuitOnLastWindowClosed(False)
self.setWindowIcon(QtGui.QIcon(self.icon)) self.setWindowIcon(QtGui.QIcon(self.icon))