8 Commits
0.2.1 ... devel

8 changed files with 91 additions and 81 deletions

View File

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

View File

@ -12,11 +12,6 @@ import octoprint.plugin
class CustomControlPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.TemplatePlugin,
octoprint.plugin.AssetPlugin):
def get_settings_defaults(self):
return dict(
controls=[]
)
def get_template_configs(self):
if "editorcollection" in self._plugin_manager.enabled_plugins:
return [
@ -28,9 +23,13 @@ class CustomControlPlugin(octoprint.plugin.SettingsPlugin,
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):
s = settings()
s.set(["controls"], data["controls"])
settings().set(["controls"], data["controls"])
def get_assets(self):
return dict(
@ -39,7 +38,7 @@ class CustomControlPlugin(octoprint.plugin.SettingsPlugin,
"js/customControl.js",
"js/customControlDialog.js",
],
css=["css/customControls.css"],
css=["css/customControls.min.css"],
less=["less/customControls.less"]
)
@ -62,6 +61,7 @@ class CustomControlPlugin(octoprint.plugin.SettingsPlugin,
__plugin_name__ = "Custom Control Editor"
__plugin_pythoncompat__ = ">=2.7,<4"
def __plugin_load__():

View File

@ -1,40 +1,40 @@
#customControls .innerSortable {
#settings_plugin_customControl .innerSortable {
width: 100%;
min-height: 50px;
}
#customControls .custom_section_horizontal > .custom_control {
.customControlEditor .custom_section_horizontal > .custom_control {
display: inline-block;
}
#customControls .custom_section_vertical > .custom_control {
.customControlEditor .custom_section_vertical > .custom_control {
display: block;
}
#customControls .custom_section_vertical_section {
.customControlEditor .custom_section_vertical_section {
min-width: 15px;
min-height: 15px;
border: 1px dashed #000000;
}
#customControls .slider.slider-disabled .slider-track {
.customControlEditor .slider.slider-disabled .slider-track {
cursor: default !important;
}
#customControls input[disabled] {
.customControlEditor input[disabled] {
background: #fff !important;
cursor: text !important;
}
#customControls .btn-group {
.customControlEditor .btn-group {
margin-bottom: 10px;
}
#customControls .btn-group.distance > .btn {
.customControlEditor .btn-group.distance > .btn {
width: 43px;
padding: 3px 0;
height: 30px;
}
#customControls .slider-handle {
.customControlEditor .slider-handle {
width: 14px;
height: 14px;
margin-left: -7px;
margin-top: -3px;
}
#customControls .custom_section h1 {
.customControlEditor .custom_section h1 {
cursor: pointer;
display: block;
width: 100%;
@ -47,7 +47,7 @@
border-bottom: 1px solid #E5E5E5;
font-weight: normal;
}
#customControls .custom_control .slider {
.customControlEditor .custom_control .slider {
margin-left: 10px;
margin-right: 10px;
margin-bottom: 2px;

View File

@ -0,0 +1 @@
#settings_plugin_customControl .innerSortable{width:100%;min-height:50px}.customControlEditor .custom_section_horizontal>.custom_control{display:inline-block}.customControlEditor .custom_section_vertical>.custom_control{display:block}.customControlEditor .custom_section_vertical_section{min-width:15px;min-height:15px;border:1px dashed #000}.customControlEditor .slider.slider-disabled .slider-track{cursor:default!important}.customControlEditor input[disabled]{background:#fff!important;cursor:text!important}.customControlEditor .btn-group{margin-bottom:10px}.customControlEditor .btn-group.distance>.btn{width:43px;padding:3px 0;height:30px}.customControlEditor .slider-handle{width:14px;height:14px;margin-left:-7px;margin-top:-3px}.customControlEditor .custom_section h1{cursor:pointer;display:block;width:100%;padding:0;margin-bottom:10px;font-size:21px;line-height:40px;color:#333;border:0;border-bottom:1px solid #E5E5E5;font-weight:400}.customControlEditor .custom_control .slider{margin-left:10px;margin-right:10px;margin-bottom:2px}

View File

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

View File

@ -1,9 +1,11 @@
#customControls {
#settings_plugin_customControl {
.innerSortable {
width: 100%;
min-height: 50px;
}
}
.customControlEditor {
.custom_section_horizontal > .custom_control {
display:inline-block;
}

View File

@ -4,7 +4,7 @@
</div>
<!-- "width: 588px" to be the same as teh real Control tab-->
<div class="innerSortable" style="width: 588px; clear: both; display: none;" id="customControls" data-bind="visible: loginState.isUser, template: { name: $root.displayMode, foreach: controls }"></div>
<div class="customControlEditor innerSortable" style="width: 588px; clear: both; display: none;" id="customControls" data-bind="visible: loginState.isUser, template: { name: $root.displayMode, foreach: controls }"></div>
<ul id="controlContextMenu" class="dropdown-menu" role="menu" style="display:block;position:fixed !important;margin-bottom:5px;">
<li>

View File

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