Compare commits

..

10 Commits

Author SHA1 Message Date
Salandora
14ff4cf24d Bump version to 0.2.2 because of python 3 compatibility flag 2020-05-04 00:33:36 +02:00
Salandora
04174179c5 Python 3 compatibility 2020-05-04 00:20:32 +02:00
Salandora
5868dc2485 Merge branch 'master' of github.com:Salandora/octoprint-customControl into devel 2020-04-30 23:12:47 +02:00
Salandora
c20d234af4
Update README.md 2019-08-15 05:08:32 +02:00
Salandora
48a6ca1a40
Merge pull request #24 from razerraz/master
Ensure python3 compatibility
2019-08-15 04:56:29 +02:00
razerraz
25a1b880ad
Update setup.py 2019-02-09 09:32:06 +01:00
Salandora
7c1dca0459 Fixed #14, and some code cleanup 2018-03-05 21:29:31 +01:00
Salandora
b684644bbe Update setup.py 2015-09-08 08:17:01 +02:00
Salandora
13dbf860f0 Added forgotten file 2015-09-08 08:05:45 +02:00
Salandora
b3fabef34c Added Sorting Feature 2015-08-31 09:01:25 +02:00
8 changed files with 4362 additions and 329 deletions

View File

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

View File

@ -8,66 +8,70 @@ from octoprint.settings import settings
import octoprint.plugin
class CustomControlPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.TemplatePlugin,
octoprint.plugin.AssetPlugin):
octoprint.plugin.TemplatePlugin,
octoprint.plugin.AssetPlugin):
def get_template_configs(self):
if "editorcollection" in self._plugin_manager.enabled_plugins:
return [
dict(type="plugin_editorcollection_EditorCollection", template="customControl_hookedsettings.jinja2",
custom_bindings=True)
]
else:
return [
dict(type="settings", template="customControl_hookedsettings.jinja2", custom_bindings=True)
]
def get_settings_defaults(self):
return dict(
controls = []
)
def on_settings_load(self):
return dict(
controls=settings().get(["controls"])
)
def get_template_configs(self):
if "editorcollection" in self._plugin_manager.enabled_plugins:
return [
dict(type="plugin_editorcollection_EditorCollection", template="customControl_hookedsettings.jinja2", custom_bindings=True)
]
else:
return [
dict(type="settings", template="customControl_hookedsettings.jinja2", custom_bindings=True)
]
def on_settings_save(self, data):
settings().set(["controls"], data["controls"])
def on_settings_save(self, data):
s = settings()
s.set(["controls"], data["controls"])
def get_assets(self):
return dict(
js=[
"js/jquery.ui.sortable.js",
"js/customControl.js",
"js/customControlDialog.js",
],
css=["css/customControls.css"],
less=["less/customControls.less"]
)
def get_assets(self):
return dict(
js=[
"js/customControl.js",
"js/customControlDialog.js",
],
css=["css/customControls.css"],
less=["less/customControls.less"]
)
def get_update_information(self):
return dict(
customcontrol=dict(
displayName="Custom Control Editor Plugin",
displayVersion=self._plugin_version,
def get_update_information(self):
return dict(
customcontrol=dict(
displayName="Custom Control Editor Plugin",
displayVersion=self._plugin_version,
# version check: github repository
type="github_release",
user="Salandora",
repo="octoprint-customControl",
current=self._plugin_version,
# version check: github repository
type="github_release",
user="Salanddora",
repo="octoprint-customControl",
current=self._plugin_version,
# update method: pip
pip="https://github.com/Salandora/octoprint-customControl/archive/{target_version}.zip"
)
)
# update method: pip
pip="https://github.com/Salandora/octoprint-customControl/archive/{target_version}.zip"
)
)
__plugin_name__ = "Custom Control Editor"
__plugin_pythoncompat__ = ">=2.7,<4"
def __plugin_load__():
global __plugin_implementation__
__plugin_implementation__ = CustomControlPlugin()
global __plugin_implementation__
__plugin_implementation__ = CustomControlPlugin()
global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}
global __plugin_license__
__plugin_license__ = "AGPLv3"
global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}
global __plugin_license__
__plugin_license__ = "AGPLv3"

View File

