Use the removable drive notification to update the state of the save button

This commit is contained in:
Arjen Hiemstra 2015-03-03 15:08:38 +01:00
parent 49c7dcc2be
commit 36a2735c5c
2 changed files with 16 additions and 5 deletions

View file

@ -13,6 +13,7 @@ Rectangle {
border.color: UM.Theme.borderColor; border.color: UM.Theme.borderColor;
signal saveRequested(); signal saveRequested();
signal saveToSdRequested();
Label { Label {
id: label; id: label;
@ -54,10 +55,7 @@ Rectangle {
onClicked: { onClicked: {
switch(base.state) { switch(base.state) {
case 'sdcard': case 'sdcard':
base.state = 'usb'; base.saveToSdRequested();
break;
case 'usb':
base.state = '';
break; break;
default: default:
base.saveRequested(); base.saveRequested();
@ -69,6 +67,7 @@ Rectangle {
states: [ states: [
State { State {
name: 'sdcard'; name: 'sdcard';
when: Printer.removableDrives.length > 0;
PropertyChanges { PropertyChanges {
target: label; target: label;
//: Write to SD card button //: Write to SD card button

View file

@ -13,7 +13,7 @@ from PlatformPhysics import PlatformPhysics
from BuildVolume import BuildVolume from BuildVolume import BuildVolume
from CameraAnimation import CameraAnimation from CameraAnimation import CameraAnimation
from PyQt5.QtCore import pyqtSlot, QUrl, Qt, pyqtSignal from PyQt5.QtCore import pyqtSlot, QUrl, Qt, pyqtSignal, pyqtProperty
from PyQt5.QtGui import QColor from PyQt5.QtGui import QColor
import os.path import os.path
@ -85,6 +85,8 @@ class PrinterApplication(QtApplication):
self.setMainQml(os.path.dirname(__file__) + "/Printer.qml") self.setMainQml(os.path.dirname(__file__) + "/Printer.qml")
self.initializeEngine() self.initializeEngine()
self.getStorageDevice('LocalFileStorage').removableDrivesChanged.connect(self._removableDrivesChanged)
#TODO: Add support for active machine preference #TODO: Add support for active machine preference
if self.getMachines(): if self.getMachines():
self.setActiveMachine(self.getMachines()[0]) self.setActiveMachine(self.getMachines()[0])
@ -132,3 +134,13 @@ class PrinterApplication(QtApplication):
self._volume.setHeight(machine.getSettingValueByKey('machine_height')) self._volume.setHeight(machine.getSettingValueByKey('machine_height'))
self._volume.setDepth(machine.getSettingValueByKey('machine_depth')) self._volume.setDepth(machine.getSettingValueByKey('machine_depth'))
self._volume.rebuild() self._volume.rebuild()
removableDrivesChanged = pyqtSignal()
@pyqtProperty("QStringList", notify = removableDrivesChanged)
def removableDrives(self):
return list(self.getStorageDevice('LocalFileStorage').getRemovableDrives().keys())
def _removableDrivesChanged(self):
print(self.getStorageDevice('LocalFileStorage').getRemovableDrives())
self.removableDrivesChanged.emit()