Compare commits
1 Commits
1471b73403
...
f488106a4c
Author | SHA1 | Date | |
---|---|---|---|
f488106a4c |
@ -1,8 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
max_line_length = 120
|
||||
|
||||
[*.py]
|
||||
indent_style = space
|
||||
indent_size = 4
|
@ -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
|
||||
you will need the NPAPI plugin, and for QtWebEngine you will need the PPAPI plugin.
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
import platform
|
||||
|
||||
@ -32,25 +31,8 @@ SETTINGS = [
|
||||
QtWebEngineWidgets.QWebEngineSettings.JavascriptCanAccessClipboard,
|
||||
QtWebEngineWidgets.QWebEngineSettings.LocalContentCanAccessRemoteUrls
|
||||
]
|
||||
LOG_LEVELS = {
|
||||
QtWebEngineWidgets.QWebEnginePage.InfoMessageLevel: logging.INFO,
|
||||
QtWebEngineWidgets.QWebEnginePage.WarningMessageLevel: logging.WARNING,
|
||||
QtWebEngineWidgets.QWebEnginePage.ErrorMessageLevel: logging.ERROR
|
||||
}
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
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)
|
||||
# WebView = QtWebEngineWidgets.QWebEngineView
|
||||
|
||||
|
||||
class WebWindow(QtWidgets.QWidget):
|
||||
@ -71,8 +53,7 @@ class WebWindow(QtWidgets.QWidget):
|
||||
self.setContentsMargins(0, 0, 0, 0)
|
||||
self.layout = QtWidgets.QVBoxLayout(self)
|
||||
self.layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.webview = QtWebEngineWidgets.QWebEngineView(self)
|
||||
self.webview.setPage(WebPage(self.webview))
|
||||
self.webview = WebView(self)
|
||||
for setting in SETTINGS:
|
||||
self.webview.settings().setAttribute(setting, True)
|
||||
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
|
||||
"""
|
||||
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. '
|
||||
'To close the program, choose <b>Quit</b> in the context menu of the system '
|
||||
'tray icon.', QtWidgets.QSystemTrayIcon.Information, 5000)
|
||||
self._has_shown_warning = True
|
||||
self.has_shown_warning = True
|
||||
|
||||
def _update_tray_menu(self):
|
||||
"""
|
||||
@ -121,11 +102,11 @@ class WebWindow(QtWidgets.QWidget):
|
||||
"""
|
||||
# Create the actions for the menu
|
||||
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.triggered.connect(self.close)
|
||||
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.triggered.connect(self.app.quit)
|
||||
# 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
|
||||
"""
|
||||
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
|
||||
"""
|
||||
@ -221,8 +202,7 @@ class WebApp(QtWidgets.QApplication):
|
||||
self.title = title
|
||||
self.url = url
|
||||
self.icon = icon
|
||||
self.can_minimize_to_tray = QtWidgets.QSystemTrayIcon.isSystemTrayAvailable() and \
|
||||
(can_minimize_to_tray or canMinimizeToTray)
|
||||
self.can_minimize_to_tray = QtWidgets.QSystemTrayIcon.isSystemTrayAvailable() and can_minimize_to_tray
|
||||
if self.can_minimize_to_tray:
|
||||
self.setQuitOnLastWindowClosed(False)
|
||||
self.setWindowIcon(QtGui.QIcon(self.icon))
|
||||
|
Loading…
Reference in New Issue
Block a user