@ -1 +1,54 @@
#customControls .custom_section_horizontal .custom_control{display:inline-block}#customControls .custom_section_vertical .custom_control{display:block}#customControls .custom_section_vertical_section{min-width:15px;min-height:15px;border:1px dashed #000}#customControls .slider.slider-disabled .slider-track{cursor:default!important}#customControls input[disabled]{background:#fff!important;cursor:text!important}#customControls .custom_section h1{cursor:pointer;display:block;width:100%;padding:0;margin-bottom:20px;font-size:21px;line-height:40px;color:#333;border:0;border-bottom:1px solid #E5E5E5;font-weight:400}
#customControls .innerSortable {
width: 100%;
min-height: 50px;
}
#customControls .custom_section_horizontal > .custom_control {
display: inline-block;
}
#customControls .custom_section_vertical > .custom_control {
display: block;
}
#customControls .custom_section_vertical_section {
min-width: 15px;
min-height: 15px;
border: 1px dashed #000000;
}
#customControls .slider.slider-disabled .slider-track {
cursor: default !important;
}
#customControls input[disabled] {
background: #fff !important;
cursor: text !important;
}
#customControls .btn-group {
margin-bottom: 10px;
}
#customControls .btn-group.distance > .btn {
width: 43px;
padding: 3px 0;
height: 30px;
}
#customControls .slider-handle {
width: 14px;
height: 14px;
margin-left: -7px;
margin-top: -3px;
}
#customControls .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: normal;
}
#customControls .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 () {
@ -56,7 +58,75 @@
// TODO: Brainstorming about how to handle additionalControls...
self.staticID = 0;
self.controls(self._processControls(undefined, self.controlsFromServer))
self.controls(undefined);
self.controls(self._processControls(undefined, self.controlsFromServer));
$(".innerSortable").sortable({
connectWith: ".innerSortable",
items: "> .sortable",
cancel: '',
sort: function (event, ui) {
var self = $(this),
width = ui.helper.outerWidth(),
top = ui.helper.position().top;//changed to ;
self.children().each(function () {
if ($(this).hasClass('ui-sortable-helper') || $(this).hasClass('ui-sortable-placeholder')) {
return true;
}
// If overlap is more than half of the dragged item
var distance = Math.abs(ui.position.left - $(this).position().left),
before = ui.position.left > $(this).position().left;
if ((width - distance) > (width / 2) && (distance < width) && $(this).position().top === top) {
if (before) {
$('.ui-sortable-placeholder', self).insertBefore($(this));
} else {
$('.ui-sortable-placeholder', self).insertAfter($(this));
}
return false;
}
});
},
update: function(event, ui) {
var target = ko.dataFor(this);
var item = ko.dataFor(ui.item[0]);
if (target === undefined) {
return;
} else {
if (target === self) {
if (!item.hasOwnProperty("children")) {
return;
}
}
else if (!target.hasOwnProperty("children")) {
return;
}
}
var position = ko.utils.arrayIndexOf(ui.item.parent().children(), ui.item[0]);
if (position >= 0) {
if (item.parent !== undefined) {
item.parent.children.remove(item);
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)
self.controlsFromServer.splice(position, 0, item);
else
target.children.splice(position, 0, item);
}
}
},
stop: function() {
self.rerenderControls();
}
}).disableSelection();
};
self._processControls = function (parent, controls) {
@ -84,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));
@ -117,7 +187,7 @@
});
return inputs;
}
};
self._processControl = function (parent, control) {
if (control.processed) {
control.id("settingsCustomControl_id" + self.staticID++);
@ -147,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);
@ -182,42 +252,42 @@
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 span + " " + offset;
return "sortable " + span + " " + offset;
};
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) {
@ -227,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"
@ -241,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"
@ -253,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"
@ -274,7 +344,7 @@
var title = "Edit Container";
var type = "container";
var data = {
parent: element.parent,
parent: element.parent
};
if (element.hasOwnProperty("name")) {
@ -357,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);
});
@ -412,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
@ -432,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)
{
@ -483,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;
@ -508,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;
}
@ -533,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();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,20 @@
#customControls {
.custom_section_horizontal .custom_control {
.innerSortable {
width: 100%;
min-height: 50px;
}
.custom_section_horizontal > .custom_control {
display:inline-block;
}
.custom_section_vertical .custom_control {
.custom_section_vertical > .custom_control {
display:block;
}
.custom_section_vertical_section {
min-width:15px;
min-height:15px;
border:1px dashed #000000;
}
@ -21,19 +27,43 @@
cursor: text !important;
}
.custom_section {
h1 {
.btn-group {
margin-bottom: 10px;
}
.btn-group.distance > .btn {
width: 43px;
padding: 3px 0;
height: 30px;
}
.slider-handle {
width: 14px;
height: 14px;
margin-left: -7px;
margin-top: -3px;
}
.custom_section {
h1 {
cursor: pointer;
display: block;
width: 100%;
padding: 0;
margin-bottom: 20px;
margin-bottom: 10px;
font-size: 21px;
line-height: 40px;
color: #333;
border: 0;
border-bottom: 1px solid #E5E5E5;
font-weight: normal;
}
font-weight: normal;
}
}
.custom_control {
.slider {
margin-left: 10px;
margin-right: 10px;
margin-bottom: 2px;
}
}
}

View File

@ -4,7 +4,7 @@
</div>
<!-- "width: 588px" to be the same as teh real Control tab-->
<div style="width: 588px; clear: both; display: none;" id="customControls" data-bind="visible: loginState.isUser, template: { name: $root.displayMode, foreach: controls }"></div>
<div class="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>
@ -47,27 +47,27 @@
<!-- Templates for custom controls -->
<script type="text/html" id="settingsCustomControls_containerTemplate_nameless">
<div class="custom_section" data-bind="contextMenu: { menuSelector: '#containerContextMenu', menuSelected: $root.controlContextMenu }, css: { 'custom_section_vertical_section': name() == '' }, attr: { 'id': id }">
<div class="custom_section sortable" data-bind="contextMenu: { menuSelector: '#containerContextMenu', menuSelected: $root.controlContextMenu }, css: { 'custom_section_vertical_section': name() == '' }, attr: { 'id': id }">
<!-- ko template: { name: 'settingsCustomControls_containerTemplate', data: $data } --><!-- /ko -->
</div>
</script>
<script type="text/html" id="settingsCustomControls_containerTemplate_collapsable">
<div class="custom_section" data-bind="contextMenu: { menuSelector: '#containerContextMenu', menuSelected: $root.controlContextMenu }, css: { 'custom_section_vertical_section': name() == '' }, attr: { 'id': id }">
<div class="custom_section sortable" data-bind="contextMenu: { menuSelector: '#containerContextMenu', menuSelected: $root.controlContextMenu }, attr: { 'id': id }">
<h1 onclick="$(this).children().first().toggleClass('icon-caret-down icon-caret-right').parent().next().slideToggle('fast')"><i data-bind="css: {'icon-caret-down': !collapsed(), 'icon-caret-right': collapsed()}"></i> <span data-bind="text: name"></span></h1>
<!-- ko template: { name: 'settingsCustomControls_containerTemplate', data: $data } --><!-- /ko -->
</div>
</script>
<script type="text/html" id="settingsCustomControls_containerTemplate">
<!-- ko if: layout() == 'vertical' -->
<div class="custom_section_vertical" data-bind="template: { name: $root.displayMode, foreach: children }, css: {hide: collapsed() && name() != '' }"></div>
<div class="custom_section_vertical innerSortable" data-bind="template: { name: $root.displayMode, foreach: children }, css: {hide: collapsed() && name() != '' }"></div>
<!-- /ko -->
<!-- ko if: layout() == 'horizontal' -->
<div class="custom_section_horizontal" data-bind="template: { name: $root.displayMode, foreach: children }, css: {hide: collapsed() && name() != '' }"></div>
<div class="custom_section_horizontal innerSortable" data-bind="template: { name: $root.displayMode, foreach: children }, css: {hide: collapsed() && name() != '' }"></div>
<!-- /ko -->
<!-- ko if: layout() == 'horizontal_grid' -->
<div class="row-fluid custom_section_horizontal_grid" data-bind="css: {hide: collapsed() && name() != ''}">
<div class="row-fluid custom_section_horizontal_grid innerSortable" data-bind="css: {hide: collapsed() && name() != ''}">
<!-- ko foreach: children -->
<div data-bind="template: { name: $root.displayMode }, css: $root.rowCss($data)"></div>
<!-- /ko -->
@ -75,7 +75,7 @@
<!-- /ko -->
</script>
<script type="text/html" id="settingsCustomControls_controlTemplate">
<form class="form-inline custom_control" style="min-height:15px; border:1px dotted #000000" data-bind="contextMenu: { menuSelector: '#commandContextMenu', menuSelected: $root.controlContextMenu }, attr: { 'id': id }">
<form class="form-inline custom_control" style="min-height:15px; border:1px dotted #000000" data-bind="contextMenu: { menuSelector: '#commandContextMenu', menuSelected: $root.controlContextMenu }, css: { 'sortable': $parent.layout() != 'horizontal_grid' }, attr: { 'id': id }">
<!-- ko template: { name: 'settingsCustomControls_controlTemplate_input', data: $data, if: $data.hasOwnProperty('input') } --><!-- /ko -->
<!-- ko template: { name: 'settingsCustomControls_controlTemplate_command', data: $data, if: $data.hasOwnProperty('command') || $data.hasOwnProperty('commands') || $data.hasOwnProperty('script') || $data.hasOwnProperty('javascript') } --><!-- /ko -->
<!-- ko template: { name: 'settingsCustomControls_controlTemplate_output', data: $data, if: $data.hasOwnProperty('value') } --><!-- /ko -->

439
setup.py
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.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
@ -27,7 +27,7 @@ plugin_description = "Makes Custom Controls editable via settings"
plugin_author = "Marc Hannappel (Salandora)"
# The plugin's author's mail address.
plugin_author_email = "sunpack@web.de"
plugin_author_email = "salandora@gmail.com"
# The plugin's homepage URL. Can be overwritten within OctoPrint's internal data via __plugin_url__ in the plugin module
plugin_url = "https://github.com/Salandora/octoprint-customControl"
@ -51,281 +51,292 @@ I18N_POT_FILE = os.path.join(I18N_OUTPUT_DIR_PY, "messages.pot")
# Requirements for out application
INSTALL_REQUIRES = [
"OctoPrint"
"OctoPrint"
]
# Requirements for developing etc
EXTRA_REQUIRES = dict(
develop=[
# Translation dependencies
"babel",
"po2json"
]
develop=[
# Translation dependencies
"babel",
"po2json"
]
)
def package_data_dirs(source, sub_folders):
import os
dirs = []
import os
dirs = []
for d in sub_folders:
folder = os.path.join(source, d)
if not os.path.exists(folder):
continue
for d in sub_folders:
folder = os.path.join(source, d)
if not os.path.exists(folder):
continue
for dirname, _, files in os.walk(folder):
dirname = os.path.relpath(dirname, source)
for f in files:
dirs.append(os.path.join(dirname, f))
for dirname, _, files in os.walk(folder):
dirname = os.path.relpath(dirname, source)
for f in files:
dirs.append(os.path.join(dirname, f))
return dirs
return dirs
def _recursively_handle_files(directory, file_matcher, folder_handler=None, file_handler=None):
applied_handler = False
applied_handler = False
for filename in os.listdir(directory):
path = os.path.join(directory, filename)
for filename in os.listdir(directory):
path = os.path.join(directory, filename)
if file_handler is not None and file_matcher(filename):
file_handler(path)
applied_handler = True
if file_handler is not None and file_matcher(filename):
file_handler(path)
applied_handler = True
elif os.path.isdir(path):
sub_applied_handler = _recursively_handle_files(path, file_matcher, folder_handler=folder_handler, file_handler=file_handler)
if sub_applied_handler:
applied_handler = True
elif os.path.isdir(path):
sub_applied_handler = _recursively_handle_files(path, file_matcher, folder_handler=folder_handler,
file_handler=file_handler)
if sub_applied_handler:
applied_handler = True
if folder_handler is not None:
folder_handler(path, sub_applied_handler)
if folder_handler is not None:
folder_handler(path, sub_applied_handler)
return applied_handler
return applied_handler
class CleanCommand(Command):
description = "clean build artifacts"
user_options = []
boolean_options = []
description = "clean build artifacts"
user_options = []
boolean_options = []
def initialize_options(self):
pass
def initialize_options(self):
pass
def finalize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import shutil
import glob
# build folder
if os.path.exists('build'):
print "Deleting build directory"
shutil.rmtree('build')
def run(self):
import shutil
import glob
# eggs
eggs = glob.glob("*.egg-info")
for egg in eggs:
print "Deleting %s directory" % egg
shutil.rmtree(egg)
# build folder
if os.path.exists('build'):
print("Deleting build directory")
shutil.rmtree('build')
# pyc files
def delete_folder_if_empty(path, applied_handler):
if not applied_handler:
return
if len(os.listdir(path)) == 0:
shutil.rmtree(path)
print "Deleted %s since it was empty" % path
# eggs
eggs = glob.glob("*.egg-info")
for egg in eggs:
print("Deleting %s directory" % egg)
shutil.rmtree(egg)
def delete_file(path):
os.remove(path)
print "Deleted %s" % path
# pyc files
def delete_folder_if_empty(path, applied_handler):
if not applied_handler:
return
if len(os.listdir(path)) == 0:
shutil.rmtree(path)
print("Deleted %s since it was empty" % path)
import fnmatch
_recursively_handle_files(
os.path.abspath(plugin_package),
lambda name: fnmatch.fnmatch(name.lower(), "*.pyc"),
folder_handler=delete_folder_if_empty,
file_handler=delete_file
)
def delete_file(path):
os.remove(path)
print("Deleted %s" % path)
# pyc files
def delete_folder_if_empty(path, applied_handler):
if not applied_handler:
return
if len(os.listdir(path)) == 0:
shutil.rmtree(path)
print "Deleted %s since it was empty" % path
import fnmatch
_recursively_handle_files(
os.path.abspath(plugin_package),
lambda name: fnmatch.fnmatch(name.lower(), "*.pyc"),
folder_handler=delete_folder_if_empty,
file_handler=delete_file
)
# pyc files
def delete_folder_if_empty(path, applied_handler):
if not applied_handler:
return
if len(os.listdir(path)) == 0:
shutil.rmtree(path)
print("Deleted %s since it was empty" % path)
def delete_file(path):
os.remove(path)
print("Deleted %s" % path)
import fnmatch
_recursively_handle_files(
os.path.abspath(plugin_package),
lambda name: fnmatch.fnmatch(name.lower(), "*.pyc"),
folder_handler=delete_folder_if_empty,
file_handler=delete_file
)
def delete_file(path):
os.remove(path)
print "Deleted %s" % path
import fnmatch
_recursively_handle_files(
os.path.abspath(plugin_package),
lambda name: fnmatch.fnmatch(name.lower(), "*.pyc"),
folder_handler=delete_folder_if_empty,
file_handler=delete_file
)
class NewTranslation(Command):
description = "create a new translation"
user_options = [
('locale=', 'l', 'locale for the new translation'),
]
boolean_options = []
description = "create a new translation"
user_options = [
('locale=', 'l', 'locale for the new translation'),
]
boolean_options = []
def __init__(self, dist, **kw):
from babel.messages import frontend as babel
self.babel_init_messages = babel.init_catalog(dist)
Command.__init__(self, dist, **kw)
def __init__(self, dist, **kw):
from babel.messages import frontend as babel
self.babel_init_messages = babel.init_catalog(dist)
Command.__init__(self, dist, **kw)
def initialize_options(self):
self.locale = None
self.babel_init_messages.initialize_options()
def initialize_options(self):
self.locale = None
self.babel_init_messages.initialize_options()
def finalize_options(self):
self.babel_init_messages.locale = self.locale
self.babel_init_messages.input_file = I18N_POT_FILE
self.babel_init_messages.output_dir = I18N_OUTPUT_DIR_PY
self.babel_init_messages.finalize_options()
def finalize_options(self):
self.babel_init_messages.locale = self.locale
self.babel_init_messages.input_file = I18N_POT_FILE
self.babel_init_messages.output_dir = I18N_OUTPUT_DIR_PY
self.babel_init_messages.finalize_options()
def run(self):
self.babel_init_messages.run()
def run(self):
self.babel_init_messages.run()
class ExtractTranslation(Command):
description = "extract translations"
user_options = []
boolean_options = []
description = "extract translations"
user_options = []
boolean_options = []
def __init__(self, dist, **kw):
from babel.messages import frontend as babel
self.babel_extract_messages = babel.extract_messages(dist)
Command.__init__(self, dist, **kw)
def __init__(self, dist, **kw):
from babel.messages import frontend as babel
self.babel_extract_messages = babel.extract_messages(dist)
Command.__init__(self, dist, **kw)
def initialize_options(self):
self.babel_extract_messages.initialize_options()
def initialize_options(self):
self.babel_extract_messages.initialize_options()
def finalize_options(self):
self.babel_extract_messages.mapping_file = I18N_MAPPING_FILE
self.babel_extract_messages.output_file = I18N_POT_FILE
self.babel_extract_messages.input_dirs = I18N_INPUT_DIRS
self.babel_extract_messages.msgid_bugs_address = plugin_author_email
self.babel_extract_messages.copyright_holder = plugin_author
self.babel_extract_messages.finalize_options()
def finalize_options(self):
self.babel_extract_messages.mapping_file = I18N_MAPPING_FILE
self.babel_extract_messages.output_file = I18N_POT_FILE
self.babel_extract_messages.input_dirs = I18N_INPUT_DIRS
self.babel_extract_messages.msgid_bugs_address = plugin_author_email
self.babel_extract_messages.copyright_holder = plugin_author
self.babel_extract_messages.finalize_options()
def run(self):
self.babel_extract_messages.run()
def run(self):
self.babel_extract_messages.run()
class RefreshTranslation(Command):
description = "refresh translations"
user_options = [
('locale=', 'l', 'locale for the translation to refresh'),
]
boolean_options = []
description = "refresh translations"
user_options = [
('locale=', 'l', 'locale for the translation to refresh'),
]
boolean_options = []
def __init__(self, dist, **kw):
from babel.messages import frontend as babel
self.babel_extract_messages = babel.extract_messages(dist)
self.babel_update_messages = babel.update_catalog(dist)
Command.__init__(self, dist, **kw)
def __init__(self, dist, **kw):
from babel.messages import frontend as babel
self.babel_extract_messages = babel.extract_messages(dist)
self.babel_update_messages = babel.update_catalog(dist)
Command.__init__(self, dist, **kw)
def initialize_options(self):
self.locale = None
self.babel_extract_messages.initialize_options()
self.babel_update_messages.initialize_options()
def initialize_options(self):
self.locale = None
self.babel_extract_messages.initialize_options()
self.babel_update_messages.initialize_options()
def finalize_options(self):
self.babel_extract_messages.mapping_file = I18N_MAPPING_FILE
self.babel_extract_messages.output_file = I18N_POT_FILE
self.babel_extract_messages.input_dirs = I18N_INPUT_DIRS
self.babel_extract_messages.msgid_bugs_address = plugin_author_email
self.babel_extract_messages.copyright_holder = plugin_author
self.babel_extract_messages.finalize_options()
def finalize_options(self):
self.babel_extract_messages.mapping_file = I18N_MAPPING_FILE
self.babel_extract_messages.output_file = I18N_POT_FILE
self.babel_extract_messages.input_dirs = I18N_INPUT_DIRS
self.babel_extract_messages.msgid_bugs_address = plugin_author_email
self.babel_extract_messages.copyright_holder = plugin_author
self.babel_extract_messages.finalize_options()
self.babel_update_messages.input_file = I18N_POT_FILE
self.babel_update_messages.output_dir = I18N_OUTPUT_DIR_PY
self.babel_update_messages.locale = self.locale
self.babel_update_messages.input_file = I18N_POT_FILE
self.babel_update_messages.output_dir = I18N_OUTPUT_DIR_PY
self.babel_update_messages.locale = self.locale
def run(self):
self.babel_extract_messages.run()
self.babel_update_messages.run()
def run(self):
self.babel_extract_messages.run()
self.babel_update_messages.run()
class CompileTranslation(Command):
description = "compile translations"
user_options = []
boolean_options = []
description = "compile translations"
user_options = []
boolean_options = []
def __init__(self, dist, **kw):
from babel.messages import frontend as babel
self.babel_compile_messages = babel.compile_catalog(dist)
Command.__init__(self, dist, **kw)
def __init__(self, dist, **kw):
from babel.messages import frontend as babel
self.babel_compile_messages = babel.compile_catalog(dist)
Command.__init__(self, dist, **kw)
def initialize_options(self):
self.babel_compile_messages.initialize_options()
def initialize_options(self):
self.babel_compile_messages.initialize_options()
def finalize_options(self):
self.babel_compile_messages.directory = I18N_OUTPUT_DIR_PY
def finalize_options(self):
self.babel_compile_messages.directory = I18N_OUTPUT_DIR_PY
def run(self):
self.babel_compile_messages.run()
def run(self):
self.babel_compile_messages.run()
import po2json
import po2json
for lang_code in os.listdir(I18N_OUTPUT_DIR_PY):
full_path = os.path.join(I18N_OUTPUT_DIR_PY, lang_code)
for lang_code in os.listdir(I18N_OUTPUT_DIR_PY):
full_path = os.path.join(I18N_OUTPUT_DIR_PY, lang_code)
if os.path.isdir(full_path):
client_po_dir = os.path.join(full_path, "LC_MESSAGES")
if os.path.isdir(full_path):
client_po_dir = os.path.join(full_path, "LC_MESSAGES")
po2json.update_js_file(
"%s/%s.po" % (client_po_dir, I18N_DOMAIN),
lang_code,
I18N_OUTPUT_DIR_JS,
I18N_DOMAIN
)
po2json.update_js_file(
"%s/%s.po" % (client_po_dir, I18N_DOMAIN),
lang_code,
I18N_OUTPUT_DIR_JS,
I18N_DOMAIN
)
def params():
# Our metadata, as defined above
name = plugin_name
version = plugin_version
description = plugin_description
author = plugin_author
author_email = plugin_author_email
url = plugin_url
license = plugin_license
cmdclass = {
'clean': CleanCommand,
'babel_new': NewTranslation,
'babel_extract': ExtractTranslation,
'babel_refresh': RefreshTranslation,
'babel_compile': CompileTranslation
};
# Our metadata, as defined above
name = plugin_name
version = plugin_version
description = plugin_description
author = plugin_author
author_email = plugin_author_email
url = plugin_url
license = plugin_license
# we only have our plugin package to install
packages = [plugin_package]
cmdclass = {
'clean': CleanCommand,
'babel_new': NewTranslation,
'babel_extract': ExtractTranslation,
'babel_refresh': RefreshTranslation,
'babel_compile': CompileTranslation
};
# we might have additional data files in sub folders that need to be installed too
package_data = {plugin_package: package_data_dirs(plugin_package, ['static', 'templates', 'translations'] + plugin_additional_data)}
include_package_data = True
# we only have our plugin package to install
packages = [plugin_package]
# If you have any package data that needs to be accessible on the file system, such as templates or static assets
# this plugin is not zip_safe.
zip_safe = False
# we might have additional data files in sub folders that need to be installed too
package_data = {plugin_package: package_data_dirs(plugin_package,
['static', 'templates', 'translations'] + plugin_additional_data)}
include_package_data = True
install_requires = INSTALL_REQUIRES
extras_require = EXTRA_REQUIRES
if os.environ.get('READTHEDOCS', None) == 'True':
# we can't tell read the docs to please perform a pip install -e .[develop], so we help
# it a bit here by explicitly adding the development dependencies, which include our
# documentation dependencies
install_requires = install_requires + extras_require['develop']
# If you have any package data that needs to be accessible on the file system, such as templates or static assets
# this plugin is not zip_safe.
zip_safe = False
# Hook the plugin into the "octoprint.plugin" entry point, mapping the plugin_identifier to the plugin_package.
# That way OctoPrint will be able to find the plugin and load it.
entry_points = {
"octoprint.plugin": ["%s = %s" % (plugin_identifier, plugin_package)]
}
install_requires = INSTALL_REQUIRES
extras_require = EXTRA_REQUIRES
return locals()
if os.environ.get('READTHEDOCS', None) == 'True':
# we can't tell read the docs to please perform a pip install -e .[develop], so we help
# it a bit here by explicitly adding the development dependencies, which include our
# documentation dependencies
install_requires = install_requires + extras_require['develop']
setup(**params())
# Hook the plugin into the "octoprint.plugin" entry point, mapping the plugin_identifier to the plugin_package.
# That way OctoPrint will be able to find the plugin and load it.
entry_points = {
"octoprint.plugin": ["%s = %s" % (plugin_identifier, plugin_package)]
}
return locals()
setup(**params())