|
18 | 18 | from io import StringIO, BufferedIOBase |
19 | 19 | from typing import cast, List |
20 | 20 | from . import gx |
21 | | -from PyQt5 import QtGui, QtCore |
| 21 | + |
| 22 | +qt_version = 6 |
| 23 | +try: |
| 24 | + from PyQt6 import QtGui, QtCore |
| 25 | +except ImportError: |
| 26 | + qt_version = 5 |
| 27 | + from PyQt5 import QtGui, QtCore |
22 | 28 |
|
23 | 29 | # Helper function that extracts values from gcode to add to the binary header. |
24 | 30 | def getValue(line, key, default=None): |
@@ -100,15 +106,17 @@ def _createSnapshot(self, g, *args): |
100 | 106 | try: |
101 | 107 | # Convert the image to grayscale, and back to 24bits so it renders properly |
102 | 108 | # in printer. |
| 109 | + qt_format_ctx = QtGui.QImage.Format if qt_version == 6 else QtGui.QImage |
| 110 | + qt_openmode_ctx = QtCore.QIODeviceBase.OpenModeFlag if qt_version == 6 else QtCore.QIODevice |
103 | 111 | img = Snapshot.snapshot(width = 80, height = 60) |
104 | | - img = img.convertToFormat(QtGui.QImage.Format_Grayscale8) |
105 | | - img = img.convertToFormat(QtGui.QImage.Format_RGB666) |
| 112 | + img = img.convertToFormat(qt_format_ctx.Format_Grayscale8) |
| 113 | + img = img.convertToFormat(qt_format_ctx.Format_RGB666) |
106 | 114 | # Converts the image into BMP byte array. |
107 | 115 | arr = QtCore.QByteArray() |
108 | 116 | buff = QtCore.QBuffer(arr) |
109 | | - buff.open(QtCore.QIODevice.WriteOnly) |
| 117 | + buff.open(qt_openmode_ctx.WriteOnly) |
110 | 118 | img.save(buff, format="BMP") |
111 | | - g.bmp = arr.data() |
| 119 | + g.bmp = arr.data() |
112 | 120 | except Exception: |
113 | 121 | Logger.logException("w", "Failed to create snapshot image") |
114 | 122 | g.bmp = gx._SAMPLE_BMP |
0 commit comments