Fix sidebar loading and unloading depending on active stage

This commit is contained in:
ChrisTerBeke 2017-12-06 17:46:18 +01:00
parent 2d044a37ae
commit ee643610e5
7 changed files with 601 additions and 603 deletions

View file

@ -1,6 +1,5 @@
# Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtNetwork import QLocalServer
from PyQt5.QtNetwork import QLocalSocket

View file

@ -1,18 +1,22 @@
# Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtProperty, QObject
from PyQt5.QtCore import pyqtProperty, QUrl, QObject
from UM.Stage import Stage
class CuraStage(Stage):
def __init__(self):
super().__init__()
def __init__(self, parent = None):
super().__init__(parent)
@pyqtProperty(QObject, constant = True)
@pyqtProperty(str, constant = True)
def stageId(self):
return self.getPluginId()
@pyqtProperty(QUrl, constant = True)
def mainComponent(self):
return self.getDisplayComponent("main")
@pyqtProperty(QObject, constant = True)
@pyqtProperty(QUrl, constant = True)
def sidebarComponent(self):
return self.getDisplayComponent("sidebar")

View file

@ -9,14 +9,13 @@ from cura.Stages.CuraStage import CuraStage
## Stage for monitoring a 3D printing while it's printing.
class MonitorStage(CuraStage):
def __init__(self):
super().__init__()
def __init__(self, parent = None):
super().__init__(parent)
Application.getInstance().engineCreatedSignal.connect(self._engineCreated)
# TODO: connect output device state to icon source
def _engineCreated(self):
# Note: currently the sidebar component for prepare and monitor stages is the same, this will change with the printer output device refactor!
sidebar_component_path = os.path.join(Resources.getPath(Application.getInstance().ResourceTypes.QmlFiles), "Sidebar.qml")
sidebar_component = Application.getInstance().createQmlComponent(sidebar_component_path)
self.addDisplayComponent("sidebar", sidebar_component)
self.addDisplayComponent("sidebar", sidebar_component_path)
self.setIconSource(Application.getInstance().getTheme().getIcon("tab_status_connected"))

View file

@ -9,11 +9,10 @@ from cura.Stages.CuraStage import CuraStage
## Stage for preparing model (slicing).
class PrepareStage(CuraStage):
def __init__(self):
super().__init__()
def __init__(self, parent = None):
super().__init__(parent)
Application.getInstance().engineCreatedSignal.connect(self._engineCreated)
def _engineCreated(self):
sidebar_component_path = os.path.join(Resources.getPath(Application.getInstance().ResourceTypes.QmlFiles), "Sidebar.qml")
sidebar_component = Application.getInstance().createQmlComponent(sidebar_component_path)
self.addDisplayComponent("sidebar", sidebar_component)
self.addDisplayComponent("sidebar", sidebar_component_path)

View file

@ -377,7 +377,8 @@ UM.MainWindow
width: UM.Theme.getSize("sidebar").width
z: 1
sourceComponent: UM.Controller.activeStage.sidebarComponent
source: UM.Controller.activeStage.sidebarComponent
asynchronous: true
}
Loader
@ -390,10 +391,6 @@ UM.MainWindow
bottom: parent.bottom
left: parent.left
right: sidebar.left
// horizontalCenter: parent.horizontalCenter
// verticalCenter: parent.verticalCenter
// horizontalCenterOffset: - UM.Theme.getSize("sidebar").width / 2
// verticalCenterOffset: UM.Theme.getSize("sidebar_header").height / 2
}
// MouseArea
@ -403,7 +400,8 @@ UM.MainWindow
// onWheel: wheel.accepted = true
// }
sourceComponent: UM.Controller.activeStage.mainComponent
source: UM.Controller.activeStage.mainComponent
asynchronous: true
}
UM.MessageStack

View file

@ -10,8 +10,7 @@ import UM 1.2 as UM
import Cura 1.0 as Cura
import "Menus"
Component
{
Rectangle
{
id: base;
@ -26,7 +25,7 @@ Component
property var connectedPrinter: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
property int backendState: UM.Backend.state
property bool monitoringPrint: UM.Controller.activeStage.id == "MonitorStage"
property bool monitoringPrint: UM.Controller.activeStage.stageId == "MonitorStage"
property variant printDuration: PrintInformation.currentPrintTime
property variant printMaterialLengths: PrintInformation.materialLengths
@ -92,7 +91,7 @@ Component
SidebarHeader {
id: header
width: parent.width
visible: machineExtruderCount.properties.value > 1 || Cura.MachineManager.hasMaterials || Cura.MachineManager.hasVariantst
visible: machineExtruderCount.properties.value > 1 || Cura.MachineManager.hasMaterials || Cura.MachineManager.hasVariants
onShowTooltip: base.showTooltip(item, location, text)
onHideTooltip: base.hideTooltip()
}
@ -541,7 +540,6 @@ Component
visible: monitoringPrint
}
SidebarTooltip
{
id: tooltip;
@ -595,7 +593,6 @@ Component
UM.SettingPropertyProvider
{
id: machineExtruderCount
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_extruder_count"
watchedProperties: [ "value" ]
@ -605,11 +602,9 @@ Component
UM.SettingPropertyProvider
{
id: machineHeatedBed
containerStackId: Cura.MachineManager.activeMachineId
key: "machine_heated_bed"
watchedProperties: [ "value" ]
storeIndex: 0
}
}
}

View file

@ -403,8 +403,6 @@ Item
}
}
//
// Infill
//
@ -568,16 +566,22 @@ Item
model: infillModel
anchors.fill: parent
property int activeIndex: {
function activeIndex () {
for (var i = 0; i < infillModel.count; i++) {
var density = parseInt(infillDensity.properties.value)
var steps = parseInt(infillSteps.properties.value)
var infillModelItem = infillModel.get(i)
if (density >= infillModelItem.percentageMin
// TODO: somehow this print causes this method not to crash QML when the sidebar view gets unloaded (when switching states)
// TODO: That should be fixed :P
print("test", density, steps, infillModelItem)
if (infillModelItem
&& density >= infillModelItem.percentageMin
&& density <= infillModelItem.percentageMax
&& steps >= infillModelItem.stepsMin
&& steps <= infillModelItem.stepsMax){
&& steps <= infillModelItem.stepsMax
){
return i
}
}
@ -587,7 +591,7 @@ Item
Rectangle
{
anchors.fill: parent
visible: infillIconList.activeIndex == index
visible: infillIconList.activeIndex() == index
border.width: UM.Theme.getSize("default_lining").width
border.color: UM.Theme.getColor("quality_slider_unavailable")