##// END OF EJS Templates
To the most conservative choice.
Brian E. Granger -
Show More
@@ -1,222 +1,222 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2012 The IPython Development Team
2 // Copyright (C) 2012 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // Notification widget
9 // Notification widget
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13 "use strict";
13 "use strict";
14 var utils = IPython.utils;
14 var utils = IPython.utils;
15
15
16
16
17 var NotificationArea = function (selector) {
17 var NotificationArea = function (selector) {
18 this.selector = selector;
18 this.selector = selector;
19 if (this.selector !== undefined) {
19 if (this.selector !== undefined) {
20 this.element = $(selector);
20 this.element = $(selector);
21 }
21 }
22 this.widget_dict = {};
22 this.widget_dict = {};
23 };
23 };
24
24
25 NotificationArea.prototype.temp_message = function (msg, timeout, css_class) {
25 NotificationArea.prototype.temp_message = function (msg, timeout, css_class) {
26 var uuid = utils.uuid();
26 var uuid = utils.uuid();
27 if( css_class == 'danger') {css_class = 'ui-state-error';}
27 if( css_class == 'danger') {css_class = 'ui-state-error';}
28 if( css_class == 'warning') {css_class = 'ui-state-highlight';}
28 if( css_class == 'warning') {css_class = 'ui-state-highlight';}
29 var tdiv = $('<div>')
29 var tdiv = $('<div>')
30 .attr('id',uuid)
30 .attr('id',uuid)
31 .addClass('notification_widget ui-widget ui-widget-content ui-corner-all')
31 .addClass('notification_widget ui-widget ui-widget-content ui-corner-all')
32 .addClass('border-box-sizing')
32 .addClass('border-box-sizing')
33 .addClass(css_class)
33 .addClass(css_class)
34 .hide()
34 .hide()
35 .text(msg);
35 .text(msg);
36
36
37 $(this.selector).append(tdiv);
37 $(this.selector).append(tdiv);
38 var tmout = Math.max(1500,(timeout||1500));
38 var tmout = Math.max(1500,(timeout||1500));
39 tdiv.fadeIn(100);
39 tdiv.fadeIn(100);
40
40
41 setTimeout(function () {
41 setTimeout(function () {
42 tdiv.fadeOut(100, function () {tdiv.remove();});
42 tdiv.fadeOut(100, function () {tdiv.remove();});
43 }, tmout);
43 }, tmout);
44 };
44 };
45
45
46 NotificationArea.prototype.widget = function(name) {
46 NotificationArea.prototype.widget = function(name) {
47 if(this.widget_dict[name] == undefined) {
47 if(this.widget_dict[name] == undefined) {
48 return this.new_notification_widget(name);
48 return this.new_notification_widget(name);
49 }
49 }
50 return this.get_widget(name);
50 return this.get_widget(name);
51 };
51 };
52
52
53 NotificationArea.prototype.get_widget = function(name) {
53 NotificationArea.prototype.get_widget = function(name) {
54 if(this.widget_dict[name] == undefined) {
54 if(this.widget_dict[name] == undefined) {
55 throw('no widgets with this name');
55 throw('no widgets with this name');
56 }
56 }
57 return this.widget_dict[name];
57 return this.widget_dict[name];
58 };
58 };
59
59
60 NotificationArea.prototype.new_notification_widget = function(name) {
60 NotificationArea.prototype.new_notification_widget = function(name) {
61 if(this.widget_dict[name] != undefined) {
61 if(this.widget_dict[name] != undefined) {
62 throw('widget with that name already exists ! ');
62 throw('widget with that name already exists ! ');
63 }
63 }
64 var div = $('<div/>').attr('id','notification_'+name);
64 var div = $('<div/>').attr('id','notification_'+name);
65 $(this.selector).append(div);
65 $(this.selector).append(div);
66 this.widget_dict[name] = new IPython.NotificationWidget('#notification_'+name);
66 this.widget_dict[name] = new IPython.NotificationWidget('#notification_'+name);
67 return this.widget_dict[name];
67 return this.widget_dict[name];
68 };
68 };
69
69
70 NotificationArea.prototype.init_notification_widgets = function() {
70 NotificationArea.prototype.init_notification_widgets = function() {
71 var knw = this.new_notification_widget('kernel');
71 var knw = this.new_notification_widget('kernel');
72 var $kernel_ind_icon = $("#kernel_indicator_icon");
72 var $kernel_ind_icon = $("#kernel_indicator_icon");
73 var $modal_ind_icon = $("#modal_indicator_icon");
73 var $modal_ind_icon = $("#modal_indicator_icon");
74
74
75 // Command/Edit mode
75 // Command/Edit mode
76 $([IPython.events]).on('edit_mode.Notebook',function () {
76 $([IPython.events]).on('edit_mode.Notebook',function () {
77 IPython.save_widget.update_document_title();
77 IPython.save_widget.update_document_title();
78 $modal_ind_icon.attr('class','icon-pencil').attr('title','Edit Mode');
78 $modal_ind_icon.attr('class','icon-pencil').attr('title','Edit Mode');
79 });
79 });
80
80
81 $([IPython.events]).on('command_mode.Notebook',function () {
81 $([IPython.events]).on('command_mode.Notebook',function () {
82 IPython.save_widget.update_document_title();
82 IPython.save_widget.update_document_title();
83 $modal_ind_icon.attr('class','').attr('title','Command Mode');
83 $modal_ind_icon.attr('class','').attr('title','Command Mode');
84 });
84 });
85
85
86 // Kernel events
86 // Kernel events
87 $([IPython.events]).on('status_idle.Kernel',function () {
87 $([IPython.events]).on('status_idle.Kernel',function () {
88 IPython.save_widget.update_document_title();
88 IPython.save_widget.update_document_title();
89 $kernel_ind_icon.attr('class','').attr('title','Kernel Idle');
89 $kernel_ind_icon.attr('class','icon-circle-blank').attr('title','Kernel Idle');
90 });
90 });
91
91
92 $([IPython.events]).on('status_busy.Kernel',function () {
92 $([IPython.events]).on('status_busy.Kernel',function () {
93 window.document.title='(Busy) '+window.document.title;
93 window.document.title='(Busy) '+window.document.title;
94 $kernel_ind_icon.attr('class','icon-sun icon-spin').attr('title','Kernel Busy');
94 $kernel_ind_icon.attr('class','icon-circle').attr('title','Kernel Busy');
95 });
95 });
96
96
97 $([IPython.events]).on('status_restarting.Kernel',function () {
97 $([IPython.events]).on('status_restarting.Kernel',function () {
98 IPython.save_widget.update_document_title();
98 IPython.save_widget.update_document_title();
99 knw.set_message("Restarting kernel", 2000);
99 knw.set_message("Restarting kernel", 2000);
100 });
100 });
101
101
102 $([IPython.events]).on('status_interrupting.Kernel',function () {
102 $([IPython.events]).on('status_interrupting.Kernel',function () {
103 knw.set_message("Interrupting kernel", 2000);
103 knw.set_message("Interrupting kernel", 2000);
104 });
104 });
105
105
106 $([IPython.events]).on('status_dead.Kernel',function () {
106 $([IPython.events]).on('status_dead.Kernel',function () {
107 var msg = 'The kernel has died, and the automatic restart has failed.' +
107 var msg = 'The kernel has died, and the automatic restart has failed.' +
108 ' It is possible the kernel cannot be restarted.' +
108 ' It is possible the kernel cannot be restarted.' +
109 ' If you are not able to restart the kernel, you will still be able to save' +
109 ' If you are not able to restart the kernel, you will still be able to save' +
110 ' the notebook, but running code will no longer work until the notebook' +
110 ' the notebook, but running code will no longer work until the notebook' +
111 ' is reopened.';
111 ' is reopened.';
112
112
113 IPython.dialog.modal({
113 IPython.dialog.modal({
114 title: "Dead kernel",
114 title: "Dead kernel",
115 body : msg,
115 body : msg,
116 buttons : {
116 buttons : {
117 "Manual Restart": {
117 "Manual Restart": {
118 class: "btn-danger",
118 class: "btn-danger",
119 click: function () {
119 click: function () {
120 $([IPython.events]).trigger('status_restarting.Kernel');
120 $([IPython.events]).trigger('status_restarting.Kernel');
121 IPython.notebook.start_kernel();
121 IPython.notebook.start_kernel();
122 }
122 }
123 },
123 },
124 "Don't restart": {}
124 "Don't restart": {}
125 }
125 }
126 });
126 });
127 });
127 });
128
128
129 $([IPython.events]).on('websocket_closed.Kernel', function (event, data) {
129 $([IPython.events]).on('websocket_closed.Kernel', function (event, data) {
130 var kernel = data.kernel;
130 var kernel = data.kernel;
131 var ws_url = data.ws_url;
131 var ws_url = data.ws_url;
132 var early = data.early;
132 var early = data.early;
133 var msg;
133 var msg;
134 if (!early) {
134 if (!early) {
135 knw.set_message('Reconnecting WebSockets', 1000);
135 knw.set_message('Reconnecting WebSockets', 1000);
136 setTimeout(function () {
136 setTimeout(function () {
137 kernel.start_channels();
137 kernel.start_channels();
138 }, 5000);
138 }, 5000);
139 return;
139 return;
140 }
140 }
141 console.log('WebSocket connection failed: ', ws_url)
141 console.log('WebSocket connection failed: ', ws_url)
142 msg = "A WebSocket connection could not be established." +
142 msg = "A WebSocket connection could not be established." +
143 " You will NOT be able to run code. Check your" +
143 " You will NOT be able to run code. Check your" +
144 " network connection or notebook server configuration.";
144 " network connection or notebook server configuration.";
145 IPython.dialog.modal({
145 IPython.dialog.modal({
146 title: "WebSocket connection failed",
146 title: "WebSocket connection failed",
147 body: msg,
147 body: msg,
148 buttons : {
148 buttons : {
149 "OK": {},
149 "OK": {},
150 "Reconnect": {
150 "Reconnect": {
151 click: function () {
151 click: function () {
152 knw.set_message('Reconnecting WebSockets', 1000);
152 knw.set_message('Reconnecting WebSockets', 1000);
153 setTimeout(function () {
153 setTimeout(function () {
154 kernel.start_channels();
154 kernel.start_channels();
155 }, 5000);
155 }, 5000);
156 }
156 }
157 }
157 }
158 }
158 }
159 });
159 });
160 });
160 });
161
161
162
162
163 var nnw = this.new_notification_widget('notebook');
163 var nnw = this.new_notification_widget('notebook');
164
164
165 // Notebook events
165 // Notebook events
166 $([IPython.events]).on('notebook_loading.Notebook', function () {
166 $([IPython.events]).on('notebook_loading.Notebook', function () {
167 nnw.set_message("Loading notebook",500);
167 nnw.set_message("Loading notebook",500);
168 });
168 });
169 $([IPython.events]).on('notebook_loaded.Notebook', function () {
169 $([IPython.events]).on('notebook_loaded.Notebook', function () {
170 nnw.set_message("Notebook loaded",500);
170 nnw.set_message("Notebook loaded",500);
171 });
171 });
172 $([IPython.events]).on('notebook_saving.Notebook', function () {
172 $([IPython.events]).on('notebook_saving.Notebook', function () {
173 nnw.set_message("Saving notebook",500);
173 nnw.set_message("Saving notebook",500);
174 });
174 });
175 $([IPython.events]).on('notebook_saved.Notebook', function () {
175 $([IPython.events]).on('notebook_saved.Notebook', function () {
176 nnw.set_message("Notebook saved",2000);
176 nnw.set_message("Notebook saved",2000);
177 });
177 });
178 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
178 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
179 nnw.set_message("Notebook save failed");
179 nnw.set_message("Notebook save failed");
180 });
180 });
181
181
182 // Checkpoint events
182 // Checkpoint events
183 $([IPython.events]).on('checkpoint_created.Notebook', function (evt, data) {
183 $([IPython.events]).on('checkpoint_created.Notebook', function (evt, data) {
184 var msg = "Checkpoint created";
184 var msg = "Checkpoint created";
185 if (data.last_modified) {
185 if (data.last_modified) {
186 var d = new Date(data.last_modified);
186 var d = new Date(data.last_modified);
187 msg = msg + ": " + d.format("HH:MM:ss");
187 msg = msg + ": " + d.format("HH:MM:ss");
188 }
188 }
189 nnw.set_message(msg, 2000);
189 nnw.set_message(msg, 2000);
190 });
190 });
191 $([IPython.events]).on('checkpoint_failed.Notebook', function () {
191 $([IPython.events]).on('checkpoint_failed.Notebook', function () {
192 nnw.set_message("Checkpoint failed");
192 nnw.set_message("Checkpoint failed");
193 });
193 });
194 $([IPython.events]).on('checkpoint_deleted.Notebook', function () {
194 $([IPython.events]).on('checkpoint_deleted.Notebook', function () {
195 nnw.set_message("Checkpoint deleted", 500);
195 nnw.set_message("Checkpoint deleted", 500);
196 });
196 });
197 $([IPython.events]).on('checkpoint_delete_failed.Notebook', function () {
197 $([IPython.events]).on('checkpoint_delete_failed.Notebook', function () {
198 nnw.set_message("Checkpoint delete failed");
198 nnw.set_message("Checkpoint delete failed");
199 });
199 });
200 $([IPython.events]).on('checkpoint_restoring.Notebook', function () {
200 $([IPython.events]).on('checkpoint_restoring.Notebook', function () {
201 nnw.set_message("Restoring to checkpoint...", 500);
201 nnw.set_message("Restoring to checkpoint...", 500);
202 });
202 });
203 $([IPython.events]).on('checkpoint_restore_failed.Notebook', function () {
203 $([IPython.events]).on('checkpoint_restore_failed.Notebook', function () {
204 nnw.set_message("Checkpoint restore failed");
204 nnw.set_message("Checkpoint restore failed");
205 });
205 });
206
206
207 // Autosave events
207 // Autosave events
208 $([IPython.events]).on('autosave_disabled.Notebook', function () {
208 $([IPython.events]).on('autosave_disabled.Notebook', function () {
209 nnw.set_message("Autosave disabled", 2000);
209 nnw.set_message("Autosave disabled", 2000);
210 });
210 });
211 $([IPython.events]).on('autosave_enabled.Notebook', function (evt, interval) {
211 $([IPython.events]).on('autosave_enabled.Notebook', function (evt, interval) {
212 nnw.set_message("Saving every " + interval / 1000 + "s", 1000);
212 nnw.set_message("Saving every " + interval / 1000 + "s", 1000);
213 });
213 });
214
214
215 };
215 };
216
216
217 IPython.NotificationArea = NotificationArea;
217 IPython.NotificationArea = NotificationArea;
218
218
219 return IPython;
219 return IPython;
220
220
221 }(IPython));
221 }(IPython));
222
222
General Comments 0
You need to be logged in to leave comments. Login now