the scaling issue is from VisPy, removing the previous changes on this subject and adding a patch until the new release of VisPy
This commit is contained in:
@@ -11,7 +11,8 @@ CHANGELOG for FlatCAM beta
|
||||
|
||||
- using PyQt6 with multi monitors, when the pixel ratio (scaling in WIndows) is different than 1.0 there are visual issues in the 3D canvas - trying to solve by updating the dpi - partial solve
|
||||
- failing to load the 3d graphic engine is now reported on the log.txt file found in the Preferences folder (in appData/Roaming/app_name for Windows)
|
||||
- added an example to ilustrate the issue with scaling in Qt6 and VisPy
|
||||
- added an example to illustrate the issue with scaling in Qt6 and VisPy
|
||||
- the scaling issue is from VisPy, removing the previous changes on this subject and adding a patch until the new release of VisPy
|
||||
|
||||
23.08.2021
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ from PyQt6.QtGui import QPalette, QScreen
|
||||
from PyQt6 import QtCore, QtWidgets
|
||||
|
||||
import vispy.scene as scene
|
||||
from vispy.scene.visuals import Rectangle, Text
|
||||
from vispy.color import Color
|
||||
|
||||
import sys
|
||||
@@ -24,6 +23,7 @@ class VisPyCanvas(scene.SceneCanvas):
|
||||
self.central_widget.bgcolor = back_color
|
||||
self.central_widget.border_color = back_color
|
||||
|
||||
# Add a Grid Widget
|
||||
self.grid_widget = self.central_widget.add_grid(margin=10)
|
||||
self.grid_widget.spacing = 0
|
||||
|
||||
@@ -60,6 +60,7 @@ class VisPyCanvas(scene.SceneCanvas):
|
||||
self.xaxis.link_view(self.view)
|
||||
self.yaxis.link_view(self.view)
|
||||
|
||||
# add GridLines
|
||||
self.grid = scene.GridLines(parent=self.view.scene, color='dimgray')
|
||||
self.grid.set_gl_state(depth_test=False)
|
||||
|
||||
@@ -166,8 +167,15 @@ class MyGui(QtWidgets.QMainWindow):
|
||||
:param new_screen: QtGui.QScreen where the app windows is located after move
|
||||
:return:
|
||||
"""
|
||||
old_pixel_ratio = old_screen.devicePixelRatio()
|
||||
new_pixel_ratio = new_screen.devicePixelRatio()
|
||||
try:
|
||||
old_pixel_ratio = old_screen.devicePixelRatio()
|
||||
except AttributeError:
|
||||
return
|
||||
|
||||
try:
|
||||
new_pixel_ratio = new_screen.devicePixelRatio()
|
||||
except AttributeError:
|
||||
return
|
||||
|
||||
if old_pixel_ratio != new_pixel_ratio:
|
||||
# update canvas dpi
|
||||
|
||||
@@ -49,7 +49,7 @@ class MainGUI(QtWidgets.QMainWindow):
|
||||
# Emitted when persistent window geometry needs to be retained
|
||||
geom_update = QtCore.pyqtSignal(int, int, int, int, int, name='geomUpdate')
|
||||
final_save = QtCore.pyqtSignal(name='saveBeforeExit')
|
||||
screenChanged = QtCore.pyqtSignal(QtGui.QScreen, QtGui.QScreen)
|
||||
# screenChanged = QtCore.pyqtSignal(QtGui.QScreen, QtGui.QScreen)
|
||||
|
||||
# https://www.w3.org/TR/SVG11/types.html#ColorKeywords
|
||||
def __init__(self, app):
|
||||
@@ -1988,23 +1988,23 @@ class MainGUI(QtWidgets.QMainWindow):
|
||||
self.infobar.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.ActionsContextMenu)
|
||||
self.build_infobar_context_menu()
|
||||
|
||||
self.screenChanged.connect(self.on_screen_change)
|
||||
# self.screenChanged.connect(self.on_screen_change)
|
||||
|
||||
def on_screen_change(self, old_screen, new_screen):
|
||||
"""
|
||||
Handler of a signal that emits when screens are changed in a multi-monitor setup
|
||||
|
||||
:param old_screen: QtGui.QScreen where the app windows was located before move
|
||||
:param new_screen: QtGui.QScreen where the app windows is located after move
|
||||
:return:
|
||||
"""
|
||||
old_pixel_ratio = old_screen.devicePixelRatio()
|
||||
new_pixel_ratio = new_screen.devicePixelRatio()
|
||||
|
||||
if old_pixel_ratio != 1.0 or new_pixel_ratio != 1.0:
|
||||
# update canvas dpi
|
||||
ratio = new_pixel_ratio / old_pixel_ratio
|
||||
self.app.plotcanvas.dpi = self.app.plotcanvas.dpi * ratio
|
||||
# def on_screen_change(self, old_screen, new_screen):
|
||||
# """
|
||||
# Handler of a signal that emits when screens are changed in a multi-monitor setup
|
||||
#
|
||||
# :param old_screen: QtGui.QScreen where the app windows was located before move
|
||||
# :param new_screen: QtGui.QScreen where the app windows is located after move
|
||||
# :return:
|
||||
# """
|
||||
# old_pixel_ratio = old_screen.devicePixelRatio()
|
||||
# new_pixel_ratio = new_screen.devicePixelRatio()
|
||||
#
|
||||
# if old_pixel_ratio != 1.0 or new_pixel_ratio != 1.0:
|
||||
# # update canvas dpi
|
||||
# ratio = new_pixel_ratio / old_pixel_ratio
|
||||
# self.app.plotcanvas.dpi = self.app.plotcanvas.dpi * ratio
|
||||
|
||||
def set_ui_title(self, name):
|
||||
"""
|
||||
@@ -4237,14 +4237,14 @@ class MainGUI(QtWidgets.QMainWindow):
|
||||
# sys.exit(0)
|
||||
event.ignore()
|
||||
|
||||
def moveEvent(self, event):
|
||||
oldScreen = QtWidgets.QApplication.screenAt(event.oldPos())
|
||||
newScreen = QtWidgets.QApplication.screenAt(event.pos())
|
||||
|
||||
if not oldScreen == newScreen:
|
||||
self.screenChanged.emit(oldScreen, newScreen)
|
||||
|
||||
return super().moveEvent(event)
|
||||
# def moveEvent(self, event):
|
||||
# oldScreen = QtWidgets.QApplication.screenAt(event.oldPos())
|
||||
# newScreen = QtWidgets.QApplication.screenAt(event.pos())
|
||||
#
|
||||
# if not oldScreen == newScreen:
|
||||
# self.screenChanged.emit(oldScreen, newScreen)
|
||||
#
|
||||
# return super().moveEvent(event)
|
||||
|
||||
|
||||
class ShortcutsTab(QtWidgets.QWidget):
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
# ##########################################################
|
||||
|
||||
from vispy.visuals import markers, InfiniteLineVisual
|
||||
from vispy.app.backends._pyqt6 import CanvasBackendDesktop
|
||||
from vispy.visuals.axis import Ticker, _get_ticks_talbot
|
||||
from vispy.scene.widgets import Grid
|
||||
import numpy as np
|
||||
@@ -55,7 +56,7 @@ def apply_patches():
|
||||
Grid._prepare_draw = _prepare_draw
|
||||
Grid._update_clipper = _update_clipper
|
||||
|
||||
# Patch InfiniteLine visual to 1px width
|
||||
# Patch InfiniteLine visual to 1.5px width
|
||||
def _prepare_draw(self, view=None):
|
||||
"""This method is called immediately before each draw.
|
||||
The *view* argument indicates which view is about to be drawn.
|
||||
@@ -72,7 +73,7 @@ def apply_patches():
|
||||
|
||||
if GL:
|
||||
GL.glDisable(GL.GL_LINE_SMOOTH)
|
||||
GL.glLineWidth(2.0)
|
||||
GL.glLineWidth(1.5)
|
||||
|
||||
if self._changed['pos']:
|
||||
self.pos_buf.set_data(self._pos)
|
||||
@@ -139,3 +140,19 @@ def apply_patches():
|
||||
return NotImplementedError
|
||||
|
||||
Ticker._get_tick_frac_labels = _get_tick_frac_labels
|
||||
|
||||
def _resizeGL(self, w, h):
|
||||
if self._vispy_canvas is None:
|
||||
return
|
||||
if hasattr(self, 'devicePixelRatio'):
|
||||
# We take into account devicePixelRatio, which is non-unity on
|
||||
# e.g HiDPI displays.
|
||||
# self.devicePixelRatio() is a float and should have been in Qt5 according to the documentation
|
||||
ratio = self.devicePixelRatio()
|
||||
w = int(w * ratio)
|
||||
h = int(h * ratio)
|
||||
self._vispy_set_physical_size(w, h)
|
||||
self._vispy_canvas.events.resize(size=(self.width(), self.height()),
|
||||
physical_size=(w, h))
|
||||
|
||||
CanvasBackendDesktop.resizeGL = _resizeGL
|
||||
|
||||
Reference in New Issue
Block a user