Skip to content

Commit

Permalink
qtdraon/hd -don't crash if qtwebengine libraries are not present.
Browse files Browse the repository at this point in the history
  • Loading branch information
c-morley committed Jul 16, 2023
1 parent 14e29f4 commit c4e9429
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 54 deletions.
71 changes: 44 additions & 27 deletions share/qtvcp/screens/qtdragon/qtdragon_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os, time
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWebEngineWidgets import QWebEnginePage
from qtvcp.widgets.gcode_editor import GcodeEditor as GCODE
from qtvcp.widgets.mdi_line import MDILine as MDI_WIDGET
from qtvcp.widgets.tool_offsetview import ToolOffsetView as TOOL_TABLE
Expand All @@ -26,6 +25,11 @@
WRITER = writer.Main()
QHAL = Qhal()

try:
from PyQt5.QtWebEngineWidgets import QWebEnginePage
except:
LOG.warning('QtDragon Warning with loading QtWebEngineWidget - is python3-pyqt5.qtwebengine installed?')

# constants for tab pages
TAB_MAIN = 0
TAB_FILE = 1
Expand Down Expand Up @@ -975,12 +979,14 @@ def load_code(self, fname):

# adjust ending to check for related HTML setup files
fname = filename+'.html'
if os.path.exists(fname):
self.w.web_view.load(QtCore.QUrl.fromLocalFile(fname))
self.add_status("Loaded HTML file : {}".format(fname), CRITICAL)
else:
self.w.web_view.setHtml(self.html)

try:
if os.path.exists(fname):
self.w.web_view.load(QtCore.QUrl.fromLocalFile(fname))
self.add_status("Loaded HTML file : {}".format(fname), CRITICAL)
else:
self.w.web_view.setHtml(self.html)
except Exception as e:
self.add_status("Error loading HTML file {} : {}".format(fname,e))
# look for PDF setup files
# load it with system program
fname = filename+'.pdf'
Expand All @@ -1003,7 +1009,7 @@ def load_code(self, fname):
self.w.btn_setup.setChecked(True)
self.w.jogging_frame.hide()
except Exception as e:
print("Error loading HTML file : {}".format(e))
self.add_status("Error loading HTML file {} : {}".format(fname,e))
else:
if os.path.exists(fname):
self.PDFView.loadView(fname)
Expand Down Expand Up @@ -1203,39 +1209,50 @@ def stop_timer(self):

# go directly the default HTML page
def homeWeb(self):
if os.path.exists(self.default_setup):
self.w.web_view.load(QtCore.QUrl.fromLocalFile(self.default_setup))
else:
self.w.web_view.setHtml(self.html)

# setup tab's web page back button
def back(self):
try:
self.w.web_view.page().triggerAction(QWebEnginePage.Back)
except:
if os.path.exists(self.default_setup):
self.w.web_view.load(QtCore.QUrl.fromLocalFile(self.default_setup))
else:
self.w.web_view.setHtml(self.html)
except:
pass
# setup tab's web page back button
def back(self):
try:
try:
self.w.web_view.page().triggerAction(QWebEnginePage.Back)
except:
if os.path.exists(self.default_setup):
self.w.web_view.load(QtCore.QUrl.fromLocalFile(self.default_setup))
else:
self.w.web_view.setHtml(self.html)
except:
pass

# setup tab's web page forward button
def forward(self):
try:
self.w.web_view.page().triggerAction(QWebEnginePage.Forward)
try:
self.w.web_view.page().triggerAction(QWebEnginePage.Forward)
except:
self.w.web_view.load(QtCore.QUrl.fromLocalFile(self.docs))
except:
self.w.web_view.load(QtCore.QUrl.fromLocalFile(self.docs))
pass

# setup tab's web page - enable/disable buttons
def onLoadFinished(self):
if self.w.web_view.history().canGoBack():
self.backBtn.setEnabled(True)
else:
self.backBtn.setEnabled(False)
try:
if self.w.web_view.history().canGoBack():
self.backBtn.setEnabled(True)
else:
self.backBtn.setEnabled(False)

if self.w.web_view.history().canGoForward():
self.forBtn.setEnabled(True)
else:
self.forBtn.setEnabled(False)
if self.w.web_view.history().canGoForward():
self.forBtn.setEnabled(True)
else:
self.forBtn.setEnabled(False)
except:
pass

