mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 15:07:28 -06:00
Fixes for printer output device views - CURA-4568
This commit is contained in:
parent
cfbb553182
commit
74eb4958af
2 changed files with 8 additions and 26 deletions
|
@ -3,19 +3,15 @@
|
||||||
|
|
||||||
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, pyqtSignal, QUrl
|
from PyQt5.QtCore import pyqtProperty, pyqtSlot, QObject, QTimer, pyqtSignal
|
||||||
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
|
from UM.Application import Application
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
i18n_catalog = i18nCatalog("cura")
|
i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
## Printer output device adds extra interface options on top of output device.
|
## Printer output device adds extra interface options on top of output device.
|
||||||
|
@ -63,11 +59,9 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
||||||
self._camera_active = False
|
self._camera_active = False
|
||||||
|
|
||||||
self._monitor_view_qml_path = ""
|
self._monitor_view_qml_path = ""
|
||||||
self._monitor_component = None
|
|
||||||
self._monitor_item = None
|
self._monitor_item = None
|
||||||
|
|
||||||
self._control_view_qml_path = ""
|
self._control_view_qml_path = ""
|
||||||
self._control_component = None
|
|
||||||
self._control_item = None
|
self._control_item = None
|
||||||
|
|
||||||
self._qml_context = None
|
self._qml_context = None
|
||||||
|
@ -155,43 +149,31 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
||||||
# Note that we specifically only check if the monitor component is created.
|
# 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
|
# 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.
|
# create the item (and fail) every time.
|
||||||
if not self._monitor_component:
|
if not self._monitor_item:
|
||||||
self._createMonitorViewFromQML()
|
self._createMonitorViewFromQML()
|
||||||
|
|
||||||
return self._monitor_item
|
return self._monitor_item
|
||||||
|
|
||||||
@pyqtProperty(QObject, constant=True)
|
@pyqtProperty(QObject, constant=True)
|
||||||
def controlItem(self):
|
def controlItem(self):
|
||||||
if not self._control_component:
|
if not self._control_item:
|
||||||
self._createControlViewFromQML()
|
self._createControlViewFromQML()
|
||||||
|
|
||||||
return self._control_item
|
return self._control_item
|
||||||
|
|
||||||
def _createControlViewFromQML(self):
|
def _createControlViewFromQML(self):
|
||||||
if not self._control_view_qml_path:
|
if not self._control_view_qml_path:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._control_component = Application.getInstance().createQmlComponent(self._control_view_qml_path, {
|
self._control_item = Application.getInstance().createQmlComponent(self._control_view_qml_path, {
|
||||||
"OutputDevice": self
|
"OutputDevice": self
|
||||||
})
|
})
|
||||||
|
|
||||||
def _createMonitorViewFromQML(self):
|
def _createMonitorViewFromQML(self):
|
||||||
if not self._monitor_view_qml_path:
|
if not self._monitor_view_qml_path:
|
||||||
return
|
return
|
||||||
path = QUrl.fromLocalFile(self._monitor_view_qml_path)
|
|
||||||
|
|
||||||
# Because of garbage collection we need to keep this referenced by python.
|
self._monitor_item = Application.getInstance().createQmlComponent(self._monitor_view_qml_path, {
|
||||||
self._monitor_component = QQmlComponent(Application.getInstance()._engine, path)
|
"OutputDevice": self
|
||||||
|
})
|
||||||
# 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):
|
||||||
|
|
|
@ -131,7 +131,7 @@ class NetworkClusterPrinterOutputDevice(NetworkPrinterOutputDevice.NetworkPrinte
|
||||||
@pyqtProperty(QObject, notify=selectedPrinterChanged)
|
@pyqtProperty(QObject, notify=selectedPrinterChanged)
|
||||||
def controlItem(self):
|
def controlItem(self):
|
||||||
# TODO: Probably not the nicest way to do this. This needs to be done better at some point in time.
|
# TODO: Probably not the nicest way to do this. This needs to be done better at some point in time.
|
||||||
if not self._control_component:
|
if not self._control_item:
|
||||||
self._createControlViewFromQML()
|
self._createControlViewFromQML()
|
||||||
name = self._selected_printer.get("friendly_name")
|
name = self._selected_printer.get("friendly_name")
|
||||||
if name == self._automatic_printer.get("friendly_name") or name == "":
|
if name == self._automatic_printer.get("friendly_name") or name == "":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue