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

View file

@ -13,7 +13,7 @@ from PlatformPhysics import PlatformPhysics
from BuildVolume import BuildVolume
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
import os.path
@ -85,6 +85,8 @@ class PrinterApplication(QtApplication):
self.setMainQml(os.path.dirname(__file__) + "/Printer.qml")
self.initializeEngine()
self.getStorageDevice('LocalFileStorage').removableDrivesChanged.connect(self._removableDrivesChanged)
#TODO: Add support for active machine preference
if self.getMachines():
self.setActiveMachine(self.getMachines()[0])
@ -132,3 +134,13 @@ class PrinterApplication(QtApplication):
self._volume.setHeight(machine.getSettingValueByKey('machine_height'))
self._volume.setDepth(machine.getSettingValueByKey('machine_depth'))
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()