diff --git a/octoprint/server.py b/octoprint/server.py index 80dacbb..ba807eb 100644 --- a/octoprint/server.py +++ b/octoprint/server.py @@ -9,6 +9,7 @@ import tornadio2 import os import threading import logging, logging.config +import subprocess from octoprint.printer import Printer, getConnectionOptions from octoprint.settings import settings @@ -30,8 +31,9 @@ def index(): return render_template( "index.html", webcamStream=settings().get(["webcam", "stream"]), - enableTimelapse=(settings().get(["webcam", "snapshot"]) is not None and settings().get(["webcam", "ffmpeg"]) is not None), - enableGCodeVisualizer=settings().get(["feature", "gCodeVisualizer"]) + enableTimelapse=settings().get(["webcam", "snapshot"]) is not None and settings().get(["webcam", "ffmpeg"]) is not None, + enableGCodeVisualizer=settings().get(["feature", "gCodeVisualizer"]), + enableSystemMenu=settings().get(["system"]) is not None and settings().get(["system", "actions"]) is not None and len(settings().get(["system", "actions"])) > 0 ) #~~ Printer state @@ -364,6 +366,9 @@ def getSettings(): }, "temperature": { "profiles": s.get(["temperature", "profiles"]) + }, + "system": { + "actions": s.get(["system", "actions"]) } }) @@ -403,10 +408,34 @@ def setSettings(): if "temperature" in data.keys(): if "profiles" in data["temperature"].keys(): s.set(["temperature", "profiles"], data["temperature"]["profiles"]) + if "system" in data.keys(): + if "actions" in data["system"].keys(): s.set(["system", "actions"], data["system"]["actions"]) + s.save() return getSettings() +#~~ system control + +@app.route(BASEURL + "system", methods=["POST"]) +def performSystemAction(): + logger = logging.getLogger(__name__) + if request.values.has_key("action"): + action = request.values["action"] + availableActions = settings().get(["system", "actions"]) + for availableAction in availableActions: + if availableAction["action"] == action: + logger.info("Performing command: %s" % availableAction["command"]) + try: + subprocess.check_output(availableAction["command"]) + except subprocess.CalledProcessError, e: + logger.warn("Command failed with return code %i: %s" % (e.returncode, e.message)) + return app.make_response(("Command failed with return code %i: %s" % (e.returncode, e.message), 500, [])) + except Exception, ex: + logger.exception("Command failed") + return app.make_response(("Command failed: %r" % ex, 500, [])) + return jsonify(SUCCESS) + #~~ startup code def run(host = "0.0.0.0", port = 5000, debug = False): diff --git a/octoprint/settings.py b/octoprint/settings.py index 2b096bc..86eb988 100644 --- a/octoprint/settings.py +++ b/octoprint/settings.py @@ -61,13 +61,16 @@ default_settings.update({ "z": 200, "e": 300 } - }, + }, "temperature": { "profiles": [ {"name": "ABS", "extruder" : 210, "bed" : 100 }, {"name": "PLA", "extruder" : 180, "bed" : 60 } ] + }, + "system": { + "actions": [] } }) diff --git a/octoprint/static/css/jquery.pnotify.default.css b/octoprint/static/css/jquery.pnotify.default.css new file mode 100644 index 0000000..de1068a --- /dev/null +++ b/octoprint/static/css/jquery.pnotify.default.css @@ -0,0 +1,83 @@ +/* +Document : jquery.pnotify.default.css +Created on : Nov 23, 2009, 3:14:10 PM +Author : Hunter Perrin +Version : 1.2.0 +Link : http://pinesframework.org/pnotify/ +Description: + Default styling for Pines Notify jQuery plugin. +*/ +/* -- Notice */ +.ui-pnotify { +top: 25px; +right: 25px; +position: absolute; +height: auto; +/* Ensures notices are above everything */ +z-index: 9999; +} +/* Hides position: fixed from IE6 */ +html > body .ui-pnotify { +position: fixed; +} +.ui-pnotify .ui-pnotify-shadow { +-webkit-box-shadow: 0px 2px 10px rgba(50, 50, 50, 0.5); +-moz-box-shadow: 0px 2px 10px rgba(50, 50, 50, 0.5); +box-shadow: 0px 2px 10px rgba(50, 50, 50, 0.5); +} +.ui-pnotify-container { +background-position: 0 0; +padding: .8em; +height: 100%; +margin: 0; +} +.ui-pnotify-sharp { +-webkit-border-radius: 0; +-moz-border-radius: 0; +border-radius: 0; +} +.ui-pnotify-closer, .ui-pnotify-sticker { +float: right; +margin-left: .2em; +} +.ui-pnotify-title { +display: block; +margin-bottom: .4em; +} +.ui-pnotify-text { +display: block; +} +.ui-pnotify-icon, .ui-pnotify-icon span { +display: block; +float: left; +margin-right: .2em; +} +/* -- History Pulldown */ +.ui-pnotify-history-container { +position: absolute; +top: 0; +right: 18px; +width: 70px; +border-top: none; +padding: 0; +-webkit-border-top-left-radius: 0; +-moz-border-top-left-radius: 0; +border-top-left-radius: 0; +-webkit-border-top-right-radius: 0; +-moz-border-top-right-radius: 0; +border-top-right-radius: 0; +/* Ensures history container is above notices. */ +z-index: 10000; +} +.ui-pnotify-history-container .ui-pnotify-history-header { +padding: 2px; +} +.ui-pnotify-history-container button { +cursor: pointer; +display: block; +width: 100%; +} +.ui-pnotify-history-container .ui-pnotify-history-pulldown { +display: block; +margin: 0 auto; +} \ No newline at end of file diff --git a/octoprint/static/css/octoprint.less b/octoprint/static/css/octoprint.less index f2169ea..ce1be6c 100644 --- a/octoprint/static/css/octoprint.less +++ b/octoprint/static/css/octoprint.less @@ -23,6 +23,18 @@ body { .brand, .nav>li>a { .navbar-inner-text(@base); } + + .nav { + li.dropdown.open>.dropdown-toggle, li.dropdown.active>.dropdown-toggle, li.dropdown.open.active>.dropdown-toggle { + // invert for dropdown + background-color: @base; /* fallback color if gradients are not supported */ + background-image: -webkit-linear-gradient(top, @bottom, @top); /* For Chrome and Safari */ + background-image: -moz-linear-gradient(top, @bottom, @top); /* For old Fx (3.6 to 15) */ + background-image: -ms-linear-gradient(top, @bottom, @top); /* For pre-releases of IE 10*/ + background-image: -o-linear-gradient(top, @bottom, @top); /* For old Opera (11.1 to 12.0) */ + background-image: linear-gradient(to bottom, @bottom, @top); /* Standard syntax; must be last */ + } + } } #navbar .navbar-inner { diff --git a/octoprint/static/js/jquery.pnotify.min.js b/octoprint/static/js/jquery.pnotify.min.js new file mode 100644 index 0000000..8017939 --- /dev/null +++ b/octoprint/static/js/jquery.pnotify.min.js @@ -0,0 +1,40 @@ +/* + * jQuery Pines Notify (pnotify) Plugin 1.2.0 + * + * http://pinesframework.org/pnotify/ + * Copyright (c) 2009-2012 Hunter Perrin + * + * Triple license under the GPL, LGPL, and MPL: + * http://www.gnu.org/licenses/gpl.html + * http://www.gnu.org/licenses/lgpl.html + * http://www.mozilla.org/MPL/MPL-1.1.html + */ +(function(d){var q,j,r,i=d(window),u={jqueryui:{container:"ui-widget ui-widget-content ui-corner-all",notice:"ui-state-highlight",notice_icon:"ui-icon ui-icon-info",info:"",info_icon:"ui-icon ui-icon-info",success:"ui-state-default",success_icon:"ui-icon ui-icon-circle-check",error:"ui-state-error",error_icon:"ui-icon ui-icon-alert",closer:"ui-icon ui-icon-close",pin_up:"ui-icon ui-icon-pin-w",pin_down:"ui-icon ui-icon-pin-s",hi_menu:"ui-state-default ui-corner-bottom",hi_btn:"ui-state-default ui-corner-all", +hi_btnhov:"ui-state-hover",hi_hnd:"ui-icon ui-icon-grip-dotted-horizontal"},bootstrap:{container:"alert",notice:"",notice_icon:"icon-exclamation-sign",info:"alert-info",info_icon:"icon-info-sign",success:"alert-success",success_icon:"icon-ok-sign",error:"alert-error",error_icon:"icon-warning-sign",closer:"icon-remove",pin_up:"icon-pause",pin_down:"icon-play",hi_menu:"well",hi_btn:"btn",hi_btnhov:"",hi_hnd:"icon-chevron-down"}},s=function(){r=d("body");i=d(window);i.bind("resize",function(){j&&clearTimeout(j); +j=setTimeout(d.pnotify_position_all,10)})};document.body?s():d(s);d.extend({pnotify_remove_all:function(){var e=i.data("pnotify");e&&e.length&&d.each(e,function(){this.pnotify_remove&&this.pnotify_remove()})},pnotify_position_all:function(){j&&clearTimeout(j);j=null;var e=i.data("pnotify");e&&e.length&&(d.each(e,function(){var d=this.opts.stack;if(d)d.nextpos1=d.firstpos1,d.nextpos2=d.firstpos2,d.addpos2=0,d.animation=true}),d.each(e,function(){this.pnotify_position()}))},pnotify:function(e){var g, +a;typeof e!="object"?(a=d.extend({},d.pnotify.defaults),a.text=e):a=d.extend({},d.pnotify.defaults,e);for(var p in a)typeof p=="string"&&p.match(/^pnotify_/)&&(a[p.replace(/^pnotify_/,"")]=a[p]);if(a.before_init&&a.before_init(a)===false)return null;var k,o=function(a,c){b.css("display","none");var f=document.elementFromPoint(a.clientX,a.clientY);b.css("display","block");var e=d(f),g=e.css("cursor");b.css("cursor",g!="auto"?g:"default");if(!k||k.get(0)!=f)k&&(n.call(k.get(0),"mouseleave",a.originalEvent), +n.call(k.get(0),"mouseout",a.originalEvent)),n.call(f,"mouseenter",a.originalEvent),n.call(f,"mouseover",a.originalEvent);n.call(f,c,a.originalEvent);k=e},f=u[a.styling],b=d("
",{"class":"ui-pnotify "+a.addclass,css:{display:"none"},mouseenter:function(l){a.nonblock&&l.stopPropagation();a.mouse_reset&&g=="out"&&(b.stop(true),g="in",b.css("height","auto").animate({width:a.width,opacity:a.nonblock?a.nonblock_opacity:a.opacity},"fast"));a.nonblock&&b.animate({opacity:a.nonblock_opacity},"fast"); +a.hide&&a.mouse_reset&&b.pnotify_cancel_remove();a.sticker&&!a.nonblock&&b.sticker.trigger("pnotify_icon").css("visibility","visible");a.closer&&!a.nonblock&&b.closer.css("visibility","visible")},mouseleave:function(l){a.nonblock&&l.stopPropagation();k=null;b.css("cursor","auto");a.nonblock&&g!="out"&&b.animate({opacity:a.opacity},"fast");a.hide&&a.mouse_reset&&b.pnotify_queue_remove();a.sticker_hover&&b.sticker.css("visibility","hidden");a.closer_hover&&b.closer.css("visibility","hidden");d.pnotify_position_all()}, +mouseover:function(b){a.nonblock&&b.stopPropagation()},mouseout:function(b){a.nonblock&&b.stopPropagation()},mousemove:function(b){a.nonblock&&(b.stopPropagation(),o(b,"onmousemove"))},mousedown:function(b){a.nonblock&&(b.stopPropagation(),b.preventDefault(),o(b,"onmousedown"))},mouseup:function(b){a.nonblock&&(b.stopPropagation(),b.preventDefault(),o(b,"onmouseup"))},click:function(b){a.nonblock&&(b.stopPropagation(),o(b,"onclick"))},dblclick:function(b){a.nonblock&&(b.stopPropagation(),o(b,"ondblclick"))}}); +b.opts=a;b.container=d("",{"class":f.container+" ui-pnotify-container "+(a.type=="error"?f.error:a.type=="info"?f.info:a.type=="success"?f.success:f.notice)}).appendTo(b);a.cornerclass!=""&&b.container.removeClass("ui-corner-all").addClass(a.cornerclass);a.shadow&&b.container.addClass("ui-pnotify-shadow");b.pnotify_version="1.2.0";b.pnotify=function(l){var c=a;typeof l=="string"?a.text=l:a=d.extend({},a,l);for(var e in a)typeof e=="string"&&e.match(/^pnotify_/)&&(a[e.replace(/^pnotify_/,"")]= +a[e]);b.opts=a;a.cornerclass!=c.cornerclass&&b.container.removeClass("ui-corner-all").addClass(a.cornerclass);a.shadow!=c.shadow&&(a.shadow?b.container.addClass("ui-pnotify-shadow"):b.container.removeClass("ui-pnotify-shadow"));a.addclass===false?b.removeClass(c.addclass):a.addclass!==c.addclass&&b.removeClass(c.addclass).addClass(a.addclass);a.title===false?b.title_container.slideUp("fast"):a.title!==c.title&&(a.title_escape?b.title_container.text(a.title).slideDown(200):b.title_container.html(a.title).slideDown(200)); +a.text===false?b.text_container.slideUp("fast"):a.text!==c.text&&(a.text_escape?b.text_container.text(a.text).slideDown(200):b.text_container.html(a.insert_brs?String(a.text).replace(/\n/g,"The command \"" + action.name + "\" could not be executed.
Reason:
" + jqXHR.responseText + "", type: "error"}); + } + }) + } + if (action.confirm) { + $("#confirmation_dialog .confirmation_dialog_message").text(action.confirm); + $("#confirmation_dialog .confirmation_dialog_acknowledge").click(function(e) {e.preventDefault(); $("#confirmation_dialog").modal("hide"); callback(); }); + $("#confirmation_dialog").modal("show"); + } else { + callback(); + } + } +} + function DataUpdater(connectionViewModel, printerStateViewModel, temperatureViewModel, controlsViewModel, speedViewModel, terminalViewModel, gcodeFilesViewModel, webcamViewModel, gcodeViewModel) { var self = this; @@ -1370,6 +1386,27 @@ function ItemListHelper(listType, supportedSorting, supportedFilters, defaultSor self._loadCurrentSortingFromLocalStorage(); } +function AppearanceViewModel(settingsViewModel) { + var self = this; + + self.name = settingsViewModel.appearance_name; + self.color = settingsViewModel.appearance_color; + + self.brand = ko.computed(function() { + if (self.name()) + return "OctoPrint: " + self.name(); + else + return "OctoPrint"; + }) + + self.title = ko.computed(function() { + if (self.name()) + return self.name() + " [OctoPrint]"; + else + return "OctoPrint"; + }) +} + $(function() { //~~ View models @@ -1384,6 +1421,7 @@ $(function() { var gcodeFilesViewModel = new GcodeFilesViewModel(); var webcamViewModel = new WebcamViewModel(); var gcodeViewModel = new GcodeViewModel(); + var navigationViewModel = new NavigationViewModel(appearanceViewModel, settingsViewModel); var dataUpdater = new DataUpdater( connectionViewModel, @@ -1566,7 +1604,7 @@ $(function() { ko.applyBindings(speedViewModel, document.getElementById("speed")); ko.applyBindings(gcodeViewModel, document.getElementById("gcode")); ko.applyBindings(settingsViewModel, document.getElementById("settings_dialog")); - ko.applyBindings(appearanceViewModel, document.getElementById("navbar")); + ko.applyBindings(navigationViewModel, document.getElementById("navbar")); ko.applyBindings(appearanceViewModel, document.getElementsByTagName("head")[0]); var webcamElement = document.getElementById("webcam"); @@ -1597,6 +1635,8 @@ $(function() { } }) + $.pnotify.defaults.history = false; + } ); diff --git a/octoprint/templates/dialogs.html b/octoprint/templates/dialogs.html new file mode 100644 index 0000000..6c95967 --- /dev/null +++ b/octoprint/templates/dialogs.html @@ -0,0 +1,33 @@ +
+ The server appears to be offline, at least I'm not getting any response from it. I'll try to reconnect + automatically over the next couple of minutes, however you are welcome to try a manual reconnect + anytime using the button below. +
+ +