From 4f37707acb68a92004d5dad0282476d81315bdbe Mon Sep 17 00:00:00 2001 From: ntoff Date: Fri, 10 Nov 2017 00:22:35 +1000 Subject: [PATCH] Update icon + add command setting Update icon to new FA icon to be compatible with octoprint 1.3.5's move to an update font awesome Add a setting to allow changing of the command in situations where the user may wish to issue some other command other than M112 --- octoprint_estop/__init__.py | 17 ++++++++++++++--- octoprint_estop/static/js/estop.js | 16 ++++++++++++++-- octoprint_estop/templates/estop_settings.jinja2 | 13 +++++++++++++ octoprint_estop/templates/estop_sidebar.jinja2 | 2 +- 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 octoprint_estop/templates/estop_settings.jinja2 diff --git a/octoprint_estop/__init__.py b/octoprint_estop/__init__.py index 15b7c29..5a45f1b 100644 --- a/octoprint_estop/__init__.py +++ b/octoprint_estop/__init__.py @@ -3,8 +3,18 @@ from __future__ import absolute_import import octoprint.plugin -class EstopPlugin(octoprint.plugin.AssetPlugin, - octoprint.plugin.TemplatePlugin): +class EstopPlugin(octoprint.plugin.StartupPlugin, + octoprint.plugin.AssetPlugin, + octoprint.plugin.TemplatePlugin, + octoprint.plugin.SettingsPlugin): + + def get_settings_defaults(self): + return dict(estopCommand = "M112") + + def on_after_startup(self): + self.estopCommand = self._settings.get(["estopCommand"]) + if (self.estopCommand != "M112"): + self._logger.warn("WARNING! EMERGENCY STOP COMMAND HAS BEEN CHANGED FROM DEFAULT \"M112\" TO \"" + self.estopCommand + "\"") def get_assets(self): return dict( @@ -13,7 +23,8 @@ class EstopPlugin(octoprint.plugin.AssetPlugin, ) def get_template_configs(self): return [ - dict(type="sidebar", name="Emergency STOP!", icon="fa icon-print", template="estop_sidebar.jinja2", styles=["display: none"], data_bind="visible: loginState.isUser") + dict(type="sidebar", name="Emergency STOP!", icon="fa fa-print", template="estop_sidebar.jinja2", styles=["display: none"], data_bind="visible: loginState.isUser"), + dict(type="settings", name="E-Stop Settings", template="estop_settings.jinja2", custom_bindings=False) ] def get_update_information(self): diff --git a/octoprint_estop/static/js/estop.js b/octoprint_estop/static/js/estop.js index 8d0c86f..6020dd4 100644 --- a/octoprint_estop/static/js/estop.js +++ b/octoprint_estop/static/js/estop.js @@ -8,6 +8,9 @@ $(function() { self.loginState = parameters[0]; self.printerState = parameters[1]; + self.settings = parameters[2]; + + self.estopCommand = ko.observable("M112"); self.enableEstop = ko.pureComputed(function() { return self.printerState.isOperational() && self.loginState.isUser(); @@ -25,9 +28,18 @@ $(function() { } }); + self.buttonTitle = ko.pureComputed(function() { + self.estopCommand(self.settings.settings.plugins.estop.estopCommand()); + return gettext("Sends " + self.estopCommand() + " to the printer IMMEDIATELY"); + }); + + self.onBeforeBinding = function () { + //self.estopCommand(self.settings.settings.plugins.estop.estopCommand()); + } self.sendEstopCommand = function () { if (self.enableEstop()) { - OctoPrint.control.sendGcode("M112"); + self.estopCommand(self.settings.settings.plugins.estop.estopCommand()); + OctoPrint.control.sendGcode(self.estopCommand()); }; }; } @@ -37,7 +49,7 @@ $(function() { dependencies: [ "loginStateViewModel", "printerStateViewModel", - ], + "settingsViewModel"], elements: ["#sidebar_plugin_estop_wrapper"] }); }); diff --git a/octoprint_estop/templates/estop_settings.jinja2 b/octoprint_estop/templates/estop_settings.jinja2 new file mode 100644 index 0000000..03937d2 --- /dev/null +++ b/octoprint_estop/templates/estop_settings.jinja2 @@ -0,0 +1,13 @@ +

{{ _('E-Stop Settings') }}

+
+

Here you can change the command issued to your printer when you press the emergency stop button.

+
+
+ +
+ + Usually this is M112. Only change if you know what you're doing. +
+
+
+
diff --git a/octoprint_estop/templates/estop_sidebar.jinja2 b/octoprint_estop/templates/estop_sidebar.jinja2 index 3804e23..beb8a3f 100644 --- a/octoprint_estop/templates/estop_sidebar.jinja2 +++ b/octoprint_estop/templates/estop_sidebar.jinja2 @@ -1,4 +1,4 @@