Added Sorting Feature
This commit is contained in:
parent
7b191b3480
commit
b3fabef34c
@ -8,66 +8,70 @@ from octoprint.settings import settings
|
|||||||
|
|
||||||
import octoprint.plugin
|
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_settings_defaults(self):
|
def get_template_configs(self):
|
||||||
return dict(
|
if "editorcollection" in self._plugin_manager.enabled_plugins:
|
||||||
controls = []
|
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_template_configs(self):
|
def on_settings_save(self, data):
|
||||||
if "editorcollection" in self._plugin_manager.enabled_plugins:
|
s = settings()
|
||||||
return [
|
s.set(["controls"], data["controls"])
|
||||||
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):
|
def get_assets(self):
|
||||||
s = settings()
|
return dict(
|
||||||
s.set(["controls"], data["controls"])
|
js=[
|
||||||
|
"js/jquery.ui.sortable.js",
|
||||||
|
"js/customControl.js",
|
||||||
|
"js/customControlDialog.js",
|
||||||
|
],
|
||||||
|
css=["css/customControls.css"],
|
||||||
|
less=["less/customControls.less"]
|
||||||
|
)
|
||||||
|
|
||||||
def get_assets(self):
|
def get_update_information(self):
|
||||||
return dict(
|
return dict(
|
||||||
js=[
|
customcontrol=dict(
|
||||||
"js/customControl.js",
|
displayName="Custom Control Editor Plugin",
|
||||||
"js/customControlDialog.js",
|
displayVersion=self._plugin_version,
|
||||||
],
|
|
||||||
css=["css/customControls.css"],
|
|
||||||
less=["less/customControls.less"]
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_update_information(self):
|
# version check: github repository
|
||||||
return dict(
|
type="github_release",
|
||||||
customcontrol=dict(
|
user="Salandora",
|
||||||
displayName="Custom Control Editor Plugin",
|
repo="octoprint-customControl",
|
||||||
displayVersion=self._plugin_version,
|
current=self._plugin_version,
|
||||||
|
|
||||||
# version check: github repository
|
# update method: pip
|
||||||
type="github_release",
|
pip="https://github.com/Salandora/octoprint-customControl/archive/{target_version}.zip"
|
||||||
user="Salanddora",
|
)
|
||||||
repo="octoprint-customControl",
|
)
|
||||||
current=self._plugin_version,
|
|
||||||
|
|
||||||
# update method: pip
|
|
||||||
pip="https://github.com/Salandora/octoprint-customControl/archive/{target_version}.zip"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
__plugin_name__ = "Custom Control Editor"
|
__plugin_name__ = "Custom Control Editor"
|
||||||
|
|
||||||
|
|
||||||
def __plugin_load__():
|
def __plugin_load__():
|
||||||
global __plugin_implementation__
|
global __plugin_implementation__
|
||||||
__plugin_implementation__ = CustomControlPlugin()
|
__plugin_implementation__ = CustomControlPlugin()
|
||||||
|
|
||||||
global __plugin_hooks__
|
global __plugin_hooks__
|
||||||
__plugin_hooks__ = {
|
__plugin_hooks__ = {
|
||||||
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
|
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
|
||||||
}
|
}
|
||||||
|
|
||||||
global __plugin_license__
|
|
||||||
__plugin_license__ = "AGPLv3"
|
|
||||||
|
|
||||||
|
global __plugin_license__
|
||||||
|
__plugin_license__ = "AGPLv3"
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
@ -56,7 +56,75 @@
|
|||||||
// TODO: Brainstorming about how to handle additionalControls...
|
// TODO: Brainstorming about how to handle additionalControls...
|
||||||
|
|
||||||
self.staticID = 0;
|
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(event, ui) {
|
||||||
|
self.rerenderControls();
|
||||||
|
}
|
||||||
|
}).disableSelection();
|
||||||
};
|
};
|
||||||
|
|
||||||
self._processControls = function (parent, controls) {
|
self._processControls = function (parent, controls) {
|
||||||
@ -197,7 +265,7 @@
|
|||||||
if (customControl.hasOwnProperty("offset") && customControl.offset() != "") {
|
if (customControl.hasOwnProperty("offset") && customControl.offset() != "") {
|
||||||
offset = "offset" + customControl.offset();
|
offset = "offset" + customControl.offset();
|
||||||
}
|
}
|
||||||
return span + " " + offset;
|
return "sortable " + span + " " + offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.searchElement = function (list, id) {
|
self.searchElement = function (list, id) {
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
#customControls {
|
#customControls {
|
||||||
.custom_section_horizontal .custom_control {
|
.innerSortable {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_section_horizontal > .custom_control {
|
||||||
display:inline-block;
|
display:inline-block;
|
||||||
}
|
}
|
||||||
.custom_section_vertical .custom_control {
|
|
||||||
|
.custom_section_vertical > .custom_control {
|
||||||
display:block;
|
display:block;
|
||||||
}
|
}
|
||||||
.custom_section_vertical_section {
|
.custom_section_vertical_section {
|
||||||
@ -21,13 +27,30 @@
|
|||||||
cursor: text !important;
|
cursor: text !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.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 {
|
.custom_section {
|
||||||
h1 {
|
h1 {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 10px;
|
||||||
font-size: 21px;
|
font-size: 21px;
|
||||||
line-height: 40px;
|
line-height: 40px;
|
||||||
color: #333;
|
color: #333;
|
||||||
@ -36,4 +59,11 @@
|
|||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.custom_control {
|
||||||
|
.slider {
|
||||||
|
margin-left: 10px;
|
||||||
|
margin-right: 10px;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- "width: 588px" to be the same as teh real Control tab-->
|
<!-- "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;">
|
<ul id="controlContextMenu" class="dropdown-menu" role="menu" style="display:block;position:fixed !important;margin-bottom:5px;">
|
||||||
<li>
|
<li>
|
||||||
@ -47,27 +47,27 @@
|
|||||||
|
|
||||||
<!-- Templates for custom controls -->
|
<!-- Templates for custom controls -->
|
||||||
<script type="text/html" id="settingsCustomControls_containerTemplate_nameless">
|
<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 -->
|
<!-- ko template: { name: 'settingsCustomControls_containerTemplate', data: $data } --><!-- /ko -->
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
<script type="text/html" id="settingsCustomControls_containerTemplate_collapsable">
|
<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>
|
<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 -->
|
<!-- ko template: { name: 'settingsCustomControls_containerTemplate', data: $data } --><!-- /ko -->
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
<script type="text/html" id="settingsCustomControls_containerTemplate">
|
<script type="text/html" id="settingsCustomControls_containerTemplate">
|
||||||
<!-- ko if: layout() == 'vertical' -->
|
<!-- 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 -->
|
||||||
|
|
||||||
<!-- ko if: layout() == 'horizontal' -->
|
<!-- 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 -->
|
||||||
|
|
||||||
<!-- ko if: layout() == 'horizontal_grid' -->
|
<!-- 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 -->
|
<!-- ko foreach: children -->
|
||||||
<div data-bind="template: { name: $root.displayMode }, css: $root.rowCss($data)"></div>
|
<div data-bind="template: { name: $root.displayMode }, css: $root.rowCss($data)"></div>
|
||||||
<!-- /ko -->
|
<!-- /ko -->
|
||||||
@ -75,7 +75,7 @@
|
|||||||
<!-- /ko -->
|
<!-- /ko -->
|
||||||
</script>
|
</script>
|
||||||
<script type="text/html" id="settingsCustomControls_controlTemplate">
|
<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_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_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 -->
|
<!-- ko template: { name: 'settingsCustomControls_controlTemplate_output', data: $data, if: $data.hasOwnProperty('value') } --><!-- /ko -->
|
||||||
|
429
setup.py
429
setup.py
@ -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.1"
|
plugin_version = "0.2"
|
||||||
|
|
||||||
# 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
|
||||||
@ -27,7 +27,7 @@ plugin_description = "Makes Custom Controls editable via settings"
|
|||||||
plugin_author = "Marc Hannappel (Salandora)"
|
plugin_author = "Marc Hannappel (Salandora)"
|
||||||
|
|
||||||
# The plugin's author's mail address.
|
# 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
|
# 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"
|
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
|
# Requirements for out application
|
||||||
INSTALL_REQUIRES = [
|
INSTALL_REQUIRES = [
|
||||||
"OctoPrint"
|
"OctoPrint"
|
||||||
]
|
]
|
||||||
|
|
||||||
# Requirements for developing etc
|
# Requirements for developing etc
|
||||||
EXTRA_REQUIRES = dict(
|
EXTRA_REQUIRES = dict(
|
||||||
develop=[
|
develop=[
|
||||||
# Translation dependencies
|
# Translation dependencies
|
||||||
"babel",
|
"babel",
|
||||||
"po2json"
|
"po2json"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def package_data_dirs(source, sub_folders):
|
def package_data_dirs(source, sub_folders):
|
||||||
import os
|
import os
|
||||||
dirs = []
|
dirs = []
|
||||||
|
|
||||||
for d in sub_folders:
|
for d in sub_folders:
|
||||||
folder = os.path.join(source, d)
|
folder = os.path.join(source, d)
|
||||||
if not os.path.exists(folder):
|
if not os.path.exists(folder):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for dirname, _, files in os.walk(folder):
|
for dirname, _, files in os.walk(folder):
|
||||||
dirname = os.path.relpath(dirname, source)
|
dirname = os.path.relpath(dirname, source)
|
||||||
for f in files:
|
for f in files:
|
||||||
dirs.append(os.path.join(dirname, f))
|
dirs.append(os.path.join(dirname, f))
|
||||||
|
|
||||||
|
return dirs
|
||||||
|
|
||||||
return dirs
|
|
||||||
|
|
||||||
def _recursively_handle_files(directory, file_matcher, folder_handler=None, file_handler=None):
|
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):
|
for filename in os.listdir(directory):
|
||||||
path = os.path.join(directory, filename)
|
path = os.path.join(directory, filename)
|
||||||
|
|
||||||
if file_handler is not None and file_matcher(filename):
|
if file_handler is not None and file_matcher(filename):
|
||||||
file_handler(path)
|
file_handler(path)
|
||||||
applied_handler = True
|
applied_handler = True
|
||||||
|
|
||||||
elif os.path.isdir(path):
|
elif os.path.isdir(path):
|
||||||
sub_applied_handler = _recursively_handle_files(path, file_matcher, folder_handler=folder_handler, file_handler=file_handler)
|
sub_applied_handler = _recursively_handle_files(path, file_matcher, folder_handler=folder_handler,
|
||||||
if sub_applied_handler:
|
file_handler=file_handler)
|
||||||
applied_handler = True
|
if sub_applied_handler:
|
||||||
|
applied_handler = True
|
||||||
|
|
||||||
if folder_handler is not None:
|
if folder_handler is not None:
|
||||||
folder_handler(path, sub_applied_handler)
|
folder_handler(path, sub_applied_handler)
|
||||||
|
|
||||||
|
return applied_handler
|
||||||
|
|
||||||
return applied_handler
|
|
||||||
|
|
||||||
class CleanCommand(Command):
|
class CleanCommand(Command):
|
||||||
description = "clean build artifacts"
|
description = "clean build artifacts"
|
||||||
user_options = []
|
user_options = []
|
||||||
boolean_options = []
|
boolean_options = []
|
||||||
|
|
||||||
def initialize_options(self):
|
def initialize_options(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
import shutil
|
import shutil
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
# 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
|
||||||
def delete_folder_if_empty(path, applied_handler):
|
def delete_folder_if_empty(path, applied_handler):
|
||||||
if not applied_handler:
|
if not applied_handler:
|
||||||
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(
|
||||||
os.path.abspath(plugin_package),
|
os.path.abspath(plugin_package),
|
||||||
lambda name: fnmatch.fnmatch(name.lower(), "*.pyc"),
|
lambda name: fnmatch.fnmatch(name.lower(), "*.pyc"),
|
||||||
folder_handler=delete_folder_if_empty,
|
folder_handler=delete_folder_if_empty,
|
||||||
file_handler=delete_file
|
file_handler=delete_file
|
||||||
)
|
)
|
||||||
|
|
||||||
# pyc files
|
# pyc files
|
||||||
def delete_folder_if_empty(path, applied_handler):
|
def delete_folder_if_empty(path, applied_handler):
|
||||||
if not applied_handler:
|
if not applied_handler:
|
||||||
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
|
||||||
|
_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
|
||||||
|
)
|
||||||
|
|
||||||
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):
|
class NewTranslation(Command):
|
||||||
description = "create a new translation"
|
description = "create a new translation"
|
||||||
user_options = [
|
user_options = [
|
||||||
('locale=', 'l', 'locale for the new translation'),
|
('locale=', 'l', 'locale for the new translation'),
|
||||||
]
|
]
|
||||||
boolean_options = []
|
boolean_options = []
|
||||||
|
|
||||||
def __init__(self, dist, **kw):
|
def __init__(self, dist, **kw):
|
||||||
from babel.messages import frontend as babel
|
from babel.messages import frontend as babel
|
||||||
self.babel_init_messages = babel.init_catalog(dist)
|
self.babel_init_messages = babel.init_catalog(dist)
|
||||||
Command.__init__(self, dist, **kw)
|
Command.__init__(self, dist, **kw)
|
||||||
|
|
||||||
def initialize_options(self):
|
def initialize_options(self):
|
||||||
self.locale = None
|
self.locale = None
|
||||||
self.babel_init_messages.initialize_options()
|
self.babel_init_messages.initialize_options()
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
self.babel_init_messages.locale = self.locale
|
self.babel_init_messages.locale = self.locale
|
||||||
self.babel_init_messages.input_file = I18N_POT_FILE
|
self.babel_init_messages.input_file = I18N_POT_FILE
|
||||||
self.babel_init_messages.output_dir = I18N_OUTPUT_DIR_PY
|
self.babel_init_messages.output_dir = I18N_OUTPUT_DIR_PY
|
||||||
self.babel_init_messages.finalize_options()
|
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):
|
class ExtractTranslation(Command):
|
||||||
description = "extract translations"
|
description = "extract translations"
|
||||||
user_options = []
|
user_options = []
|
||||||
boolean_options = []
|
boolean_options = []
|
||||||
|
|
||||||
def __init__(self, dist, **kw):
|
def __init__(self, dist, **kw):
|
||||||
from babel.messages import frontend as babel
|
from babel.messages import frontend as babel
|
||||||
self.babel_extract_messages = babel.extract_messages(dist)
|
self.babel_extract_messages = babel.extract_messages(dist)
|
||||||
Command.__init__(self, dist, **kw)
|
Command.__init__(self, dist, **kw)
|
||||||
|
|
||||||
def initialize_options(self):
|
def initialize_options(self):
|
||||||
self.babel_extract_messages.initialize_options()
|
self.babel_extract_messages.initialize_options()
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
self.babel_extract_messages.mapping_file = I18N_MAPPING_FILE
|
self.babel_extract_messages.mapping_file = I18N_MAPPING_FILE
|
||||||
self.babel_extract_messages.output_file = I18N_POT_FILE
|
self.babel_extract_messages.output_file = I18N_POT_FILE
|
||||||
self.babel_extract_messages.input_dirs = I18N_INPUT_DIRS
|
self.babel_extract_messages.input_dirs = I18N_INPUT_DIRS
|
||||||
self.babel_extract_messages.msgid_bugs_address = plugin_author_email
|
self.babel_extract_messages.msgid_bugs_address = plugin_author_email
|
||||||
self.babel_extract_messages.copyright_holder = plugin_author
|
self.babel_extract_messages.copyright_holder = plugin_author
|
||||||
self.babel_extract_messages.finalize_options()
|
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):
|
class RefreshTranslation(Command):
|
||||||
description = "refresh translations"
|
description = "refresh translations"
|
||||||
user_options = [
|
user_options = [
|
||||||
('locale=', 'l', 'locale for the translation to refresh'),
|
('locale=', 'l', 'locale for the translation to refresh'),
|
||||||
]
|
]
|
||||||
boolean_options = []
|
boolean_options = []
|
||||||
|
|
||||||
def __init__(self, dist, **kw):
|
def __init__(self, dist, **kw):
|
||||||
from babel.messages import frontend as babel
|
from babel.messages import frontend as babel
|
||||||
self.babel_extract_messages = babel.extract_messages(dist)
|
self.babel_extract_messages = babel.extract_messages(dist)
|
||||||
self.babel_update_messages = babel.update_catalog(dist)
|
self.babel_update_messages = babel.update_catalog(dist)
|
||||||
Command.__init__(self, dist, **kw)
|
Command.__init__(self, dist, **kw)
|
||||||
|
|
||||||
def initialize_options(self):
|
def initialize_options(self):
|
||||||
self.locale = None
|
self.locale = None
|
||||||
self.babel_extract_messages.initialize_options()
|
self.babel_extract_messages.initialize_options()
|
||||||
self.babel_update_messages.initialize_options()
|
self.babel_update_messages.initialize_options()
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
self.babel_extract_messages.mapping_file = I18N_MAPPING_FILE
|
self.babel_extract_messages.mapping_file = I18N_MAPPING_FILE
|
||||||
self.babel_extract_messages.output_file = I18N_POT_FILE
|
self.babel_extract_messages.output_file = I18N_POT_FILE
|
||||||
self.babel_extract_messages.input_dirs = I18N_INPUT_DIRS
|
self.babel_extract_messages.input_dirs = I18N_INPUT_DIRS
|
||||||
self.babel_extract_messages.msgid_bugs_address = plugin_author_email
|
self.babel_extract_messages.msgid_bugs_address = plugin_author_email
|
||||||
self.babel_extract_messages.copyright_holder = plugin_author
|
self.babel_extract_messages.copyright_holder = plugin_author
|
||||||
self.babel_extract_messages.finalize_options()
|
self.babel_extract_messages.finalize_options()
|
||||||
|
|
||||||
self.babel_update_messages.input_file = I18N_POT_FILE
|
self.babel_update_messages.input_file = I18N_POT_FILE
|
||||||
self.babel_update_messages.output_dir = I18N_OUTPUT_DIR_PY
|
self.babel_update_messages.output_dir = I18N_OUTPUT_DIR_PY
|
||||||
self.babel_update_messages.locale = self.locale
|
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):
|
class CompileTranslation(Command):
|
||||||
description = "compile translations"
|
description = "compile translations"
|
||||||
user_options = []
|
user_options = []
|
||||||
boolean_options = []
|
boolean_options = []
|
||||||
|
|
||||||
def __init__(self, dist, **kw):
|
def __init__(self, dist, **kw):
|
||||||
from babel.messages import frontend as babel
|
from babel.messages import frontend as babel
|
||||||
self.babel_compile_messages = babel.compile_catalog(dist)
|
self.babel_compile_messages = babel.compile_catalog(dist)
|
||||||
Command.__init__(self, dist, **kw)
|
Command.__init__(self, dist, **kw)
|
||||||
|
|
||||||
def initialize_options(self):
|
def initialize_options(self):
|
||||||
self.babel_compile_messages.initialize_options()
|
self.babel_compile_messages.initialize_options()
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
self.babel_compile_messages.directory = I18N_OUTPUT_DIR_PY
|
self.babel_compile_messages.directory = I18N_OUTPUT_DIR_PY
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.babel_compile_messages.run()
|
self.babel_compile_messages.run()
|
||||||
|
|
||||||
import po2json
|
import po2json
|
||||||
|
|
||||||
for lang_code in os.listdir(I18N_OUTPUT_DIR_PY):
|
for lang_code in os.listdir(I18N_OUTPUT_DIR_PY):
|
||||||
full_path = os.path.join(I18N_OUTPUT_DIR_PY, lang_code)
|
full_path = os.path.join(I18N_OUTPUT_DIR_PY, lang_code)
|
||||||
|
|
||||||
if os.path.isdir(full_path):
|
if os.path.isdir(full_path):
|
||||||
client_po_dir = os.path.join(full_path, "LC_MESSAGES")
|
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():
|
def params():
|
||||||
# Our metadata, as defined above
|
# Our metadata, as defined above
|
||||||
name = plugin_name
|
name = plugin_name
|
||||||
version = plugin_version
|
version = plugin_version
|
||||||
description = plugin_description
|
description = plugin_description
|
||||||
author = plugin_author
|
author = plugin_author
|
||||||
author_email = plugin_author_email
|
author_email = plugin_author_email
|
||||||
url = plugin_url
|
url = plugin_url
|
||||||
license = plugin_license
|
license = plugin_license
|
||||||
|
|
||||||
cmdclass = {
|
cmdclass = {
|
||||||
'clean': CleanCommand,
|
'clean': CleanCommand,
|
||||||
'babel_new': NewTranslation,
|
'babel_new': NewTranslation,
|
||||||
'babel_extract': ExtractTranslation,
|
'babel_extract': ExtractTranslation,
|
||||||
'babel_refresh': RefreshTranslation,
|
'babel_refresh': RefreshTranslation,
|
||||||
'babel_compile': CompileTranslation
|
'babel_compile': CompileTranslation
|
||||||
};
|
};
|
||||||
|
|
||||||
# we only have our plugin package to install
|
# we only have our plugin package to install
|
||||||
packages = [plugin_package]
|
packages = [plugin_package]
|
||||||
|
|
||||||
# we might have additional data files in sub folders that need to be installed too
|
# 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)}
|
package_data = {plugin_package: package_data_dirs(plugin_package,
|
||||||
include_package_data = True
|
['static', 'templates', 'translations'] + plugin_additional_data)}
|
||||||
|
include_package_data = True
|
||||||
|
|
||||||
# If you have any package data that needs to be accessible on the file system, such as templates or static assets
|
# 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.
|
# this plugin is not zip_safe.
|
||||||
zip_safe = False
|
zip_safe = False
|
||||||
|
|
||||||
install_requires = INSTALL_REQUIRES
|
install_requires = INSTALL_REQUIRES
|
||||||
extras_require = EXTRA_REQUIRES
|
extras_require = EXTRA_REQUIRES
|
||||||
|
|
||||||
if os.environ.get('READTHEDOCS', None) == 'True':
|
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
|
# 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
|
# it a bit here by explicitly adding the development dependencies, which include our
|
||||||
# documentation dependencies
|
# documentation dependencies
|
||||||
install_requires = install_requires + extras_require['develop']
|
install_requires = install_requires + extras_require['develop']
|
||||||
|
|
||||||
# Hook the plugin into the "octoprint.plugin" entry point, mapping the plugin_identifier to the plugin_package.
|
# 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.
|
# That way OctoPrint will be able to find the plugin and load it.
|
||||||
entry_points = {
|
entry_points = {
|
||||||
"octoprint.plugin": ["%s = %s" % (plugin_identifier, plugin_package)]
|
"octoprint.plugin": ["%s = %s" % (plugin_identifier, plugin_package)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return locals()
|
||||||
|
|
||||||
return locals()
|
|
||||||
|
|
||||||
setup(**params())
|
setup(**params())
|
Loading…
Reference in New Issue
Block a user