Move printing user into job data & add UI representation
This commit is contained in:
1 parent
b41df46491
commit
79abe31a06
4 files changed
+63
-44
No files matched your search
@@ -65,8 +65,6 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
|
||||
self._state = None
|
||||
|
||||
self._printingUser = None
|
||||
|
||||
self._currentZ = None
|
||||
|
||||
self._printAfterSelect = False
|
||||
@@ -115,7 +113,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
estimatedPrintTime=None,
|
||||
lastPrintTime=None,
|
||||
filament=self._dict(length=None,
|
||||
volume=None)),
|
||||
volume=None),
|
||||
user=None),
|
||||
progress=self._dict(completion=None,
|
||||
filepos=None,
|
||||
printTime=None,
|
||||
@@ -176,14 +175,16 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
if self._selectedFile:
|
||||
self._setJobData(self._selectedFile["filename"],
|
||||
self._selectedFile["filesize"],
|
||||
self._selectedFile["sd"])
|
||||
self._selectedFile["sd"],
|
||||
self._selectedFile["user"])
|
||||
|
||||
def _on_event_MetadataStatisticsUpdated(self, event, data):
|
||||
with self._selectedFileMutex:
|
||||
if self._selectedFile:
|
||||
self._setJobData(self._selectedFile["filename"],
|
||||
self._selectedFile["filesize"],
|
||||
self._selectedFile["sd"])
|
||||
self._selectedFile["sd"],
|
||||
self._selectedFile["user"])
|
||||
|
||||
#~~ progress plugin reporting
|
||||
|
||||
@@ -438,9 +439,9 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
self._fileManager.delete_recovery_data()
|
||||
|
||||
self._printAfterSelect = printAfterSelect
|
||||
self._printingUser = user
|
||||
self._posAfterSelect = pos
|
||||
self._comm.selectFile("/" + path if sd else path, sd,
|
||||
user=user,
|
||||
tags=kwargs.get("tags", set()) | {"trigger:printer.select_file"})
|
||||
self._updateProgressData()
|
||||
self._setCurrentZ(None)
|
||||
@@ -916,7 +917,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
if not os.path.isfile(path_on_disk):
|
||||
raise InvalidFileLocation("{} does not exist in local storage, cannot select for printing".format(filename))
|
||||
|
||||
def _setJobData(self, filename, filesize, sd):
|
||||
def _setJobData(self, filename, filesize, sd, user=None):
|
||||
with self._selectedFileMutex:
|
||||
if filename is not None:
|
||||
if sd:
|
||||
@@ -933,7 +934,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
"filename": path_in_storage,
|
||||
"filesize": filesize,
|
||||
"sd": sd,
|
||||
"estimatedPrintTime": None
|
||||
"estimatedPrintTime": None,
|
||||
"user": user
|
||||
}
|
||||
else:
|
||||
self._selectedFile = None
|
||||
@@ -946,7 +948,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
estimatedPrintTime=None,
|
||||
averagePrintTime=None,
|
||||
lastPrintTime=None,
|
||||
filament=None))
|
||||
filament=None,
|
||||
user=None))
|
||||
return
|
||||
|
||||
estimatedPrintTime = None
|
||||
@@ -997,10 +1000,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
estimatedPrintTime=estimatedPrintTime,
|
||||
averagePrintTime=averagePrintTime,
|
||||
lastPrintTime=lastPrintTime,
|
||||
filament=filament))
|
||||
|
||||
def _setPrintingUser(self, user):
|
||||
self._stateMonitor.set_printing_user(user)
|
||||
filament=filament,
|
||||
user=user))
|
||||
|
||||
def _sendInitialStateUpdate(self, callback):
|
||||
try:
|
||||
@@ -1124,7 +1125,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
eventManager().fire(Events.UPDATED_FILES, {"type": "gcode"})
|
||||
self._sdFilelistAvailable.set()
|
||||
|
||||
def on_comm_file_selected(self, full_path, size, sd):
|
||||
def on_comm_file_selected(self, full_path, size, sd, user=None):
|
||||
if full_path is not None:
|
||||
payload = self._payload_for_print_job_event(location=FileDestinations.SDCARD if sd else FileDestinations.LOCAL,
|
||||
print_job_file=full_path)
|
||||
@@ -1132,7 +1133,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
else:
|
||||
eventManager().fire(Events.FILE_DESELECTED)
|
||||
|
||||
self._setJobData(full_path, size, sd)
|
||||
self._setJobData(full_path, size, sd, user=user)
|
||||
self._stateMonitor.set_state(self._dict(text=self.get_state_string(), flags=self._getStateFlags()))
|
||||
|
||||
if self._printAfterSelect:
|
||||
@@ -1239,10 +1240,10 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
context=dict(event=payload),
|
||||
must_be_set=False)
|
||||
|
||||
def on_comm_file_transfer_started(self, filename, filesize):
|
||||
def on_comm_file_transfer_started(self, filename, filesize, user=None):
|
||||
self._sdStreaming = True
|
||||
|
||||
self._setJobData(filename, filesize, True)
|
||||
self._setJobData(filename, filesize, True, user=user)
|
||||
self._updateProgressData(completion=0.0, filepos=0, printTime=0)
|
||||
self._stateMonitor.set_state(self._dict(text=self.get_state_string(), flags=self._getStateFlags()))
|
||||
|
||||
@@ -1333,7 +1334,6 @@ class StateMonitor(object):
|
||||
self._current_z = None
|
||||
self._offsets = dict()
|
||||
self._progress = None
|
||||
self._printing_user = None
|
||||
|
||||
self._progress_dirty = False
|
||||
|
||||
@@ -1351,13 +1351,12 @@ class StateMonitor(object):
|
||||
return self._on_get_progress()
|
||||
return self._progress
|
||||
|
||||
def reset(self, state=None, job_data=None, progress=None, current_z=None, offsets=None, printing_user=None):
|
||||
def reset(self, state=None, job_data=None, progress=None, current_z=None, offsets=None):
|
||||
self.set_state(state)
|
||||
self.set_job_data(job_data)
|
||||
self.set_progress(progress)
|
||||
self.set_current_z(current_z)
|
||||
self.set_temp_offsets(offsets)
|
||||
self.set_printing_user(printing_user)
|
||||
|
||||
def add_temperature(self, temperature):
|
||||
self._on_add_temperature(temperature)
|
||||
@@ -1384,10 +1383,6 @@ class StateMonitor(object):
|
||||
self._job_data = job_data
|
||||
self._change_event.set()
|
||||
|
||||
def set_printing_user(self, user):
|
||||
self._printing_user = user
|
||||
self._change_event.set()
|
||||
|
||||
def trigger_progress_update(self):
|
||||
with self._progress_lock:
|
||||
self._progress_dirty = True
|
||||
@@ -1432,8 +1427,7 @@ class StateMonitor(object):
|
||||
"job": self._job_data,
|
||||
"currentZ": self._current_z,
|
||||
"progress": self._progress,
|
||||
"offsets": self._offsets,
|
||||
"printingUser": self._printing_user,
|
||||
"offsets": self._offsets
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ $(function() {
|
||||
self.printTimeLeftOrigin = ko.observable(undefined);
|
||||
self.sd = ko.observable(undefined);
|
||||
self.timelapse = ko.observable(undefined);
|
||||
self.user = ko.observable(undefined);
|
||||
|
||||
self.busyFiles = ko.observableArray([]);
|
||||
|
||||
@@ -167,6 +168,11 @@ $(function() {
|
||||
}
|
||||
});
|
||||
|
||||
self.userString = ko.pureComputed(function() {
|
||||
var user = self.user();
|
||||
return user ? user : "-";
|
||||
});
|
||||
|
||||
self.fromCurrentData = function(data) {
|
||||
self._fromData(data);
|
||||
};
|
||||
@@ -244,6 +250,8 @@ $(function() {
|
||||
});
|
||||
}
|
||||
self.filament(result);
|
||||
|
||||
self.user(data.user);
|
||||
};
|
||||
|
||||
self._processProgressData = function(data) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<span title="{{ _('Current printer state') }}">{{ _('State') }}</span>: <strong data-bind="text: stateString"></strong><br>
|
||||
<hr>
|
||||
<span title="{{ _('Name of file currently selected for printing') }}">{{ _('File') }}</span>: <strong data-bind="text: filedisplay, attr: {title: filepath}"></strong> <strong data-bind="visible: sd">(SD)</strong><br>
|
||||
<span title="{{ _('User who selected this file for printing') }}">{{ _('User') }}</span>: <strong data-bind="text: userString"></strong><br>
|
||||
<span title="{{ _('Current timelapse configuration') }}">{{ _('Timelapse') }}</span>: <strong data-bind="text: timelapseString"></strong><br>
|
||||
<!-- ko foreach: filament -->
|
||||
<span data-bind="text: 'Filament (' + name() + '): ', title: 'Filament usage for ' + name()"></span><strong data-bind="text: formatFilament(data())"></strong><br>
|
||||
|
||||
+34
-18
@@ -549,6 +549,7 @@ class MachineCom(object):
|
||||
self._sdFileList = False
|
||||
self._sdFiles = []
|
||||
self._sdFileToSelect = None
|
||||
self._sdFileToSelectUser = None
|
||||
self._ignore_select = False
|
||||
self._manualStreaming = False
|
||||
|
||||
@@ -1071,7 +1072,7 @@ class MachineCom(object):
|
||||
|
||||
self.sendCommand("M28 %s" % remoteFilename, tags=tags | {"trigger:comm.start_file_transfer",})
|
||||
eventManager().fire(Events.TRANSFER_STARTED, {"local": localFilename, "remote": remoteFilename})
|
||||
self._callback.on_comm_file_transfer_started(remoteFilename, self._currentFile.getFilesize())
|
||||
self._callback.on_comm_file_transfer_started(remoteFilename, self._currentFile.getFilesize(), user=self._currentFile.getUser())
|
||||
|
||||
def cancelFileTransfer(self, tags=None):
|
||||
if not self.isOperational() or not self.isStreaming():
|
||||
@@ -1111,7 +1112,7 @@ class MachineCom(object):
|
||||
self.refreshSdFiles(tags={"trigger:comm.finish_file_transfer",})
|
||||
self._sendCommand(SendQueueMarker(finalize))
|
||||
|
||||
def selectFile(self, filename, sd, tags=None):
|
||||
def selectFile(self, filename, sd, user=None, tags=None):
|
||||
if self.isBusy():
|
||||
return
|
||||
|
||||
@@ -1127,17 +1128,21 @@ class MachineCom(object):
|
||||
filename = filename[1:]
|
||||
|
||||
self._sdFileToSelect = filename
|
||||
self._sdFileToSelectUser = user
|
||||
self.sendCommand("M23 %s" % filename, tags=tags | {"trigger:comm.select_file",})
|
||||
else:
|
||||
self._currentFile = PrintingGcodeFileInformation(filename, offsets_callback=self.getOffsets, current_tool_callback=self.getCurrentTool)
|
||||
self._callback.on_comm_file_selected(filename, self._currentFile.getFilesize(), False)
|
||||
self._currentFile = PrintingGcodeFileInformation(filename,
|
||||
offsets_callback=self.getOffsets,
|
||||
current_tool_callback=self.getCurrentTool,
|
||||
user=user)
|
||||
self._callback.on_comm_file_selected(filename, self._currentFile.getFilesize(), False, user=user)
|
||||
|
||||
def unselectFile(self):
|
||||
if self.isBusy():
|
||||
return
|
||||
|
||||
self._currentFile = None
|
||||
self._callback.on_comm_file_selected(None, None, False)
|
||||
self._callback.on_comm_file_selected(None, None, False, user=None)
|
||||
|
||||
def _cancel_preparation_done(self):
|
||||
self._recordFilePosition()
|
||||
@@ -1809,14 +1814,18 @@ class MachineCom(object):
|
||||
else:
|
||||
name = "Unknown"
|
||||
size = 0
|
||||
user = None
|
||||
|
||||
expected = False
|
||||
if self._sdFileToSelect:
|
||||
expected = True
|
||||
name = self._sdFileToSelect
|
||||
self._sdFileToSelect = None
|
||||
user = self._sdFileToSelectUser
|
||||
|
||||
self._currentFile = PrintingSdFileInformation(name, size)
|
||||
self._sdFileToSelect = None
|
||||
self._sdFileToSelectUser = None
|
||||
|
||||
self._currentFile = PrintingSdFileInformation(name, size, user=user)
|
||||
|
||||
if not expected:
|
||||
# It doesn't look like we expected this, so it might be that someone just started a print
|
||||
@@ -1828,7 +1837,10 @@ class MachineCom(object):
|
||||
self._ignore_select = False
|
||||
elif self._currentFile is not None and self.isSdFileSelected():
|
||||
# final answer to M23, at least on Marlin, Repetier and Sprinter: "File selected"
|
||||
self._callback.on_comm_file_selected(self._currentFile.getFilename(), self._currentFile.getFilesize(), True)
|
||||
self._callback.on_comm_file_selected(self._currentFile.getFilename(),
|
||||
self._currentFile.getFilesize(),
|
||||
True,
|
||||
user=self._currentFile.getUser())
|
||||
elif 'Writing to file' in line and self.isStreaming():
|
||||
self._changeState(self.STATE_PRINTING)
|
||||
elif 'Done printing file' in line and self.isSdPrinting():
|
||||
@@ -3370,7 +3382,7 @@ class MachineComPrintCallback(object):
|
||||
def on_comm_z_change(self, newZ):
|
||||
pass
|
||||
|
||||
def on_comm_file_selected(self, filename, filesize, sd):
|
||||
def on_comm_file_selected(self, filename, filesize, sd, user=None):
|
||||
pass
|
||||
|
||||
def on_comm_sd_state_change(self, sdReady):
|
||||
@@ -3379,7 +3391,7 @@ class MachineComPrintCallback(object):
|
||||
def on_comm_sd_files(self, files):
|
||||
pass
|
||||
|
||||
def on_comm_file_transfer_started(self, filename, filesize):
|
||||
def on_comm_file_transfer_started(self, filename, filesize, user=None):
|
||||
pass
|
||||
|
||||
def on_comm_file_transfer_done(self, filename):
|
||||
@@ -3406,9 +3418,10 @@ class PrintingFileInformation(object):
|
||||
|
||||
checksum = True
|
||||
|
||||
def __init__(self, filename):
|
||||
def __init__(self, filename, user=None):
|
||||
self._logger = logging.getLogger(__name__)
|
||||
self._filename = filename
|
||||
self._user = user
|
||||
self._pos = 0
|
||||
self._size = None
|
||||
self._start_time = None
|
||||
@@ -3429,6 +3442,9 @@ class PrintingFileInformation(object):
|
||||
def getFileLocation(self):
|
||||
return FileDestinations.LOCAL
|
||||
|
||||
def getUser(self):
|
||||
return self._user
|
||||
|
||||
def getProgress(self):
|
||||
"""
|
||||
The current progress of the file, calculated as relation between file position and absolute size. Returns -1
|
||||
@@ -3468,8 +3484,8 @@ class PrintingSdFileInformation(PrintingFileInformation):
|
||||
|
||||
checksum = False
|
||||
|
||||
def __init__(self, filename, size):
|
||||
PrintingFileInformation.__init__(self, filename)
|
||||
def __init__(self, filename, size, user=None):
|
||||
PrintingFileInformation.__init__(self, filename, user=user)
|
||||
self._size = size
|
||||
|
||||
def getFileLocation(self):
|
||||
@@ -3505,8 +3521,8 @@ class PrintingGcodeFileInformation(PrintingFileInformation):
|
||||
that the file is closed in case of an error.
|
||||
"""
|
||||
|
||||
def __init__(self, filename, offsets_callback=None, current_tool_callback=None):
|
||||
PrintingFileInformation.__init__(self, filename)
|
||||
def __init__(self, filename, offsets_callback=None, current_tool_callback=None, user=None):
|
||||
PrintingFileInformation.__init__(self, filename, user=user)
|
||||
|
||||
self._handle = None
|
||||
self._handle_mutex = threading.RLock()
|
||||
@@ -3607,8 +3623,8 @@ class PrintingGcodeFileInformation(PrintingFileInformation):
|
||||
pass
|
||||
|
||||
class StreamingGcodeFileInformation(PrintingGcodeFileInformation):
|
||||
def __init__(self, path, localFilename, remoteFilename):
|
||||
PrintingGcodeFileInformation.__init__(self, path)
|
||||
def __init__(self, path, localFilename, remoteFilename, user=None):
|
||||
PrintingGcodeFileInformation.__init__(self, path, user=user)
|
||||
self._localFilename = localFilename
|
||||
self._remoteFilename = remoteFilename
|
||||
|
||||
@@ -4407,7 +4423,7 @@ def upload_cli():
|
||||
self._target = target
|
||||
self._state = None
|
||||
|
||||
def on_comm_file_transfer_started(self, filename, filesize):
|
||||
def on_comm_file_transfer_started(self, filename, filesize, user=None):
|
||||
# transfer started, report
|
||||
logger.info("Started file transfer of {}, size {}B".format(filename, filesize))
|
||||
self.started = True
|
||||
|
||||
Reference in new issue
Block a user