Javascript console messages are logged by the PyQt wrapper app.

master
Pacman Ghost 6 years ago
parent 2ae8dd1589
commit d54da64fa5
  1. 16
      vasl_templates/main_window.py

@ -1,6 +1,7 @@
""" Main application window. """ """ Main application window. """
import os import os
import re
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QFileDialog, QMessageBox from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QFileDialog, QMessageBox
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile, QWebEnginePage from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile, QWebEnginePage
@ -11,6 +12,8 @@ from PyQt5.QtCore import QObject, QUrl, pyqtSlot
from vasl_templates.webapp.config.constants import APP_NAME from vasl_templates.webapp.config.constants import APP_NAME
from vasl_templates.webapp import app as webapp from vasl_templates.webapp import app as webapp
_CONSOLE_SOURCE_REGEX = re.compile( r"^http://.+?/static/(.*)$" )
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
class WebChannelHandler( QObject ): class WebChannelHandler( QObject ):
@ -30,6 +33,17 @@ class WebChannelHandler( QObject ):
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
class AppWebPage( QWebEnginePage ):
"""Main webapp page."""
def javaScriptConsoleMessage( self, level, msg, line_no, source_id ): #pylint: disable=unused-argument,no-self-use
"""Log a Javascript console message."""
mo = _CONSOLE_SOURCE_REGEX.search( source_id )
source = mo.group(1) if mo else source_id
print( "{}:{} - {}".format( source, line_no, msg ) )
# ---------------------------------------------------------------------
class MainWindow( QWidget ): class MainWindow( QWidget ):
"""Main application window.""" """Main application window."""
@ -65,7 +79,7 @@ class MainWindow( QWidget ):
# nb: we create an off-the-record profile to stop the view from using cached JS files :-/ # nb: we create an off-the-record profile to stop the view from using cached JS files :-/
profile = QWebEngineProfile( None, self.view ) profile = QWebEngineProfile( None, self.view )
profile.downloadRequested.connect( self.onDownloadRequested ) profile.downloadRequested.connect( self.onDownloadRequested )
page = QWebEnginePage( profile, self.view ) page = AppWebPage( profile, self.view )
self.view.setPage( page ) self.view.setPage( page )
# create a web channel to communicate with the front-end # create a web channel to communicate with the front-end

Loading…
Cancel
Save