From f70649b0d2c94738856e12f77bb9e35cc594431a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sat, 30 Mar 2013 18:21:49 +0100 Subject: [PATCH] Removed a couple of redundancies for loadAndPrint button, actions are now disabled if they don't make sense --- octoprint/printer.py | 35 +++++--------------- octoprint/server.py | 13 +++----- octoprint/static/css/octoprint.less | 19 +++++++++++ octoprint/static/js/ui.js | 51 ++++++++++++++++++++++------- octoprint/templates/index.html | 5 ++- 5 files changed, 74 insertions(+), 49 deletions(-) diff --git a/octoprint/printer.py b/octoprint/printer.py index 72cb531..be080b2 100644 --- a/octoprint/printer.py +++ b/octoprint/printer.py @@ -158,7 +158,7 @@ class Printer(): self._comm.setFeedrateModifier(self._feedrateModifierMapping[structure], percentage / 100.0) - def loadGcode(self, file): + def loadGcode(self, file, printAfterLoading=False): """ Loads the gcode from the given file as the new print job. Aborts if the printer is currently printing or another gcode file is currently being loaded. @@ -168,27 +168,15 @@ class Printer(): self._setJobData(None, None) - self._gcodeLoader = GcodeLoader(file, self._onGcodeLoadingProgress, self._onGcodeLoaded) + onGcodeLoadedCallback = self._onGcodeLoaded + if printAfterLoading: + onGcodeLoadedCallback = self._onGcodeLoadedToPrint + + self._gcodeLoader = GcodeLoader(file, self._onGcodeLoadingProgress, onGcodeLoadedCallback) self._gcodeLoader.start() self._stateMonitor.setState({"state": self._state, "stateString": self.getStateString(), "flags": self._getStateFlags()}) - def loadAndPrintGcode(self, file): - """ - Loads the gcode from the given file as the new print job and starts the print. - Aborts if the printer is currently printing or another gcode file is currently being loaded, or if loading the gcode file fails. - """ - if (self._comm is not None and self._comm.isPrinting()) or (self._gcodeLoader is not None): - return - - self._setJobData(None, None) - - self._gcodeLoader = GcodeLoader(file, self._onGcodeLoadingProgress, self._onGcodeLoadedToPrint) - self._gcodeLoader.start() - - self._stateMonitor.setState({"state": self._state, "stateString": self.getStateString(), "flags": self._getStateFlags()}) - - def startPrint(self): """ Starts the currently loaded print job. @@ -433,15 +421,8 @@ class Printer(): self._stateMonitor.setState({"state": self._state, "stateString": self.getStateString(), "flags": self._getStateFlags()}) def _onGcodeLoadedToPrint(self, filename, gcodeList): - self._setJobData(filename, gcodeList) - self._setCurrentZ(None) - self._setProgressData(None, None, None) - self._gcodeLoader = None - - self._stateMonitor.setGcodeData({"filename": None, "progress": None}) - self._stateMonitor.setState({"state": self._state, "stateString": self.getStateString(), "flags": self._getStateFlags()}) - - self.startPrint(); + self._onGcodeLoaded(filename, gcodeList) + self.startPrint() #~~ state reports diff --git a/octoprint/server.py b/octoprint/server.py index 6af1e58..865d792 100644 --- a/octoprint/server.py +++ b/octoprint/server.py @@ -261,17 +261,12 @@ def uploadGcodeFile(): @app.route(BASEURL + "gcodefiles/load", methods=["POST"]) def loadGcodeFile(): if "filename" in request.values.keys(): + printAfterLoading = False + if "print" in request.values.keys() and request.values["print"]: + printAfterLoading = True filename = gcodeManager.getAbsolutePath(request.values["filename"]) if filename is not None: - printer.loadGcode(filename) - return jsonify(SUCCESS) - -@app.route(BASEURL + "gcodefiles/loadandprint", methods=["POST"]) -def loadAndPrintGcodeFile(): - if "filename" in request.values.keys(): - filename = gcodeManager.getAbsolutePath(request.values["filename"]) - if filename is not None: - printer.loadAndPrintGcode(filename) + printer.loadGcode(filename, printAfterLoading) return jsonify(SUCCESS) @app.route(BASEURL + "gcodefiles/delete", methods=["POST"]) diff --git a/octoprint/static/css/octoprint.less b/octoprint/static/css/octoprint.less index 31a233c..5a592fa 100644 --- a/octoprint/static/css/octoprint.less +++ b/octoprint/static/css/octoprint.less @@ -65,6 +65,10 @@ body { @base: #7728FF; .navbar-inner-color(@base); } + + .brand img { + vertical-align: bottom; + } } /** OctoPrint application tabs */ @@ -115,6 +119,11 @@ body { a.accordion-toggle { display: inline-block; } + + [class^="icon-"], + [class*=" icon-"] { + color: #000; + } } } @@ -146,6 +155,16 @@ table { &.gcode_files_action { text-align: center; width: 70px; + + a { + text-decoration: none; + color: #000; + + &.disabled { + color: #ccc; + cursor: default; + } + } } // timelapse files diff --git a/octoprint/static/js/ui.js b/octoprint/static/js/ui.js index 8027d51..bf0831c 100644 --- a/octoprint/static/js/ui.js +++ b/octoprint/static/js/ui.js @@ -657,6 +657,14 @@ function TerminalViewModel() { function GcodeFilesViewModel() { var self = this; + self.isErrorOrClosed = ko.observable(undefined); + self.isOperational = ko.observable(undefined); + self.isPrinting = ko.observable(undefined); + self.isPaused = ko.observable(undefined); + self.isError = ko.observable(undefined); + self.isReady = ko.observable(undefined); + self.isLoading = ko.observable(undefined); + // initialize list helper self.listHelper = new ItemListHelper( "gcodeFiles", @@ -688,7 +696,33 @@ function GcodeFilesViewModel() { "name", [], CONFIG_GCODEFILESPERPAGE - ) + ); + + self.isLoadActionPossible = ko.computed(function() { + return !self.isPrinting() && !self.isPaused() && !self.isLoading(); + }); + + self.isLoadAndPrintActionPossible = ko.computed(function() { + return self.isOperational() && self.isLoadActionPossible(); + }); + + self.fromCurrentData = function(data) { + self._processStateData(data.state); + } + + self.fromHistoryData = function(data) { + self._processStateData(data.state); + } + + self._processStateData = function(data) { + self.isErrorOrClosed(data.flags.closedOrError); + self.isOperational(data.flags.operational); + self.isPaused(data.flags.paused); + self.isPrinting(data.flags.printing); + self.isError(data.flags.error); + self.isReady(data.flags.ready); + self.isLoading(data.flags.loading); + } self.requestData = function() { $.ajax({ @@ -710,21 +744,12 @@ function GcodeFilesViewModel() { } } - self.loadFile = function(filename) { + self.loadFile = function(filename, printAfterLoad) { $.ajax({ url: AJAX_BASEURL + "gcodefiles/load", type: "POST", dataType: "json", - data: {filename: filename} - }) - } - - self.loadAndPrintFile = function(filename) { - $.ajax({ - url: AJAX_BASEURL + "gcodefiles/loadandprint", - type: "POST", - dataType: "json", - data: {filename: filename} + data: {filename: filename, print: printAfterLoad} }) } @@ -1149,6 +1174,7 @@ function DataUpdater(connectionViewModel, printerStateViewModel, temperatureView self.terminalViewModel.fromHistoryData(data); self.webcamViewModel.fromHistoryData(data); self.gcodeViewModel.fromHistoryData(data); + self.gcodeFilesViewModel.fromCurrentData(data); }) self._socket.on("current", function(data) { self.connectionViewModel.fromCurrentData(data); @@ -1158,6 +1184,7 @@ function DataUpdater(connectionViewModel, printerStateViewModel, temperatureView self.terminalViewModel.fromCurrentData(data); self.webcamViewModel.fromCurrentData(data); self.gcodeViewModel.fromCurrentData(data); + self.gcodeFilesViewModel.fromCurrentData(data); }) self._socket.on("updateTrigger", function(type) { if (type == "gcodeFiles") { diff --git a/octoprint/templates/index.html b/octoprint/templates/index.html index 8bf411c..2f17cc1 100644 --- a/octoprint/templates/index.html +++ b/octoprint/templates/index.html @@ -8,6 +8,7 @@ + @@ -127,7 +128,9 @@ -  |  |  + +  |  |  +