##// END OF EJS Templates
Some code cleanup in javascript and python...
Matthias Bussonnier -
Show More
@@ -243,8 +243,6 b' class InteractiveShell(SingletonConfigurable):'
243 243 """
244 244 )
245 245
246 banner = Unicode('')
247
248 246 banner1 = Unicode(default_banner, config=True,
249 247 help="""The part of the banner to be printed before the profile"""
250 248 )
@@ -1,8 +1,7 b''
1 1 // Copyright (c) IPython Development Team.
2 2 // Distributed under the terms of the Modified BSD License.
3 3
4 define(['require'
5 ], function(require) {
4 define(function(require){
6 5 "use strict";
7 6
8 7 var ActionHandler = function (env) {
@@ -36,7 +35,7 b" define(['require'"
36 35 * but is considered undefined behavior.
37 36 *
38 37 **/
39 var _action = {
38 var _actions = {
40 39 'run-select-next': {
41 40 icon: 'fa-play',
42 41 help : 'run cell, select below',
@@ -387,31 +386,36 b" define(['require'"
387 386 // Will actually generate/register all the IPython actions
388 387 var fun = function(){
389 388 var final_actions = {};
390 for(var k in _action){
391 // Js closure are function level not block level need to wrap in a IIFE
392 // and append ipython to event name these things do intercept event so are wrapped
393 // in a function that return false.
394 var handler = _prepare_handler(final_actions, k, _action);
395 (function(key, handler){
396 final_actions['ipython.'+key].handler = function(env, event){
397 handler(env);
398 if(event){
399 event.preventDefault();
400 }
401 return false;
402 };
403 })(k, handler);
389 var k;
390 for(k in _actions){
391 if(_actions.hasOwnProperty(k)){
392 // Js closure are function level not block level need to wrap in a IIFE
393 // and append ipython to event name these things do intercept event so are wrapped
394 // in a function that return false.
395 var handler = _prepare_handler(final_actions, k, _actions);
396 (function(key, handler){
397 final_actions['ipython.'+key].handler = function(env, event){
398 handler(env);
399 if(event){
400 event.preventDefault();
401 }
402 return false;
403 };
404 })(k, handler);
405 }
404 406 }
405 407
406 for(var k in custom_ignore){
408 for(k in custom_ignore){
407 409 // Js closure are function level not block level need to wrap in a IIFE
408 410 // same as above, but decide for themselves wether or not they intercept events.
409 var handler = _prepare_handler(final_actions, k, custom_ignore);
410 (function(key, handler){
411 final_actions['ipython.'+key].handler = function(env, event){
412 return handler(env, event);
413 };
414 })(k, handler);
411 if(custom_ignore.hasOwnProperty(k)){
412 var handler = _prepare_handler(final_actions, k, custom_ignore);
413 (function(key, handler){
414 final_actions['ipython.'+key].handler = function(env, event){
415 return handler(env, event);
416 };
417 })(k, handler);
418 }
415 419 }
416 420
417 421 return final_actions;
@@ -40,7 +40,7 b' define(['
40 40 var Cell = cell.Cell;
41 41
42 42 /* local util for codemirror */
43 var posEq = function(a, b) {return a.line == b.line && a.ch == b.ch;};
43 var posEq = function(a, b) {return a.line === b.line && a.ch === b.ch;};
44 44
45 45 /**
46 46 *
@@ -332,7 +332,7 b' define(['
332 332 // whatever key is pressed, first, cancel the tooltip request before
333 333 // they are sent, and remove tooltip if any, except for tab again
334 334 var tooltip_closed = null;
335 if (event.type === 'keydown' && event.which != keycodes.tab ) {
335 if (event.type === 'keydown' && event.which !== keycodes.tab ) {
336 336 tooltip_closed = this.tooltip.remove_and_cancel_tooltip();
337 337 }
338 338
@@ -366,7 +366,7 b' define(['
366 366 if (editor.somethingSelected() || editor.getSelections().length !== 1){
367 367 var anchor = editor.getCursor("anchor");
368 368 var head = editor.getCursor("head");
369 if( anchor.line != head.line){
369 if( anchor.line !== head.line){
370 370 return false;
371 371 }
372 372 }
@@ -374,7 +374,7 b' define(['
374 374 event.codemirrorIgnore = true;
375 375 event.preventDefault();
376 376 return true;
377 } else if (event.keyCode === keycodes.tab && event.type == 'keydown') {
377 } else if (event.keyCode === keycodes.tab && event.type === 'keydown') {
378 378 // Tab completion.
379 379 this.tooltip.remove_and_cancel_tooltip();
380 380
@@ -371,7 +371,6 b' define(['
371 371 * Set the 'Download as foo' menu option for the relevant language.
372 372 */
373 373 var el = this.element.find('#download_script');
374 var that = this;
375 374
376 375 // Set menu entry text to e.g. "Python (.py)"
377 376 var langname = (langinfo.name || 'Script')
@@ -347,7 +347,7 b' define(['
347 347 if (value === undefined) {
348 348 value = true;
349 349 }
350 if (this.dirty == value) {
350 if (this.dirty === value) {
351 351 return;
352 352 }
353 353 this.events.trigger('set_dirty.Notebook', {value: value});
@@ -1792,7 +1792,7 b' define(['
1792 1792 cell_data = new_cells[i];
1793 1793 new_cell = this.insert_cell_at_index(cell_data.cell_type, i);
1794 1794 new_cell.fromJSON(cell_data);
1795 if (new_cell.cell_type == 'code' && !new_cell.output_area.trusted) {
1795 if (new_cell.cell_type === 'code' && !new_cell.output_area.trusted) {
1796 1796 trusted = false;
1797 1797 }
1798 1798 }
@@ -1818,7 +1818,7 b' define(['
1818 1818 var trusted = true;
1819 1819 for (var i=0; i<ncells; i++) {
1820 1820 var cell = cells[i];
1821 if (cell.cell_type == 'code' && !cell.output_area.trusted) {
1821 if (cell.cell_type === 'code' && !cell.output_area.trusted) {
1822 1822 trusted = false;
1823 1823 }
1824 1824 cell_array[i] = cell.toJSON();
@@ -1829,7 +1829,7 b' define(['
1829 1829 nbformat: this.nbformat,
1830 1830 nbformat_minor: this.nbformat_minor
1831 1831 };
1832 if (trusted != this.trusted) {
1832 if (trusted !== this.trusted) {
1833 1833 this.trusted = trusted;
1834 1834 this.events.trigger("trust_changed.Notebook", trusted);
1835 1835 }
@@ -1957,7 +1957,7 b' define(['
1957 1957 // round to 10 seconds, otherwise we will be setting a new interval too often
1958 1958 interval = 10000 * Math.round(interval / 10000);
1959 1959 // set new interval, if it's changed
1960 if (interval != this.autosave_interval) {
1960 if (interval !== this.autosave_interval) {
1961 1961 this.set_autosave_interval(interval);
1962 1962 }
1963 1963 }
@@ -1997,7 +1997,7 b' define(['
1997 1997 var cells = nb.get_cells();
1998 1998 for (var i = 0; i < cells.length; i++) {
1999 1999 var cell = cells[i];
2000 if (cell.cell_type == 'code') {
2000 if (cell.cell_type === 'code') {
2001 2001 cell.output_area.trusted = true;
2002 2002 }
2003 2003 }
@@ -2264,7 +2264,7 b' define(['
2264 2264 var found = false;
2265 2265 for (var i = 0; i < this.checkpoints.length; i++) {
2266 2266 var existing = this.checkpoints[i];
2267 if (existing.id == checkpoint.id) {
2267 if (existing.id === checkpoint.id) {
2268 2268 found = true;
2269 2269 this.checkpoints[i] = checkpoint;
2270 2270 break;
@@ -125,7 +125,6 b' define(['
125 125 var cont = Cell.prototype.unrender.apply(this);
126 126 if (cont) {
127 127 var text_cell = this.element;
128 var output = text_cell.find("div.text_cell_render");
129 128 if (this.get_text() === this.placeholder) {
130 129 this.set_text('');
131 130 }
@@ -15,6 +15,7 b' require(['
15 15 page,
16 16 terminado
17 17 ){
18 "use strict";
18 19 page = new page.Page();
19 20 // Test size: 25x80
20 21 var termRowHeight = function(){ return 1.00 * $("#dummy-screen")[0].offsetHeight / 25;};
@@ -28,8 +29,8 b' require(['
28 29
29 30 var header = $("#header")[0]
30 31 function calculate_size() {
31 height = window.innerHeight - header.offsetHeight;
32 width = $('#terminado-container').width();
32 var height = window.innerHeight - header.offsetHeight;
33 var width = $('#terminado-container').width();
33 34 var rows = Math.min(1000, Math.max(20, Math.floor(height/termRowHeight())-1));
34 35 var cols = Math.min(1000, Math.max(40, Math.floor(width/termColWidth())-1));
35 36 console.log("resize to :", rows , 'rows by ', cols, 'columns');
@@ -38,7 +39,7 b' require(['
38 39
39 40 page.show_header();
40 41
41 size = calculate_size();
42 var size = calculate_size();
42 43 var terminal = terminado.make_terminal($("#terminado-container")[0], size, ws_url);
43 44
44 45 page.show_site();
@@ -1,4 +1,5 b''
1 1 define ([], function() {
2 "use strict";
2 3 function make_terminal(element, size, ws_url) {
3 4 var ws = new WebSocket(ws_url);
4 5 var term = new Terminal({
@@ -21,7 +22,7 b' define ([], function() {'
21 22 term.open(element);
22 23
23 24 ws.onmessage = function(event) {
24 json_msg = JSON.parse(event.data);
25 var json_msg = JSON.parse(event.data);
25 26 switch(json_msg[0]) {
26 27 case "stdout":
27 28 term.write(json_msg[1]);
@@ -64,7 +64,6 b' define(['
64 64 };
65 65
66 66 TerminalList.prototype.load_terminals = function() {
67 var that = this;
68 67 var url = utils.url_join_encode(this.base_url, 'api/terminals');
69 68 $.ajax(url, {
70 69 type: "GET",
@@ -78,7 +77,7 b' define(['
78 77 TerminalList.prototype.terminals_loaded = function (data) {
79 78 this.terminals = data;
80 79 this.clear_list();
81 var item, path_name, term;
80 var item, term;
82 81 for (var i=0; i < this.terminals.length; i++) {
83 82 term = this.terminals[i];
84 83 item = this.new_item(-1);
@@ -8,6 +8,7 b' define(["widgets/js/manager",'
8 8 "base/js/utils",
9 9 "base/js/namespace",
10 10 ], function(widgetmanager, _, Backbone, $, utils, IPython){
11 "use strict";
11 12
12 13 var WidgetModel = Backbone.Model.extend({
13 14 constructor: function (widget_manager, model_id, comm) {
@@ -175,7 +176,7 b' define(["widgets/js/manager",'
175 176
176 177 get_state: function() {
177 178 // Get the serializable state of the model.
178 state = this.toJSON();
179 var state = this.toJSON();
179 180 for (var key in state) {
180 181 if (state.hasOwnProperty(key)) {
181 182 state[key] = this._pack_models(state[key]);
@@ -587,7 +588,6 b' define(["widgets/js/manager",'
587 588 /**
588 589 * Update the css styling of this view.
589 590 */
590 var e = this.$el;
591 591 if (css === undefined) {return;}
592 592 for (var i = 0; i < css.length; i++) {
593 593 // Apply the css traits to all elements that match the selector.
@@ -705,7 +705,7 b' define(["widgets/js/manager",'
705 705 */
706 706 var remove = remove_view || this._remove_view;
707 707 var create = create_view || this._create_view;
708 var context = context || this._handler_context;
708 context = context || this._handler_context;
709 709 var i = 0;
710 710 // first, skip past the beginning of the lists if they are identical
711 711 for (; i < new_models.length; i++) {
@@ -7,6 +7,7 b' define(['
7 7 "base/js/utils",
8 8 "bootstrap",
9 9 ], function(widget, $, utils){
10 "use strict";
10 11
11 12 var BoxView = widget.DOMWidgetView.extend({
12 13 initialize: function(){
@@ -260,11 +260,12 b' define(['
260 260 * Calling model.set will trigger all of the other views of the
261 261 * model to update.
262 262 */
263 var actual_value;
263 264 if (this.model.get("_range")) {
264 var actual_value = ui.values.map(this._validate_slide_value);
265 actual_value = ui.values.map(this._validate_slide_value);
265 266 this.$readout.text(actual_value.join("-"));
266 267 } else {
267 var actual_value = this._validate_slide_value(ui.value);
268 actual_value = this._validate_slide_value(ui.value);
268 269 this.$readout.text(actual_value);
269 270 }
270 271 this.model.set('value', actual_value, {updated_view: this});
@@ -168,7 +168,6 b' define(['
168 168 * Called when view is rendered.
169 169 */
170 170 var uuid = 'tabs'+utils.uuid();
171 var that = this;
172 171 this.$tabs = $('<div />', {id: uuid})
173 172 .addClass('nav')
174 173 .addClass('nav-tabs')
@@ -2,6 +2,7 b''
2 2 // Test that a Markdown cell is rendered to HTML.
3 3 //
4 4 casper.notebook_test(function () {
5 "use strict";
5 6 // Test JavaScript models.
6 7 var output = this.evaluate(function () {
7 8 IPython.notebook.to_markdown();
@@ -56,7 +57,7 b' casper.notebook_test(function () {'
56 57 for (var idx=0; idx < levels.length; idx++) {
57 58 var level = levels[idx];
58 59 level_text = set_level(level);
59 hashes = new Array(level + 1).join('#');
60 var hashes = new Array(level + 1).join('#');
60 61 this.test.assertEquals(level_text, hashes + ' ' + text, 'markdown set_heading_level ' + level);
61 62 }
62 63 });
@@ -23,7 +23,7 b' var svg = "\\"<svg width=\'1cm\' height=\'1cm\' viewBox=\'0 0 1000 500\'><defs><style>r'
23 23 // represetnation, while the original in-memory cell retains its long mimetype
24 24 // name, and that fromJSON also gets its long mimetype name
25 25 function assert_has(short_name, json, result, result2) {
26 long_name = mime[short_name];
26 var long_name = mime[short_name];
27 27 this.test.assertFalse(json[0].data.hasOwnProperty(short_name),
28 28 "toJSON() representation doesn't use " + short_name);
29 29 this.test.assertTrue(json[0].data.hasOwnProperty(long_name),
@@ -40,7 +40,7 b' function assert_has(short_name, json, result, result2) {'
40 40 // 'png', etc) are not used.
41 41 function check_output_area(output_type, keys) {
42 42 this.wait_for_output(0);
43 json = this.evaluate(function() {
43 var json = this.evaluate(function() {
44 44 var json = IPython.notebook.get_cell(0).output_area.toJSON();
45 45 // appended cell will initially be empty, let's add some output
46 46 IPython.notebook.get_cell(1).output_area.fromJSON(json);
@@ -422,8 +422,9 b' casper.click_cell_editor = function(index) {'
422 422 // region of codemirror that the user can focus.
423 423 this.evaluate(function (i) {
424 424 var cm = IPython.notebook.get_cell(i).code_mirror;
425 if (cm.options.readOnly != "nocursor" && (document.activeElement != cm.display.input))
425 if (cm.options.readOnly != "nocursor" && (document.activeElement != cm.display.input)){
426 426 cm.display.input.focus();
427 }
427 428 }, {i: index});
428 429 };
429 430
@@ -591,7 +592,7 b' casper.assert_colors_equal = function (hex_color, local_color, msg) {'
591 592
592 593 // If the local color is rgb, clean it up and replace
593 594 if (local_color.substr(0,3).toLowerCase() == 'rgb') {
594 components = local_color.substr(3).split(',');
595 var components = local_color.substr(3).split(',');
595 596 local_color = '';
596 597 for (var i = 0; i < components.length; i++) {
597 598 var part = parseInt(components[i]).toString(16);
@@ -1,5 +1,6 b''
1 1 // Test widget bool class
2 2 casper.notebook_test(function () {
3 "use strict";
3 4
4 5 // Create a checkbox and togglebutton.
5 6 var bool_index = this.append_cell(
@@ -57,7 +58,7 b' casper.notebook_test(function () {'
57 58 });
58 59
59 60 // Try changing the state of the widgets programatically.
60 index = this.append_cell(
61 var index = this.append_cell(
61 62 'bool_widgets[0].value = False\n' +
62 63 'bool_widgets[1].value = False\n' +
63 64 'print("Success")');
@@ -88,4 +89,4 b' casper.notebook_test(function () {'
88 89 'Toggle button is toggled. (3)');
89 90
90 91 });
91 }); No newline at end of file
92 });
@@ -1,6 +1,7 b''
1 1 // Test image class
2 2 casper.notebook_test(function () {
3 index = this.append_cell(
3 "use strict";
4 var index = this.append_cell(
4 5 'from IPython.html import widgets\n' +
5 6 'from IPython.display import display, clear_output\n' +
6 7 'print("Success")');
@@ -45,4 +46,4 b' casper.notebook_test(function () {'
45 46 var img_src = this.cell_element_function(image_index, img_selector, 'attr', ['src']);
46 47 this.test.assert(img_src.indexOf(test_jpg) > -1, 'Image src data exists.');
47 48 });
48 }); No newline at end of file
49 });
@@ -27,10 +27,6 b' from IPython.utils import py3compat'
27 27
28 28 fs_encoding = sys.getfilesystemencoding()
29 29
30 def _get_long_path_name(path):
31 """Dummy no-op."""
32 return path
33
34 30 def _writable_dir(path):
35 31 """Whether `path` is a directory, to which the user has write access."""
36 32 return os.path.isdir(path) and os.access(path, os.W_OK)
@@ -61,6 +57,11 b" if sys.platform == 'win32':"
61 57 return path
62 58 else:
63 59 return buf.value
60 else:
61 def _get_long_path_name(path):
62 """Dummy no-op."""
63 return path
64
64 65
65 66
66 67 def get_long_path_name(path):
@@ -35,23 +35,18 b' from . import py3compat'
35 35 ignore_termtitle = True
36 36
37 37
38 def _term_clear():
39 pass
40
41 38
42 39 if os.name == 'posix':
43 40 def _term_clear():
44 41 os.system('clear')
45
46
47 if sys.platform == 'win32':
42 elif sys.platform == 'win32':
48 43 def _term_clear():
49 44 os.system('cls')
45 else:
46 def _term_clear():
47 pass
50 48
51 49
52 def term_clear():
53 _term_clear()
54
55 50
56 51 def toggle_set_term_title(val):
57 52 """Control whether set_term_title is active or not.
@@ -85,9 +80,7 b" if os.name == 'posix':"
85 80 TERM = os.environ.get('TERM','')
86 81 if TERM.startswith('xterm'):
87 82 _set_term_title = _set_term_title_xterm
88
89
90 if sys.platform == 'win32':
83 elif sys.platform == 'win32':
91 84 try:
92 85 import ctypes
93 86
@@ -127,10 +120,6 b' def freeze_term_title():'
127 120 ignore_termtitle = True
128 121
129 122
130 def get_terminal_size(defaultx=80, defaulty=25):
131 return defaultx, defaulty
132
133
134 123 if sys.platform == 'win32':
135 124 def get_terminal_size(defaultx=80, defaulty=25):
136 125 """Return size of current terminal console.
@@ -161,4 +150,7 b" if sys.platform == 'win32':"
161 150 return (sizex, sizey)
162 151 else:
163 152 return (defaultx, defaulty)
153 else:
154 def get_terminal_size(defaultx=80, defaulty=25):
155 return defaultx, defaulty
164 156
@@ -16,7 +16,6 b' def expect_token(expected, cell, cursor_pos):'
16 16 offset += len(line)
17 17 column = cursor_pos - offset
18 18 line_with_cursor = '%s|%s' % (line[:column], line[column:])
19 line
20 19 nt.assert_equal(token, expected,
21 20 "Expected %r, got %r in: %r (pos %i)" % (
22 21 expected, token, line_with_cursor, cursor_pos)
@@ -298,7 +298,7 b" if 'setuptools' in sys.modules:"
298 298 if 'bdist_wininst' in sys.argv:
299 299 if len(sys.argv) > 2 and \
300 300 ('sdist' in sys.argv or 'bdist_rpm' in sys.argv):
301 print >> sys.stderr, "ERROR: bdist_wininst must be run alone. Exiting."
301 print("ERROR: bdist_wininst must be run alone. Exiting.", file=sys.stderr)
302 302 sys.exit(1)
303 303 setup_args['data_files'].append(
304 304 ['Scripts', ('scripts/ipython.ico', 'scripts/ipython_nb.ico')])
General Comments 0
You need to be logged in to leave comments. Login now