Compare commits

..

No commits in common. "master" and "0.2.1" have entirely different histories.

4 changed files with 67 additions and 74 deletions

View File

@ -1,8 +1,3 @@
# WARNING
Plugin actually not in active development!
### ATTENTION ### ATTENTION
Plugin still in development! Plugin still in development!

View File

@ -12,6 +12,11 @@ import octoprint.plugin
class CustomControlPlugin(octoprint.plugin.SettingsPlugin, class CustomControlPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.TemplatePlugin, octoprint.plugin.TemplatePlugin,
octoprint.plugin.AssetPlugin): octoprint.plugin.AssetPlugin):
def get_settings_defaults(self):
return dict(
controls=[]
)
def get_template_configs(self): def get_template_configs(self):
if "editorcollection" in self._plugin_manager.enabled_plugins: if "editorcollection" in self._plugin_manager.enabled_plugins:
return [ return [
@ -23,13 +28,9 @@ class CustomControlPlugin(octoprint.plugin.SettingsPlugin,
dict(type="settings", template="customControl_hookedsettings.jinja2", custom_bindings=True) dict(type="settings", template="customControl_hookedsettings.jinja2", custom_bindings=True)
] ]
def on_settings_load(self):
return dict(
controls=settings().get(["controls"])
)
def on_settings_save(self, data): def on_settings_save(self, data):
settings().set(["controls"], data["controls"]) s = settings()
s.set(["controls"], data["controls"])
def get_assets(self): def get_assets(self):
return dict( return dict(
@ -61,7 +62,6 @@ class CustomControlPlugin(octoprint.plugin.SettingsPlugin,
__plugin_name__ = "Custom Control Editor" __plugin_name__ = "Custom Control Editor"
__plugin_pythoncompat__ = ">=2.7,<4"
def __plugin_load__(): def __plugin_load__():

View File

@ -32,9 +32,7 @@
}; };
self.onSettingsShown = function () { self.onSettingsShown = function () {
OctoPrint.control.getCustomControls().done(function(response) { self.requestData();
self._fromResponse(response);
});
}; };
self.requestData = function () { self.requestData = function () {
@ -92,10 +90,10 @@
var target = ko.dataFor(this); var target = ko.dataFor(this);
var item = ko.dataFor(ui.item[0]); var item = ko.dataFor(ui.item[0]);
if (target === undefined) { if (target == undefined) {
return; return;
} else { } else {
if (target === self) { if (target == self) {
if (!item.hasOwnProperty("children")) { if (!item.hasOwnProperty("children")) {
return; return;
} }
@ -107,23 +105,23 @@
var position = ko.utils.arrayIndexOf(ui.item.parent().children(), ui.item[0]); var position = ko.utils.arrayIndexOf(ui.item.parent().children(), ui.item[0]);
if (position >= 0) { if (position >= 0) {
if (item.parent !== undefined) { if (item.parent != undefined) {
item.parent.children.remove(item); item.parent.children.remove(item);
if (target === self) if (target == self)
self.controlsFromServer.splice(position, 0, item); self.controlsFromServer.splice(position, 0, item);
else else
target.children.splice(position, 0, item); target.children.splice(position, 0, item);
} else { } else {
self.controlsFromServer = _.without(self.controlsFromServer, item); self.controlsFromServer = _.without(self.controlsFromServer, item);
if (target === self) if (target == self)
self.controlsFromServer.splice(position, 0, item); self.controlsFromServer.splice(position, 0, item);
else else
target.children.splice(position, 0, item); target.children.splice(position, 0, item);
} }
} }
}, },
stop: function() { stop: function(event, ui) {
self.rerenderControls(); self.rerenderControls();
} }
}).disableSelection(); }).disableSelection();
@ -154,19 +152,19 @@
return def; return def;
}; };
_.each(list, function (element) { _.each(list, function (element, index, l) {
var input = { var input = {
name: ko.observable(element.name), name: ko.observable(element.name),
parameter: ko.observable(element.parameter), parameter: ko.observable(element.parameter),
default: ko.observable(element.hasOwnProperty("default") ? element.default : undefined) default: ko.observable(element.hasOwnProperty("default") ? element.default : undefined)
}; }
if (element.hasOwnProperty("slider") && _.isObject(element.slider)) { if (element.hasOwnProperty("slider") && _.isObject(element.slider)) {
input.slider = { input.slider = {
min: ko.observable(element.slider.min), min: ko.observable(element.slider.min),
max: ko.observable(element.slider.max), max: ko.observable(element.slider.max),
step: ko.observable(element.slider.step) step: ko.observable(element.slider.step)
}; }
var defaultValue = attributeToInt(element, "default", attributeToInt(element.slider, "min", 0)); var defaultValue = attributeToInt(element, "default", attributeToInt(element.slider, "min", 0));
@ -187,7 +185,7 @@
}); });
return inputs; return inputs;
}; }
self._processControl = function (parent, control) { self._processControl = function (parent, control) {
if (control.processed) { if (control.processed) {
control.id("settingsCustomControl_id" + self.staticID++); control.id("settingsCustomControl_id" + self.staticID++);
@ -217,7 +215,7 @@
if (control.hasOwnProperty("children")) { if (control.hasOwnProperty("children")) {
control.children = ko.observableArray(self._processControls(control, control.children)); control.children = ko.observableArray(self._processControls(control, control.children));
if (!control.hasOwnProperty("layout") || !(control.layout === "vertical" || control.layout === "horizontal" || control.layout === "horizontal_grid")) if (!control.hasOwnProperty("layout") || !(control.layout == "vertical" || control.layout == "horizontal" || control.layout == "horizontal_grid"))
control.layout = ko.observable("vertical"); control.layout = ko.observable("vertical");
else else
control.layout = ko.observable(control.layout); control.layout = ko.observable(control.layout);
@ -252,19 +250,19 @@
self.displayMode = function (customControl) { self.displayMode = function (customControl) {
if (customControl.hasOwnProperty("children")) { if (customControl.hasOwnProperty("children")) {
return (customControl.hasOwnProperty("name") && customControl.name() !== "") ? "settingsCustomControls_containerTemplate_collapsable" : "settingsCustomControls_containerTemplate_nameless"; return (customControl.hasOwnProperty("name") && customControl.name() != "") ? "settingsCustomControls_containerTemplate_collapsable" : "settingsCustomControls_containerTemplate_nameless";
} else { } else {
return "settingsCustomControls_controlTemplate"; return "settingsCustomControls_controlTemplate";
} }
}; }
self.rowCss = function (customControl) { self.rowCss = function (customControl) {
var span = "span2"; var span = "span2";
var offset = ""; var offset = "";
if (customControl.hasOwnProperty("width") && customControl.width() !== "") { if (customControl.hasOwnProperty("width") && customControl.width() != "") {
span = "span" + customControl.width(); span = "span" + customControl.width();
} }
if (customControl.hasOwnProperty("offset") && customControl.offset() !== "") { if (customControl.hasOwnProperty("offset") && customControl.offset() != "") {
offset = "offset" + customControl.offset(); offset = "offset" + customControl.offset();
} }
return "sortable " + span + " " + offset; return "sortable " + span + " " + offset;
@ -273,21 +271,21 @@
self.searchElement = function (list, id) { self.searchElement = function (list, id) {
for (var i = 0; i < list.length; i++) for (var i = 0; i < list.length; i++)
{ {
if (list[i].id() === id) if (list[i].id() == id)
return list[i]; return list[i];
if (list[i].hasOwnProperty("children")) { if (list[i].hasOwnProperty("children")) {
var element = self.searchElement(list[i].children(), id); var element = self.searchElement(list[i].children(), id);
if (element !== undefined) if (element != undefined)
return element; return element;
} }
} }
return undefined; return undefined;
}; }
self.createElement = function (invokedOn, contextParent) { self.createElement = function (invokedOn, contextParent, selectedMenu) {
if (contextParent.attr('id') === "base") { if (contextParent.attr('id') == "base") {
self.customControlDialogViewModel.reset(); self.customControlDialogViewModel.reset();
self.customControlDialogViewModel.show(function (ret) { self.customControlDialogViewModel.show(function (ret) {
@ -297,7 +295,7 @@
} }
else { else {
var parentElement = self.searchElement(self.controlsFromServer, contextParent.attr('id')); var parentElement = self.searchElement(self.controlsFromServer, contextParent.attr('id'));
if (parentElement === undefined) { if (parentElement == undefined) {
self._showPopup({ self._showPopup({
title: gettext("Something went wrong while creating the new Element"), title: gettext("Something went wrong while creating the new Element"),
type: "error" type: "error"
@ -311,10 +309,10 @@
parentElement.children.push(self._processControl(parentElement, ret)); parentElement.children.push(self._processControl(parentElement, ret));
}); });
} }
}; }
self.deleteElement = function (invokedOn, contextParent) { self.deleteElement = function (invokedOn, contextParent, selectedMenu) {
var element = self.searchElement(self.controlsFromServer, contextParent.attr('id')); var element = self.searchElement(self.controlsFromServer, contextParent.attr('id'));
if (element === undefined) { if (element == undefined) {
self._showPopup({ self._showPopup({
title: gettext("Something went wrong while creating the new Element"), title: gettext("Something went wrong while creating the new Element"),
type: "error" type: "error"
@ -323,17 +321,17 @@
} }
showConfirmationDialog("", function (e) { showConfirmationDialog("", function (e) {
if (element.parent !== undefined) if (element.parent != undefined)
element.parent.children.remove(element); element.parent.children.remove(element);
else { else {
self.controlsFromServer = _.without(self.controlsFromServer, element); self.controlsFromServer = _.without(self.controlsFromServer, element);
self.rerenderControls(); self.rerenderControls();
} }
}); });
}; }
self.editElement = function (invokedOn, contextParent) { self.editElement = function (invokedOn, contextParent, selectedMenu) {
var element = self.element = self.searchElement(self.controlsFromServer, contextParent.attr('id')); var element = self.element = self.searchElement(self.controlsFromServer, contextParent.attr('id'));
if (element === undefined) { if (element == undefined) {
self._showPopup({ self._showPopup({
title: gettext("Something went wrong while creating the new Element"), title: gettext("Something went wrong while creating the new Element"),
type: "error" type: "error"
@ -344,7 +342,7 @@
var title = "Edit Container"; var title = "Edit Container";
var type = "container"; var type = "container";
var data = { var data = {
parent: element.parent parent: element.parent,
}; };
if (element.hasOwnProperty("name")) { if (element.hasOwnProperty("name")) {
@ -427,21 +425,21 @@
case "command": { case "command": {
element.name(ret.name); element.name(ret.name);
if (ret.command !== undefined) { if (ret.command != undefined) {
element.command = ret.command; element.command = ret.command;
delete element.commands; delete element.commands;
} }
if (ret.commands !== undefined) { if (ret.commands != undefined) {
element.commands = ret.commands; element.commands = ret.commands;
delete element.command; delete element.command;
} }
if (ret.confirm !== "") { if (ret.confirm != "") {
element.confirm = ret.confirm; element.confirm = ret.confirm;
} }
if (ret.input !== undefined) { if (ret.input != undefined) {
_.each(ret.input, function (element, index) { _.each(ret.input, function (element, index, list) {
data.input[index] = ko.mapping.toJS(element); data.input[index] = ko.mapping.toJS(element);
}); });
@ -482,11 +480,11 @@
element.name(ret.name); element.name(ret.name);
element.script = ret.script; element.script = ret.script;
if (ret.confirm !== "") { if (ret.confirm != "") {
element.confirm = ret.confirm; element.confirm = ret.confirm;
} }
if (ret.input !== undefined) { if (ret.input != undefined) {
element.input(self._processInput(ret.input)); element.input(self._processInput(ret.input));
} }
else else
@ -502,15 +500,15 @@
} }
} }
if (element.parent && element.parent.layout() === "horizontal_grid") { if (element.parent && element.parent.layout() == "horizontal_grid") {
if (ret.width !== undefined && ret.width !== "") if (ret.width != undefined && ret.width != "")
element.width(ret.width); element.width(ret.width);
if (ret.offset !== undefined && ret.offset !== "") if (ret.offset != undefined && ret.offset != "")
element.offset(ret.offset); element.offset(ret.offset);
} }
}); });
}; }
self.controlContextMenu = function (invokedOn, contextParent, selectedMenu) self.controlContextMenu = function (invokedOn, contextParent, selectedMenu)
{ {
@ -553,19 +551,19 @@
break; break;
} }
} }
}; }
self.editStyle = function (type) { self.editStyle = function (type) {
}; }
self.recursiveDeleteProperties = function (list) { self.recursiveDeleteProperties = function (list) {
_.each(list, function (element) { _.each(list, function (element, index, ll) {
if (!element.parent || (element.parent.hasOwnProperty("layout") && element.parent.layout() !== "horizontal_grid")) { if (!element.parent || (element.parent.hasOwnProperty("layout") && element.parent.layout() != "horizontal_grid")) {
delete element.width; delete element.width;
delete element.offset; delete element.offset;
} }
if (element.default === "") if (element.default == "")
delete element.default; delete element.default;
delete element.id; delete element.id;
@ -578,19 +576,19 @@
if (element.hasOwnProperty("input")) { if (element.hasOwnProperty("input")) {
_.each(element.input(), function (e, i, l) { _.each(element.input(), function (e, i, l) {
if (e.default === "") if (e.default == "")
delete e.default; delete e.default;
delete e.value; delete e.value;
}); });
} }
if (element.hasOwnProperty("width") && element.width() === "") if (element.hasOwnProperty("width") && element.width() == "")
delete element.width; delete element.width;
if (element.hasOwnProperty("offset") && element.offset() === "") if (element.hasOwnProperty("offset") && element.offset() == "")
delete element.offset; delete element.offset;
if (!element.hasOwnProperty("name") || element.name() === "") { if (!element.hasOwnProperty("name") || element.name() == "") {
delete element.name; delete element.name;
delete element.collapsed; delete element.collapsed;
} }
@ -603,13 +601,13 @@
self.recursiveDeleteProperties(element.children()); self.recursiveDeleteProperties(element.children());
} }
}); });
}; }
self.onSettingsBeforeSave = function () { self.onSettingsBeforeSave = function () {
self.recursiveDeleteProperties(self.controlsFromServer); self.recursiveDeleteProperties(self.controlsFromServer);
self.settingsViewModel.settings.plugins.customControl.controls = self.controlsFromServer; self.settingsViewModel.settings.plugins.customControl.controls = self.controlsFromServer;
}; }
self.onEventSettingsUpdated = function () { self.onEventSettingsUpdated = function (payload) {
self.requestData(); self.requestData();
} }
} }

View File

@ -17,7 +17,7 @@ plugin_package = "octoprint_%s" % plugin_identifier
plugin_name = "OctoPrint-CustomControlPlugin" plugin_name = "OctoPrint-CustomControlPlugin"
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.2.2" plugin_version = "0.2.1"
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module # module
@ -120,13 +120,13 @@ class CleanCommand(Command):
# build folder # build folder
if os.path.exists('build'): if os.path.exists('build'):
print("Deleting build directory") print "Deleting build directory"
shutil.rmtree('build') shutil.rmtree('build')
# eggs # eggs
eggs = glob.glob("*.egg-info") eggs = glob.glob("*.egg-info")
for egg in eggs: for egg in eggs:
print("Deleting %s directory" % egg) print "Deleting %s directory" % egg
shutil.rmtree(egg) shutil.rmtree(egg)
# pyc files # pyc files
@ -135,11 +135,11 @@ class CleanCommand(Command):
return return
if len(os.listdir(path)) == 0: if len(os.listdir(path)) == 0:
shutil.rmtree(path) shutil.rmtree(path)
print("Deleted %s since it was empty" % path) print "Deleted %s since it was empty" % path
def delete_file(path): def delete_file(path):
os.remove(path) os.remove(path)
print("Deleted %s" % path) print "Deleted %s" % path
import fnmatch import fnmatch
_recursively_handle_files( _recursively_handle_files(
@ -155,11 +155,11 @@ class CleanCommand(Command):
return return
if len(os.listdir(path)) == 0: if len(os.listdir(path)) == 0:
shutil.rmtree(path) shutil.rmtree(path)
print("Deleted %s since it was empty" % path) print "Deleted %s since it was empty" % path
def delete_file(path): def delete_file(path):
os.remove(path) os.remove(path)
print("Deleted %s" % path) print "Deleted %s" % path
import fnmatch import fnmatch
_recursively_handle_files( _recursively_handle_files(