Show More
@@ -0,0 +1,141 b'' | |||
|
1 | //---------------------------------------------------------------------------- | |
|
2 | // Copyright (C) 2012 The IPython Development Team | |
|
3 | // | |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
|
5 | // the file COPYING, distributed as part of this software. | |
|
6 | //---------------------------------------------------------------------------- | |
|
7 | ||
|
8 | //============================================================================ | |
|
9 | // Notification widget | |
|
10 | //============================================================================ | |
|
11 | ||
|
12 | var IPython = (function (IPython) { | |
|
13 | "use strict"; | |
|
14 | var utils = IPython.utils; | |
|
15 | ||
|
16 | ||
|
17 | var NotificationArea = function (selector) { | |
|
18 | this.selector = selector; | |
|
19 | if (this.selector !== undefined) { | |
|
20 | this.element = $(selector); | |
|
21 | } | |
|
22 | this.widget_dict = {}; | |
|
23 | }; | |
|
24 | ||
|
25 | NotificationArea.prototype.temp_message = function (msg, timeout, css_class) { | |
|
26 | var uuid = utils.uuid(); | |
|
27 | if( css_class == 'danger') {css_class = 'ui-state-error';} | |
|
28 | if( css_class == 'warning') {css_class = 'ui-state-highlight';} | |
|
29 | var tdiv = $('<div>') | |
|
30 | .attr('id',uuid) | |
|
31 | .addClass('notification_widget ui-widget ui-widget-content ui-corner-all') | |
|
32 | .addClass('border-box-sizing') | |
|
33 | .addClass(css_class) | |
|
34 | .hide() | |
|
35 | .text(msg); | |
|
36 | ||
|
37 | $(this.selector).append(tdiv); | |
|
38 | var tmout = Math.max(1500,(timeout||1500)); | |
|
39 | tdiv.fadeIn(100); | |
|
40 | ||
|
41 | setTimeout(function () { | |
|
42 | tdiv.fadeOut(100, function () {tdiv.remove();}); | |
|
43 | }, tmout); | |
|
44 | }; | |
|
45 | ||
|
46 | NotificationArea.prototype.widget = function(name) { | |
|
47 | if(this.widget_dict[name] == undefined) { | |
|
48 | return this.new_notification_widget(name); | |
|
49 | } | |
|
50 | return this.get_widget(name); | |
|
51 | }; | |
|
52 | ||
|
53 | NotificationArea.prototype.get_widget = function(name) { | |
|
54 | if(this.widget_dict[name] == undefined) { | |
|
55 | throw('no widgets with this name'); | |
|
56 | } | |
|
57 | return this.widget_dict[name]; | |
|
58 | }; | |
|
59 | ||
|
60 | NotificationArea.prototype.new_notification_widget = function(name) { | |
|
61 | if(this.widget_dict[name] != undefined) { | |
|
62 | throw('widget with that name already exists ! '); | |
|
63 | } | |
|
64 | var div = $('<div/>').attr('id','notification_'+name); | |
|
65 | $(this.selector).append(div); | |
|
66 | this.widget_dict[name] = new IPython.NotificationWidget('#notification_'+name); | |
|
67 | return this.widget_dict[name]; | |
|
68 | }; | |
|
69 | ||
|
70 | NotificationArea.prototype.init_notification_widgets = function() { | |
|
71 | var knw = this.new_notification_widget('kernel'); | |
|
72 | ||
|
73 | // Kernel events | |
|
74 | $([IPython.events]).on('status_idle.Kernel',function () { | |
|
75 | IPython.save_widget.update_document_title(); | |
|
76 | knw.set_message('Kernel Idle',200); | |
|
77 | } | |
|
78 | ); | |
|
79 | ||
|
80 | $([IPython.events]).on('status_busy.Kernel',function () { | |
|
81 | window.document.title='(Busy) '+window.document.title; | |
|
82 | knw.set_message("Kernel busy"); | |
|
83 | }); | |
|
84 | ||
|
85 | $([IPython.events]).on('status_restarting.Kernel',function () { | |
|
86 | IPython.save_widget.update_document_title(); | |
|
87 | knw.set_message("Restarting kernel",1000); | |
|
88 | }); | |
|
89 | ||
|
90 | $([IPython.events]).on('status_interrupting.Kernel',function () { | |
|
91 | knw.set_message("Interrupting kernel"); | |
|
92 | }); | |
|
93 | ||
|
94 | $([IPython.events]).on('status_dead.Kernel',function () { | |
|
95 | var dialog = $('<div/>'); | |
|
96 | dialog.html('The kernel has died, would you like to restart it? If you do not restart the kernel, you will be able to save the notebook, but running code will not work until the notebook is reopened.'); | |
|
97 | $(document).append(dialog); | |
|
98 | dialog.dialog({ | |
|
99 | resizable: false, | |
|
100 | modal: true, | |
|
101 | title: "Dead kernel", | |
|
102 | buttons : { | |
|
103 | "Restart": function () { | |
|
104 | $([IPython.events]).trigger('status_restarting.Kernel'); | |
|
105 | IPython.notebook.start_kernel(); | |
|
106 | $(this).dialog('close'); | |
|
107 | }, | |
|
108 | "Continue running": function () { | |
|
109 | $(this).dialog('close'); | |
|
110 | } | |
|
111 | } | |
|
112 | }); | |
|
113 | }); | |
|
114 | ||
|
115 | var nnw = this.new_notification_widget('notebook'); | |
|
116 | ||
|
117 | // Notebook events | |
|
118 | $([IPython.events]).on('notebook_loading.Notebook', function () { | |
|
119 | nnw.set_message("Loading notebook",500); | |
|
120 | }); | |
|
121 | $([IPython.events]).on('notebook_loaded.Notebook', function () { | |
|
122 | nnw.set_message("Notebook loaded",500); | |
|
123 | }); | |
|
124 | $([IPython.events]).on('notebook_saving.Notebook', function () { | |
|
125 | nnw.set_message("Saving notebook",500); | |
|
126 | }); | |
|
127 | $([IPython.events]).on('notebook_saved.Notebook', function () { | |
|
128 | nnw.set_message("Notebook saved",2000); | |
|
129 | }); | |
|
130 | $([IPython.events]).on('notebook_save_failed.Notebook', function () { | |
|
131 | nnw.set_message("Notebook save failed"); | |
|
132 | }); | |
|
133 | ||
|
134 | }; | |
|
135 | ||
|
136 | IPython.NotificationArea = NotificationArea; | |
|
137 | ||
|
138 | return IPython; | |
|
139 | ||
|
140 | }(IPython)); | |
|
141 |
@@ -51,10 +51,20 b' span#notebook_name {' | |||
|
51 | 51 | position: relative; |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | #notification { | |
|
54 | #notification_area { | |
|
55 | 55 | position: absolute; |
|
56 |
right: |
|
|
57 |
top: |
|
|
56 | right: 0px; | |
|
57 | top: 0px; | |
|
58 | height: 25px; | |
|
59 | padding: 3px 0px; | |
|
60 | padding-right: 3px; | |
|
61 | z-index: 10; | |
|
62 | } | |
|
63 | ||
|
64 | .notification_widget{ | |
|
65 | float : right; | |
|
66 | right: 0px; | |
|
67 | top: 1px; | |
|
58 | 68 | height: 25px; |
|
59 | 69 | padding: 3px 6px; |
|
60 | 70 | z-index: 10; |
@@ -391,4 +401,4 b' pre, code, kbd, samp { white-space: pre-wrap; }' | |||
|
391 | 401 | |
|
392 | 402 | .js-error { |
|
393 | 403 | color: darkred; |
|
394 | } No newline at end of file | |
|
404 | } |
@@ -99,7 +99,7 b' var IPython = (function (IPython) {' | |||
|
99 | 99 | " or if the url does not look right, there could be an error in the" + |
|
100 | 100 | " server's configuration."; |
|
101 | 101 | } else { |
|
102 | IPython.notification_widget.set_message('Reconnecting Websockets', 1000); | |
|
102 | IPython.notification_area.widget('kernel').set_message('Reconnecting Websockets', 1000); | |
|
103 | 103 | this.start_channels(); |
|
104 | 104 | return; |
|
105 | 105 | } |
@@ -31,7 +31,8 b' $(document).ready(function () {' | |||
|
31 | 31 | IPython.menubar = new IPython.MenuBar('#menubar') |
|
32 | 32 | IPython.toolbar = new IPython.ToolBar('#toolbar') |
|
33 | 33 | IPython.tooltip = new IPython.Tooltip() |
|
34 |
IPython.notification_ |
|
|
34 | IPython.notification_area = new IPython.NotificationArea('#notification_area') | |
|
35 | IPython.notification_area.init_notification_widgets(); | |
|
35 | 36 | |
|
36 | 37 | IPython.layout_manager.do_resize(); |
|
37 | 38 |
@@ -10,7 +10,7 b'' | |||
|
10 | 10 | //============================================================================ |
|
11 | 11 | |
|
12 | 12 | var IPython = (function (IPython) { |
|
13 | ||
|
13 | "use strict"; | |
|
14 | 14 | var utils = IPython.utils; |
|
15 | 15 | |
|
16 | 16 | |
@@ -21,92 +21,51 b' var IPython = (function (IPython) {' | |||
|
21 | 21 | if (this.selector !== undefined) { |
|
22 | 22 | this.element = $(selector); |
|
23 | 23 | this.style(); |
|
24 | this.bind_events(); | |
|
25 | 24 | } |
|
25 | this.element.button(); | |
|
26 | this.element.hide(); | |
|
27 | var that = this; | |
|
28 | ||
|
26 | 29 | }; |
|
27 | 30 | |
|
28 | 31 | |
|
29 | 32 | NotificationWidget.prototype.style = function () { |
|
30 | this.element.addClass('ui-widget ui-widget-content ui-corner-all'); | |
|
33 | this.element.addClass('notification_widget ui-widget ui-widget-content ui-corner-all'); | |
|
31 | 34 | this.element.addClass('border-box-sizing'); |
|
32 | 35 | }; |
|
33 | 36 | |
|
34 | ||
|
35 | NotificationWidget.prototype.bind_events = function () { | |
|
36 | var that = this; | |
|
37 | // Kernel events | |
|
38 | $([IPython.events]).on('status_idle.Kernel',function () { | |
|
39 | IPython.save_widget.update_document_title(); | |
|
40 | if (that.get_message() === 'Kernel busy') { | |
|
41 | that.element.fadeOut(100, function () { | |
|
42 | that.element.html(''); | |
|
43 | }); | |
|
44 | }; | |
|
45 | }); | |
|
46 | $([IPython.events]).on('status_busy.Kernel',function () { | |
|
47 | window.document.title='(Busy) '+window.document.title; | |
|
48 | that.set_message("Kernel busy"); | |
|
49 | }); | |
|
50 | $([IPython.events]).on('status_restarting.Kernel',function () { | |
|
51 | IPython.save_widget.update_document_title(); | |
|
52 | that.set_message("Restarting kernel",500); | |
|
53 | }); | |
|
54 | $([IPython.events]).on('status_interrupting.Kernel',function () { | |
|
55 | that.set_message("Interrupting kernel",500); | |
|
56 | }); | |
|
57 | $([IPython.events]).on('status_dead.Kernel',function () { | |
|
58 | var dialog = $('<div/>'); | |
|
59 | dialog.html('The kernel has died, would you like to restart it? If you do not restart the kernel, you will be able to save the notebook, but running code will not work until the notebook is reopened.'); | |
|
60 | $(document).append(dialog); | |
|
61 | dialog.dialog({ | |
|
62 | resizable: false, | |
|
63 | modal: true, | |
|
64 | title: "Dead kernel", | |
|
65 | buttons : { | |
|
66 | "Restart": function () { | |
|
67 | $([IPython.events]).trigger('status_restarting.Kernel'); | |
|
68 | IPython.notebook.start_kernel(); | |
|
69 | $(this).dialog('close'); | |
|
70 | }, | |
|
71 | "Continue running": function () { | |
|
72 | $(this).dialog('close'); | |
|
73 | } | |
|
74 | } | |
|
75 | }); | |
|
76 | }); | |
|
77 | // Notebook events | |
|
78 | $([IPython.events]).on('notebook_loading.Notebook', function () { | |
|
79 | that.set_message("Loading notebook",500); | |
|
80 | }); | |
|
81 | $([IPython.events]).on('notebook_loaded.Notebook', function () { | |
|
82 | that.set_message("Notebook loaded",500); | |
|
83 | }); | |
|
84 | $([IPython.events]).on('notebook_saving.Notebook', function () { | |
|
85 | that.set_message("Saving notebook",500); | |
|
86 | }); | |
|
87 | $([IPython.events]).on('notebook_saved.Notebook', function () { | |
|
88 | that.set_message("Notebook saved",2000); | |
|
89 | }); | |
|
90 | $([IPython.events]).on('notebook_save_failed.Notebook', function () { | |
|
91 | that.set_message("Notebook save failed",2000); | |
|
92 | }); | |
|
93 | }; | |
|
94 | ||
|
95 | ||
|
96 | NotificationWidget.prototype.set_message = function (msg, timeout) { | |
|
37 | // msg : message to display | |
|
38 | // timeout : time in ms before diseapearing | |
|
39 | // | |
|
40 | // if timeout <= 0 | |
|
41 | // click_callback : function called if user click on notification | |
|
42 | // could return false to prevent the notification to be dismissed | |
|
43 | NotificationWidget.prototype.set_message = function (msg, timeout, click_callback) { | |
|
44 | var callback = click_callback || function() {return false;}; | |
|
97 | 45 | var that = this; |
|
98 | 46 | this.element.html(msg); |
|
99 | 47 | this.element.fadeIn(100); |
|
100 | 48 | if (this.timeout !== null) { |
|
101 | 49 | clearTimeout(this.timeout); |
|
102 | 50 | this.timeout = null; |
|
103 |
} |
|
|
104 | if (timeout !== undefined) { | |
|
51 | } | |
|
52 | if (timeout !== undefined && timeout >=0) { | |
|
105 | 53 | this.timeout = setTimeout(function () { |
|
106 | 54 | that.element.fadeOut(100, function () {that.element.html('');}); |
|
107 | 55 | that.timeout = null; |
|
108 | }, timeout) | |
|
109 |
} |
|
|
56 | }, timeout); | |
|
57 | } else { | |
|
58 | this.element.click(function() { | |
|
59 | if( callback() != false ) { | |
|
60 | that.element.fadeOut(100, function () {that.element.html('');}); | |
|
61 | that.element.unbind('click'); | |
|
62 | } | |
|
63 | if (that.timeout !== undefined) { | |
|
64 | that.timeout = undefined; | |
|
65 | clearTimeout(that.timeout); | |
|
66 | } | |
|
67 | }); | |
|
68 | } | |
|
110 | 69 | }; |
|
111 | 70 | |
|
112 | 71 |
@@ -152,7 +152,8 b' data-notebook-id={{notebook_id}}' | |||
|
152 | 152 | </ul> |
|
153 | 153 | |
|
154 | 154 | </div> |
|
155 |
<div id="notification" |
|
|
155 | <div id="notification_area"> | |
|
156 | </div> | |
|
156 | 157 | </div> |
|
157 | 158 | |
|
158 | 159 | |
@@ -242,6 +243,7 b' data-notebook-id={{notebook_id}}' | |||
|
242 | 243 | <script src="{{ static_url("js/toolbar.js") }}" type="text/javascript" charset="utf-8"></script> |
|
243 | 244 | <script src="{{ static_url("js/notebook.js") }}" type="text/javascript" charset="utf-8"></script> |
|
244 | 245 | <script src="{{ static_url("js/notificationwidget.js") }}" type="text/javascript" charset="utf-8"></script> |
|
246 | <script src="{{ static_url("js/notificationarea.js") }}" type="text/javascript" charset="utf-8"></script> | |
|
245 | 247 | <script src="{{ static_url("js/tooltip.js") }}" type="text/javascript" charset="utf-8"></script> |
|
246 | 248 | <script src="{{ static_url("js/notebookmain.js") }}" type="text/javascript" charset="utf-8"></script> |
|
247 | 249 |
General Comments 0
You need to be logged in to leave comments.
Login now