1 parent
0376bc4235
commit
73a85646c5
6 files changed
+136
-20
No files matched your search
@@ -236,11 +236,26 @@ class PrinterInterface(object):
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def pause_print(self):
|
||||
"""
|
||||
Pauses the current print job if it is currently running, does nothing otherwise.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def resume_print(self):
|
||||
"""
|
||||
Resumes the current print job if it is currently paused, does nothing otherwise.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def toggle_pause_print(self):
|
||||
"""
|
||||
Pauses the current print job if it is currently running or resumes it if it is currently paused.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
if self.is_printing():
|
||||
self.pause_print()
|
||||
elif self.is_paused():
|
||||
self.resume_print()
|
||||
|
||||
def cancel_print(self):
|
||||
"""
|
||||
|
||||
@@ -404,14 +404,29 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
self._setCurrentZ(None)
|
||||
self._comm.startPrint(pos=pos)
|
||||
|
||||
def toggle_pause_print(self):
|
||||
def pause_print(self):
|
||||
"""
|
||||
Pause the current printjob.
|
||||
Pause the current printjob.
|
||||
"""
|
||||
if self._comm is None:
|
||||
return
|
||||
|
||||
self._comm.setPause(not self._comm.isPaused())
|
||||
if self._comm.isPaused():
|
||||
return
|
||||
|
||||
self._comm.setPause(True)
|
||||
|
||||
def resume_print(self):
|
||||
"""
|
||||
Resume the current printjob.
|
||||
"""
|
||||
if self._comm is None:
|
||||
return
|
||||
|
||||
if not self._comm.isPaused():
|
||||
return
|
||||
|
||||
self._comm.setPause(False)
|
||||
|
||||
def cancel_print(self):
|
||||
"""
|
||||
|
||||
@@ -43,7 +43,15 @@ def controlJob():
|
||||
elif command == "pause":
|
||||
if not activePrintjob:
|
||||
return make_response("Printer is neither printing nor paused, 'pause' command cannot be performed", 409)
|
||||
printer.toggle_pause_print()
|
||||
action = data.get("action", "toggle")
|
||||
if action == "toggle":
|
||||
printer.toggle_pause_print()
|
||||
elif action == "pause":
|
||||
printer.pause_print()
|
||||
elif action == "resume":
|
||||
printer.resume_print()
|
||||
else:
|
||||
return make_response("Unknown action '{}', allowed values for action parameter are 'pause', 'resume' and 'toggle'".format(action), 400)
|
||||
elif command == "cancel":
|
||||
if not activePrintjob:
|
||||
return make_response("Printer is neither printing nor paused, 'cancel' command cannot be performed", 409)
|
||||
@@ -58,4 +66,4 @@ def jobState():
|
||||
"job": currentData["job"],
|
||||
"progress": currentData["progress"],
|
||||
"state": currentData["state"]["text"]
|
||||
})
|
||||
})
|
||||
@@ -223,21 +223,41 @@ $(function() {
|
||||
|
||||
};
|
||||
|
||||
self.pause = function() {
|
||||
self._jobCommand("pause");
|
||||
self.onlyPause = function() {
|
||||
self.pause("pause");
|
||||
};
|
||||
|
||||
self.onlyResume = function() {
|
||||
self.pause("resume");
|
||||
};
|
||||
|
||||
self.pause = function(action) {
|
||||
action = action || "toggle";
|
||||
self._jobCommand("pause", {"action": action});
|
||||
};
|
||||
|
||||
self.cancel = function() {
|
||||
self._jobCommand("cancel");
|
||||
};
|
||||
|
||||
self._jobCommand = function(command, callback) {
|
||||
self._jobCommand = function(command, payload, callback) {
|
||||
if (arguments.length == 1) {
|
||||
payload = {};
|
||||
callback = undefined;
|
||||
} else if (arguments.length == 2 && typeof payload === "function") {
|
||||
callback = payload;
|
||||
payload = {};
|
||||
}
|
||||
|
||||
var data = _.extend(payload, {});
|
||||
data.command = command;
|
||||
|
||||
$.ajax({
|
||||
url: API_BASEURL + "job",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
contentType: "application/json; charset=UTF-8",
|
||||
data: JSON.stringify({command: command}),
|
||||
data: JSON.stringify(data),
|
||||
success: function(response) {
|
||||
if (callback != undefined) {
|
||||
callback();
|
||||
|
||||
@@ -15,6 +15,6 @@
|
||||
|
||||
<div class="row-fluid print-control" style="display: none;" data-bind="visible: loginState.isUser">
|
||||
<button class="btn btn-primary span4" data-bind="click: print, enable: enablePrint, css: {'btn-danger': isPaused()}, attr: {title: titlePrintButton}" id="job_print"><i class="icon-white" data-bind="css: {'icon-print': !isPaused(), 'icon-undo': isPaused()}"></i> <span data-bind="text: (isPaused() ? '{{ _('Restart') }}' : '{{ _('Print') }}')">{{ _('Print') }}</span></button>
|
||||
<button class="btn span4" id="job_pause" data-bind="click: pause, enable: enablePause, css: {active: isPaused()}, attr: {title: titlePauseButton}"><i data-bind="css: {'icon-pause': !isPaused(), 'icon-play': isPaused()}"></i> <span data-bind="visible: !isPaused()">{{ _('Pause') }}</span><span data-bind="visible: isPaused()">{{ _('Resume') }}</span></button>
|
||||
<button class="btn span4" id="job_pause" data-bind="click: function() { isPaused() ? onlyResume() : onlyPause(); }, enable: enablePause, css: {active: isPaused()}, attr: {title: titlePauseButton}"><i data-bind="css: {'icon-pause': !isPaused(), 'icon-play': isPaused()}"></i> <span data-bind="visible: !isPaused()">{{ _('Pause') }}</span><span data-bind="visible: isPaused()">{{ _('Resume') }}</span></button>
|
||||
<button class="btn span4" id="job_cancel" data-bind="click: cancel, enable: enableCancel" title="{{ _('Cancels the print job') }}"><i class="icon-stop"></i> {{ _('Cancel') }}</button>
|
||||
</div>
|
||||
Reference in new issue
Block a user