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