diff --git a/lib/python/qtvcp/widgets/basic_probe.py b/lib/python/qtvcp/widgets/basic_probe.py index 3147e88bf36..d50e14aee31 100644 --- a/lib/python/qtvcp/widgets/basic_probe.py +++ b/lib/python/qtvcp/widgets/basic_probe.py @@ -19,6 +19,7 @@ import os import hal import json +import re from qtpy.QtCore import QProcess, QRegularExpression, QFile, QEvent, Qt, Property from qtpy import QtGui, QtWidgets, uic, QtCore from qtpy.QtWidgets import QDialogButtonBox, QAbstractSlider, QLineEdit, QApplication @@ -613,6 +614,30 @@ def buildWidget(self): except Exception as e: t.setText('Basic Probe Help file Unavailable:\n\n{}'.format(e)) + def _set_scaled_html(self, t, html): + # QTextEdit scales raster images with a nearest-neighbour filter, which + # makes the help diagrams look jagged. Pre-scale each raster to + # its requested size with a smooth filter and register it as a document + # resource so Qt draws it 1:1. SVG images are left untouched so Qt's + # vector renderer draws them crisply at any size. + doc = t.document() + for tag in re.findall(r']*>', html): + match = re.search(r'src="([^"]+)"', tag) + if match is None or match.group(1).lower().endswith('.svg'): + continue + src = match.group(1) + image = QtGui.QImage(src) + if image.isNull(): + continue + width = re.search(r'width="(\d+)"', tag) + height = re.search(r'height="(\d+)"', tag) + if width is not None and int(width.group(1)) != image.width(): + image = image.scaledToWidth(int(width.group(1)), QtCore.Qt.SmoothTransformation) + elif height is not None and int(height.group(1)) != image.height(): + image = image.scaledToHeight(int(height.group(1)), QtCore.Qt.SmoothTransformation) + doc.addResource(QtGui.QTextDocument.ImageResource, QtCore.QUrl(src), image) + t.setHtml(html) + def next(self,t,direction=None): if direction is None: self.currentHelpPage = 0 @@ -631,7 +656,7 @@ def next(self,t,direction=None): html = file.readAll() html = str(html, encoding='utf8') html = html.replace("../images/widgets/","{}/widgets/".format(PATH.IMAGEDIR)) - t.setHtml(html) + self._set_scaled_html(t, html) if t.verticalScrollBar().isVisible(): t.verticalScrollBar().setPageStep(100) self.pageStepDwnbutton.show() diff --git a/lib/python/qtvcp/widgets/versa_probe.py b/lib/python/qtvcp/widgets/versa_probe.py index 88b0054371b..c0f4ca0fb35 100644 --- a/lib/python/qtvcp/widgets/versa_probe.py +++ b/lib/python/qtvcp/widgets/versa_probe.py @@ -19,6 +19,7 @@ import os import hal import json +import re from qtpy import QtGui, QtCore, QtWidgets, uic from qtpy.QtCore import QProcess, QEvent, Qt, Property @@ -687,6 +688,30 @@ def buildWidget(self): except Exception as e: t.setText('Versa Probe Help file Unavailable:\n\n{}'.format(e)) + def _set_scaled_html(self, t, html): + # QTextEdit scales raster images with a nearest-neighbour filter, which + # makes the help diagrams look jagged. Pre-scale each raster to + # its requested size with a smooth filter and register it as a document + # resource so Qt draws it 1:1. SVG images are left untouched so Qt's + # vector renderer draws them crisply at any size. + doc = t.document() + for tag in re.findall(r']*>', html): + match = re.search(r'src="([^"]+)"', tag) + if match is None or match.group(1).lower().endswith('.svg'): + continue + src = match.group(1) + image = QtGui.QImage(src) + if image.isNull(): + continue + width = re.search(r'width="(\d+)"', tag) + height = re.search(r'height="(\d+)"', tag) + if width is not None and int(width.group(1)) != image.width(): + image = image.scaledToWidth(int(width.group(1)), QtCore.Qt.SmoothTransformation) + elif height is not None and int(height.group(1)) != image.height(): + image = image.scaledToHeight(int(height.group(1)), QtCore.Qt.SmoothTransformation) + doc.addResource(QtGui.QTextDocument.ImageResource, QtCore.QUrl(src), image) + t.setHtml(html) + def next(self,t,direction=None): if direction is None: self.currentHelpPage = 0 @@ -704,8 +729,8 @@ def next(self,t,direction=None): file.open(QtCore.QFile.ReadOnly) html = file.readAll() html = str(html, encoding='utf8') - html = html.replace("../images/probe_icons/","{}/probe_icons/".format(PATH.IMAGEDIR)) - t.setHtml(html) + html = html.replace("../images/","{}/".format(PATH.IMAGEDIR)) + self._set_scaled_html(t, html) if t.verticalScrollBar().isVisible(): t.verticalScrollBar().setPageStep(20) self.pageStepDwnbutton.show() diff --git a/share/qtvcp/widgets_ui/basic_help4.html b/share/qtvcp/widgets_ui/basic_help4.html index 035fe395d38..a455fad83f9 100644 --- a/share/qtvcp/widgets_ui/basic_help4.html +++ b/share/qtvcp/widgets_ui/basic_help4.html @@ -1,6 +1,6 @@

Basic Probe Help 4

-
+
diff --git a/share/qtvcp/widgets_ui/basic_help6.html b/share/qtvcp/widgets_ui/basic_help6.html index a012beb5355..0a421ac0b01 100644 --- a/share/qtvcp/widgets_ui/basic_help6.html +++ b/share/qtvcp/widgets_ui/basic_help6.html @@ -1,6 +1,6 @@

Basic Probe Help 6

-
+
diff --git a/share/qtvcp/widgets_ui/basic_help7.html b/share/qtvcp/widgets_ui/basic_help7.html index 2e3a1d8aeca..ecab36d818b 100644 --- a/share/qtvcp/widgets_ui/basic_help7.html +++ b/share/qtvcp/widgets_ui/basic_help7.html @@ -4,7 +4,7 @@

Basic Probe Help 7


-

+

This is a 3d representation of probe starting and finishing points of inside probing.

The probe starting placement is approximately on the intersection of edges.

-

the green cross-hair is the finishing position after probing.

+

The green cross-hair is the finishing position after probing.

diff --git a/share/qtvcp/widgets_ui/basic_help8.html b/share/qtvcp/widgets_ui/basic_help8.html index de64370c26f..da448f8e3af 100644 --- a/share/qtvcp/widgets_ui/basic_help8.html +++ b/share/qtvcp/widgets_ui/basic_help8.html @@ -4,7 +4,7 @@

Basic Probe Help 8 - Example


-

+


Demo of inside corner probing using the top right button in Basic Probe (back_right_inside).

While all probe entries must be correct, the most important settings to change for each probe sequence:

@@ -15,13 +15,13 @@

* EDGE WIDTH -distance along edge wall (away from corner) to start probing.


[NOTE]

-

These distance are always to be set in 'machine units' (mm for metric machine, inch for imprial machine)

+

These distances are always to be set in 'machine units' (mm for metric machine, inch for imperial machine)


Preset:



- +