def writer(self):
WRITER.show()
Expand Down
71 changes: 44 additions & 27 deletions share/qtvcp/screens/qtdragon_hd/qtdragon_hd_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os, time
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWebEngineWidgets import QWebEnginePage
from qtvcp.widgets.gcode_editor import GcodeEditor as GCODE
from qtvcp.widgets.mdi_line import MDILine as MDI_WIDGET
from qtvcp.widgets.tool_offsetview import ToolOffsetView as TOOL_TABLE
Expand Down Expand Up @@ -30,6 +29,11 @@
WRITER = writer.Main()
QHAL = Qhal()

try:
from PyQt5.QtWebEngineWidgets import QWebEnginePage
except:
LOG.warning('QtDragon warning with loading QtWebEngineWidget - is python3-pyqt5.qtwebengine installed?')

# constants for tab pages
# probe is not actually a separate tab now
# but there is a button for showing it in stack
Expand Down Expand Up @@ -1042,12 +1046,14 @@ def load_code(self, fname):

# adjust ending to check for related HTML setup files
fname = filename+'.html'
if os.path.exists(fname):
self.w.web_view.load(QtCore.QUrl.fromLocalFile(fname))
self.add_status("Loaded HTML file : {}".format(fname))
else:
self.w.web_view.setHtml(self.html)

try:
if os.path.exists(fname):
self.w.web_view.load(QtCore.QUrl.fromLocalFile(fname))
self.add_status("Loaded HTML file : {}".format(fname))
else:
self.w.web_view.setHtml(self.html)
except Exception as e:
self.add_status("Can not Load HTML file {} :()".format(fname,e))
# look for PDF setup files
fname = filename+'.pdf'
if os.path.exists(fname):
Expand All @@ -1065,7 +1071,7 @@ def load_code(self, fname):
self.w.stackedWidget.setCurrentIndex(0)
self.w.btn_setup.setChecked(True)
except Exception as e:
print("Error loading HTML file : {}".format(e))
self.add_status("Error loading HTML file {} : {}".format(fname,e))
else:
# load PDF into setup page
if os.path.exists(fname):
Expand Down Expand Up @@ -1246,39 +1252,50 @@ def stop_timer(self):

# go directly the default HTML page
def homeWeb(self):
if os.path.exists(self.default_setup):
self.w.web_view.load(QtCore.QUrl.fromLocalFile(self.default_setup))
else:
self.w.web_view.setHtml(self.html)

# setup tab's web page back button
def back(self):
try:
self.w.web_view.page().triggerAction(QWebEnginePage.Back)
except:
if os.path.exists(self.default_setup):
self.w.web_view.load(QtCore.QUrl.fromLocalFile(self.default_setup))
else:
self.w.web_view.setHtml(self.html)
except:
pass
# setup tab's web page back button
def back(self):
try:
try:
self.w.web_view.page().triggerAction(QWebEnginePage.Back)
except:
if os.path.exists(self.default_setup):
self.w.web_view.load(QtCore.QUrl.fromLocalFile(self.default_setup))
else:
self.w.web_view.setHtml(self.html)
except:
pass

# setup tab's web page forward button
def forward(self):
try:
self.w.web_view.page().triggerAction(QWebEnginePage.Forward)
try:
self.w.web_view.page().triggerAction(QWebEnginePage.Forward)
except:
self.w.web_view.load(QtCore.QUrl.fromLocalFile(self.docs))
except:
self.w.web_view.load(QtCore.QUrl.fromLocalFile(self.docs))
pass

# setup tab's web page - enable/disable buttons
def onLoadFinished(self):
if self.w.web_view.history().canGoBack():
self.backBtn.setEnabled(True)
else:
self.backBtn.setEnabled(False)
try:
if self.w.web_view.history().canGoBack():
self.backBtn.setEnabled(True)
else:
self.backBtn.setEnabled(False)

if self.w.web_view.history().canGoForward():
self.forBtn.setEnabled(True)
else:
self.forBtn.setEnabled(False)
if self.w.web_view.history().canGoForward():
self.forBtn.setEnabled(True)
else:
self.forBtn.setEnabled(False)
except:
pass

def writer(self):
WRITER.show()
Expand Down

0 comments on commit c4e9429

Please sign in to comment.