├── demo.gif ├── LICENSE.txt ├── README.md └── main.js /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NII-cloud-operation/Jupyter-code_cell_status/master/demo.gif -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, National Institute of Informatics. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of National Institute of Informatics nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | According to the code cell status "output_area.prompt_overlay" is colored. 4 | Light Cyan, Linen and Pink represent "running", "finished successfully" and "finished with errors" respectively. 5 | 6 | # Setup 7 | 8 | ## 1. Installation 9 | 10 | 1. make the `nbextensions` folder to `~/.ipython/` 11 | 2. copy the `code_cell_status` folder to `~/.ipython/nbextensions/` 12 | 13 | ## 2. Configuration 14 | 15 | 1. make (or edit) youre `~/.jupyter/nbconfig/notebook.json` file 16 | 17 | ``` 18 | { 19 | "load_extensions": { 20 | "code_cell_status/main": true 21 | } 22 | } 23 | ``` 24 | 25 | 1. Edit the .jupyter/jupyter_notebook.json to look like this 26 | 27 | ``` 28 | { 29 | "Exporter": { 30 | "preprocessors": [ 31 | "pre_codefolding.CodeFoldingPreprocessor", 32 | "pre_pymarkdown.PyMarkdownPreprocessor" 33 | ] 34 | }, 35 | "NbConvertApp": { 36 | "postprocessor_class": "post_embedhtml.EmbedPostProcessor" 37 | }, 38 | "NotebookApp": { 39 | "server_extensions": [ 40 | "nbextensions" 41 | ] 42 | }, 43 | "version": 1 44 | } 45 | ``` 46 | 47 | Edit the .jupyter/jupyter_nbconvert.json to look like this: 48 | 49 | ``` 50 | { 51 | "Exporter": { 52 | "preprocessors": [ 53 | "pre_codefolding.CodeFoldingPreprocessor", 54 | "pre_pymarkdown.PyMarkdownPreprocessor" 55 | ] 56 | }, 57 | "NbConvertApp": { 58 | "postprocessor_class": "post_embedhtml.EmbedPostProcessor" 59 | }, 60 | "version": 1 61 | } 62 | ``` 63 | # Usage 64 | 65 | ![demo](https://raw.githubusercontent.com/NII-cloud-operation/Jupyter-code_cell_status/master/demo.gif) 66 | 67 | # License 68 | 69 | This project is licensed under the terms of the Modified BSD License (also known as New or Revised or 3-Clause BSD), see LICENSE.txt. 70 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'base/js/namespace', 3 | 'jquery', 4 | 'require', 5 | 'base/js/events', 6 | 'codemirror/lib/codemirror', 7 | 'codemirror/addon/fold/foldgutter', 8 | ], function(IPython, $, require, events, codemirror) { 9 | "use strict"; 10 | 11 | function changeColor(first, cell, msg){ 12 | var outback = cell.output_area.prompt_overlay; 13 | var inback = cell.input[0].firstChild; 14 | 15 | if(first == true){ 16 | $(outback).css({"background-color":"#e0ffff"});//現在のセルを予約色に変更 17 | $(inback).css({"background-color":"#e0ffff"}); 18 | } 19 | else{ 20 | if (msg.content.status != "ok" && msg.content.status != "aborted") { 21 | $(outback).css({"background-color": "#ffc0cb"}); //現在のセルを警告色に変更 22 | $(inback).css({"background-color": "#ffc0cb"}); 23 | } else if (msg.content.status != "aborted") { 24 | $(outback).css({"background-color": "#faf0e6"}); //現在のセルを完了色に変更 25 | $(inback).css({"background-color": "#faf0e6"}); 26 | } 27 | } 28 | } 29 | 30 | /** 31 | * Called after extension was loaded 32 | * 33 | */ 34 | var code_cell_status = function() { 35 | 36 | IPython.CodeCell.prototype.execute = function (stop_on_error) { 37 | if (!this.kernel || !this.kernel.is_connected()) { 38 | console.log("Can't execute, kernel is not connected."); 39 | return; 40 | } 41 | 42 | this.output_area.clear_output(false, true); 43 | 44 | if (stop_on_error === undefined) { 45 | stop_on_error = true; 46 | } 47 | 48 | var old_msg_id = this.last_msg_id; 49 | 50 | if (old_msg_id) { 51 | this.kernel.clear_callbacks_for_msg(old_msg_id); 52 | if (old_msg_id) { 53 | delete IPython.CodeCell.msg_cells[old_msg_id]; 54 | } 55 | } 56 | if (this.get_text().trim().length === 0) { 57 | // nothing to do 58 | this.set_input_prompt(null); 59 | return; 60 | } 61 | this.set_input_prompt('*'); 62 | this.element.addClass("running"); 63 | 64 | changeColor(true, this); 65 | 66 | var callbacks = this.get_callbacks(); 67 | 68 | this.last_msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false, store_history: true, 69 | stop_on_error : stop_on_error}); 70 | IPython.CodeCell.msg_cells[this.last_msg_id] = this; 71 | this.render(); 72 | this.events.trigger('execute.CodeCell', {cell: this}); 73 | }; 74 | 75 | IPython.CodeCell.prototype._handle_execute_reply = function (msg) { 76 | this.set_input_prompt(msg.content.execution_count); 77 | var cells = IPython.notebook.get_cells(); 78 | 79 | changeColor(false, this, msg); 80 | 81 | this.element.removeClass("running"); 82 | this.events.trigger('set_dirty.Notebook', {value: true}); 83 | }; 84 | }; 85 | 86 | return { load_ipython_extension : code_cell_status }; 87 | }); 88 | --------------------------------------------------------------------------------