Added button to cura settings to check validity of engine path

This commit is contained in:
Gina Häußge 2015-07-08 13:36:56 +02:00
parent e2894c25b5
commit 377607cf12
3 changed files with 54 additions and 5 deletions

View file

@ -16,6 +16,8 @@ import octoprint.util
import octoprint.slicing
import octoprint.settings
from octoprint.util.paths import normalize as normalize_path
from .profile import Profile
class CuraPlugin(octoprint.plugin.SlicerPlugin,
@ -156,7 +158,7 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin,
##~~ SlicerPlugin API
def is_slicer_configured(self):
cura_engine = self._settings.get(["cura_engine"])
cura_engine = normalize_path(self._settings.get(["cura_engine"]))
if cura_engine is not None and os.path.exists(cura_engine):
return True
else:
@ -230,7 +232,7 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin,
engine_settings = self._convert_to_engine(profile_path, printer_profile, posX, posY)
executable = self._settings.get(["cura_engine"])
executable = normalize_path(self._settings.get(["cura_engine"]))
if not executable:
return False, "Path to CuraEngine is not configured "

View file

@ -6,6 +6,13 @@ $(function() {
self.settingsViewModel = parameters[1];
self.slicingViewModel = parameters[2];
self.pathBroken = ko.observable(false);
self.pathOk = ko.observable(false);
self.pathText = ko.observable();
self.pathHelpVisible = ko.computed(function() {
return self.pathBroken() || self.pathOk();
});
self.fileName = ko.observable();
self.placeholderName = ko.observable();
@ -157,6 +164,36 @@ $(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) {
if (!response.result) {
if (!response.exists) {
self.pathText(gettext("The path doesn't exist"));
} else if (!response.typeok) {
self.pathText(gettext("The path is not a file"));
} else if (!response.access) {
self.pathText(gettext("The path is not an executable"));
}
} else {
self.pathText(gettext("The path is valid"));
}
self.pathOk(response.result);
self.pathBroken(!response.result);
}
})
};
self.requestData = function() {
$.ajax({
url: API_BASEURL + "slicing/cura/profiles",
@ -184,6 +221,12 @@ $(function() {
self.settings = self.settingsViewModel.settings;
self.requestData();
};
self.onSettingsHidden = function() {
self.pathBroken(false);
self.pathOk(false);
self.pathText("");
};
}
// view model class, parameters for constructor, container to bind to
@ -192,4 +235,4 @@ $(function() {
["loginStateViewModel", "settingsViewModel", "slicingViewModel"],
"#settings_plugin_cura"
]);
});
});

View file

@ -1,10 +1,14 @@
<h4>{{ _('General') }}</h4>
<form class="form-horizontal">
<div class="control-group">
<div class="control-group" data-bind="css: {error: pathBroken, success: pathOk}">
<label class="control-label" for="settings-cura-path">{{ _('Path to CuraEngine') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.cura.cura_engine">
<div class="input-append">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.cura.cura_engine">
<button class="btn" type="button" data-bind="click: testEnginePath">{{ _('Test') }}</button>
</div>
<span class="help-block" data-bind="visible: pathBroken() || pathOk, text: pathText"></span>
</div>
</div>
<div class="control-group">