mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-13 17:57:55 -06:00
Printer output device can now have a QML item
This contributes to CURA-3826. This will allow printer output devices to add custom UI elements to the monitor tab in the future.
This commit is contained in:
parent
71bb3c3a22
commit
5dbee706a7
1 changed files with 37 additions and 1 deletions
|
@ -3,13 +3,18 @@
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
from UM.OutputDevice.OutputDevice import OutputDevice
|
from UM.OutputDevice.OutputDevice import OutputDevice
|
||||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QTimer
|
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QTimer, pyqtSignal, QUrl
|
||||||
|
from PyQt5.QtQml import QQmlComponent, QQmlContext
|
||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
from enum import IntEnum # For the connection state tracking.
|
from enum import IntEnum # For the connection state tracking.
|
||||||
|
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Signal import signalemitter
|
from UM.Signal import signalemitter
|
||||||
|
from UM.PluginRegistry import PluginRegistry
|
||||||
|
from UM.Application import Application
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
i18n_catalog = i18nCatalog("cura")
|
i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
@ -57,6 +62,11 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
||||||
|
|
||||||
self._camera_active = False
|
self._camera_active = False
|
||||||
|
|
||||||
|
self._monitor_view_qml_path = ""
|
||||||
|
self._monitor_component = None
|
||||||
|
self._monitor_item = None
|
||||||
|
self._qml_context = None
|
||||||
|
|
||||||
def requestWrite(self, nodes, file_name = None, filter_by_machine = False, file_handler = None):
|
def requestWrite(self, nodes, file_name = None, filter_by_machine = False, file_handler = None):
|
||||||
raise NotImplementedError("requestWrite needs to be implemented")
|
raise NotImplementedError("requestWrite needs to be implemented")
|
||||||
|
|
||||||
|
@ -111,6 +121,32 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
||||||
# Signal to be emitted when some drastic change occurs in the remaining time (not when the time just passes on normally).
|
# Signal to be emitted when some drastic change occurs in the remaining time (not when the time just passes on normally).
|
||||||
preheatBedRemainingTimeChanged = pyqtSignal()
|
preheatBedRemainingTimeChanged = pyqtSignal()
|
||||||
|
|
||||||
|
@pyqtProperty(QObject, constant=True)
|
||||||
|
def monitorItem(self):
|
||||||
|
# Note that we specifically only check if the monitor component is created.
|
||||||
|
# It could be that it failed to actually create the qml item! If we check if the item was created, it will try to
|
||||||
|
# create the item (and fail) every time.
|
||||||
|
if not self._monitor_component:
|
||||||
|
self._createMonitorViewFromQML()
|
||||||
|
|
||||||
|
return self._monitor_item
|
||||||
|
|
||||||
|
def _createMonitorViewFromQML(self):
|
||||||
|
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), self._monitor_view_qml_path))
|
||||||
|
|
||||||
|
# Because of garbage collection we need to keep this referenced by python.
|
||||||
|
self._monitor_component = QQmlComponent(Application.getInstance()._engine, path)
|
||||||
|
|
||||||
|
# Check if the context was already requested before (Printer output device might have multiple items in the future)
|
||||||
|
if self._qml_context is None:
|
||||||
|
self._qml_context = QQmlContext(Application.getInstance()._engine.rootContext())
|
||||||
|
self._qml_context.setContextProperty("OutputDevice", self)
|
||||||
|
|
||||||
|
self._monitor_item = self._monitor_component.create(self._qml_context)
|
||||||
|
if self._monitor_item is None:
|
||||||
|
Logger.log("e", "QQmlComponent status %s", self._monitor_component.status())
|
||||||
|
Logger.log("e", "QQmlComponent error string %s", self._monitor_component.errorString())
|
||||||
|
|
||||||
@pyqtProperty(str, notify=printerTypeChanged)
|
@pyqtProperty(str, notify=printerTypeChanged)
|
||||||
def printerType(self):
|
def printerType(self):
|
||||||
return self._printer_type
|
return self._printer_type
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue