From 3dfb2b2989d93b26b21fa7d3fca06a0b3166a970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 16 Jul 2015 14:01:28 +0200 Subject: [PATCH] Adjusted CuraPlugin for new wizard capabilities --- src/octoprint/plugins/cura/__init__.py | 8 ++- src/octoprint/plugins/cura/static/js/cura.js | 69 ++++++++++++++------ 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/src/octoprint/plugins/cura/__init__.py b/src/octoprint/plugins/cura/__init__.py index b21fd1a7..765f65f3 100644 --- a/src/octoprint/plugins/cura/__init__.py +++ b/src/octoprint/plugins/cura/__init__.py @@ -41,7 +41,7 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin, def _is_engine_configured(self, cura_engine=None): if cura_engine is None: cura_engine = normalize_path(self._settings.get(["cura_engine"])) - return cura_engine is not None and os.path.exists(cura_engine) + return cura_engine is not None and os.path.isfile(cura_engine) and os.access(cura_engine, os.X_OK) def _is_profile_available(self): return bool(self._slicing_manager.all_profiles("cura", require_configured=False)) @@ -60,6 +60,12 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin, def is_wizard_required(self): return not self._is_engine_configured() or not self._is_profile_available() + def get_wizard_details(self): + return dict( + engine=self._is_engine_configured(), + profile=self._is_profile_available() + ) + ##~~ StartupPlugin API def on_startup(self, host, port): diff --git a/src/octoprint/plugins/cura/static/js/cura.js b/src/octoprint/plugins/cura/static/js/cura.js index c03c7e84..b0482cc6 100644 --- a/src/octoprint/plugins/cura/static/js/cura.js +++ b/src/octoprint/plugins/cura/static/js/cura.js @@ -167,19 +167,13 @@ $(function() { $("#settings_plugin_cura_import").modal("show"); }; - self.testEnginePath = function() { - $.ajax({ - url: API_BASEURL + "util/test", - type: "POST", - dataType: "json", - data: JSON.stringify({ - command: "path", - path: self.settings.plugins.cura.cura_engine(), - check_type: "file", - check_access: "x" - }), - contentType: "application/json; charset=UTF-8", - success: function(response) { + self.testEnginePath = function(successCallback) { + self.sendTestRequest(self.settings.plugins.cura.cura_engine()); + }; + + self.sendTestRequest = function(enginePath, successCallback) { + if (successCallback == undefined) { + successCallback = function(response) { if (!response.result) { if (!response.exists) { self.pathText(gettext("The path doesn't exist")); @@ -194,6 +188,20 @@ $(function() { self.pathOk(response.result); self.pathBroken(!response.result); } + } + + $.ajax({ + url: API_BASEURL + "util/test", + type: "POST", + dataType: "json", + data: JSON.stringify({ + command: "path", + path: enginePath, + check_type: "file", + check_access: "x" + }), + contentType: "application/json; charset=UTF-8", + success: successCallback }) }; @@ -218,13 +226,6 @@ $(function() { }); }); self.profiles.updateItems(profiles); - - if (self.unconfiguredCuraEngine() === undefined) { - self.unconfiguredCuraEngine(self.settings.plugins.cura.cura_engine() == false); - } - if (self.unconfiguredSlicingProfile() === undefined) { - self.unconfiguredSlicingProfile(profiles.length == 0); - } }; self.onBeforeBinding = function () { @@ -233,10 +234,38 @@ $(function() { }; self.onSettingsHidden = function() { + self.resetPathTest(); + }; + + self.resetPathTest = function() { self.pathBroken(false); self.pathOk(false); self.pathText(""); }; + + self.onWizardDetails = function(response) { + if (!response.hasOwnProperty("cura") || !response.cura.required) return; + + if (response.cura.details.hasOwnProperty("engine")) { + self.unconfiguredCuraEngine(!response.cura.details.engine); + } + if (response.cura.details.hasOwnProperty("profile")) { + self.unconfiguredSlicingProfile(!response.cura.details.profile); + } + }; + + self.onWizardFinish = function() { + self.settingsViewModel.enqueueForSaving({ + plugins: { + cura: { + cura_engine: self.settings.plugins.cura.cura_engine(), + default_profile: self.settings.plugins.cura.default_profile(), + debug_logging: self.settings.plugins.cura.debug_logging() + } + } + }); + self.resetPathTest(); + }; } // view model class, parameters for constructor, container to bind to