##// END OF EJS Templates
rename css class names to be consistent with current style
Paul Ivanov -
Show More
@@ -1,235 +1,235
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 if(this.widget_dict[name] == undefined) {
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 if(this.widget_dict[name] == undefined) {
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 if(this.widget_dict[name] != undefined) {
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 $modal_ind_icon.attr('class','ipython-edit-mode').attr('title','Edit Mode');
78 $modal_ind_icon.attr('class','edit_mode_icon').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 $modal_ind_icon.attr('class','ipython-command-mode').attr('title','Command Mode');
83 $modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode');
84 84 });
85 85
86 86 // Implicitly start off in Command mode, switching to Edit mode will trigger event
87 $modal_ind_icon.attr('class','ipython-command-mode').attr('title','Command Mode');
87 $modal_ind_icon.attr('class','command-mode_icon').attr('title','Command Mode');
88 88
89 89 // Kernel events
90 90 $([IPython.events]).on('status_idle.Kernel',function () {
91 91 IPython.save_widget.update_document_title();
92 $kernel_ind_icon.attr('class','ipython-kernel-idle').attr('title','Kernel Idle');
92 $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle');
93 93 });
94 94
95 95 $([IPython.events]).on('status_busy.Kernel',function () {
96 96 window.document.title='(Busy) '+window.document.title;
97 $kernel_ind_icon.attr('class','ipython-kernel-busy').attr('title','Kernel Busy');
97 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
98 98 });
99 99
100 100 $([IPython.events]).on('status_restarting.Kernel',function () {
101 101 IPython.save_widget.update_document_title();
102 102 knw.set_message("Restarting kernel", 2000);
103 103 });
104 104
105 105 $([IPython.events]).on('status_interrupting.Kernel',function () {
106 106 knw.set_message("Interrupting kernel", 2000);
107 107 });
108 108
109 109 // Start the kernel indicator in the busy state, and send a kernel_info request.
110 110 // When the kernel_info reply arrives, the kernel is idle.
111 $kernel_ind_icon.attr('class','ipython-kernel-busy').attr('title','Kernel Busy');
111 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
112 112
113 113 $([IPython.events]).on('status_started.Kernel', function (evt, data) {
114 114 data.kernel.kernel_info(function () {
115 115 $([IPython.events]).trigger('status_idle.Kernel');
116 116 });
117 117 });
118 118
119 119 $([IPython.events]).on('status_dead.Kernel',function () {
120 120 var msg = 'The kernel has died, and the automatic restart has failed.' +
121 121 ' It is possible the kernel cannot be restarted.' +
122 122 ' If you are not able to restart the kernel, you will still be able to save' +
123 123 ' the notebook, but running code will no longer work until the notebook' +
124 124 ' is reopened.';
125 125
126 126 IPython.dialog.modal({
127 127 title: "Dead kernel",
128 128 body : msg,
129 129 buttons : {
130 130 "Manual Restart": {
131 131 class: "btn-danger",
132 132 click: function () {
133 133 $([IPython.events]).trigger('status_restarting.Kernel');
134 134 IPython.notebook.start_kernel();
135 135 }
136 136 },
137 137 "Don't restart": {}
138 138 }
139 139 });
140 140 });
141 141
142 142 $([IPython.events]).on('websocket_closed.Kernel', function (event, data) {
143 143 var kernel = data.kernel;
144 144 var ws_url = data.ws_url;
145 145 var early = data.early;
146 146 var msg;
147 147 if (!early) {
148 148 knw.set_message('Reconnecting WebSockets', 1000);
149 149 setTimeout(function () {
150 150 kernel.start_channels();
151 151 }, 5000);
152 152 return;
153 153 }
154 console.log('WebSocket connection failed: ', ws_url)
154 console.log('WebSocket connection failed: ', ws_url);
155 155 msg = "A WebSocket connection could not be established." +
156 156 " You will NOT be able to run code. Check your" +
157 157 " network connection or notebook server configuration.";
158 158 IPython.dialog.modal({
159 159 title: "WebSocket connection failed",
160 160 body: msg,
161 161 buttons : {
162 162 "OK": {},
163 163 "Reconnect": {
164 164 click: function () {
165 165 knw.set_message('Reconnecting WebSockets', 1000);
166 166 setTimeout(function () {
167 167 kernel.start_channels();
168 168 }, 5000);
169 169 }
170 170 }
171 171 }
172 172 });
173 173 });
174 174
175 175
176 176 var nnw = this.new_notification_widget('notebook');
177 177
178 178 // Notebook events
179 179 $([IPython.events]).on('notebook_loading.Notebook', function () {
180 180 nnw.set_message("Loading notebook",500);
181 181 });
182 182 $([IPython.events]).on('notebook_loaded.Notebook', function () {
183 183 nnw.set_message("Notebook loaded",500);
184 184 });
185 185 $([IPython.events]).on('notebook_saving.Notebook', function () {
186 186 nnw.set_message("Saving notebook",500);
187 187 });
188 188 $([IPython.events]).on('notebook_saved.Notebook', function () {
189 189 nnw.set_message("Notebook saved",2000);
190 190 });
191 191 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
192 192 nnw.set_message("Notebook save failed");
193 193 });
194 194
195 195 // Checkpoint events
196 196 $([IPython.events]).on('checkpoint_created.Notebook', function (evt, data) {
197 197 var msg = "Checkpoint created";
198 198 if (data.last_modified) {
199 199 var d = new Date(data.last_modified);
200 200 msg = msg + ": " + d.format("HH:MM:ss");
201 201 }
202 202 nnw.set_message(msg, 2000);
203 203 });
204 204 $([IPython.events]).on('checkpoint_failed.Notebook', function () {
205 205 nnw.set_message("Checkpoint failed");
206 206 });
207 207 $([IPython.events]).on('checkpoint_deleted.Notebook', function () {
208 208 nnw.set_message("Checkpoint deleted", 500);
209 209 });
210 210 $([IPython.events]).on('checkpoint_delete_failed.Notebook', function () {
211 211 nnw.set_message("Checkpoint delete failed");
212 212 });
213 213 $([IPython.events]).on('checkpoint_restoring.Notebook', function () {
214 214 nnw.set_message("Restoring to checkpoint...", 500);
215 215 });
216 216 $([IPython.events]).on('checkpoint_restore_failed.Notebook', function () {
217 217 nnw.set_message("Checkpoint restore failed");
218 218 });
219 219
220 220 // Autosave events
221 221 $([IPython.events]).on('autosave_disabled.Notebook', function () {
222 222 nnw.set_message("Autosave disabled", 2000);
223 223 });
224 224 $([IPython.events]).on('autosave_enabled.Notebook', function (evt, interval) {
225 225 nnw.set_message("Saving every " + interval / 1000 + "s", 1000);
226 226 });
227 227
228 228 };
229 229
230 230 IPython.NotificationArea = NotificationArea;
231 231
232 232 return IPython;
233 233
234 234 }(IPython));
235 235
@@ -1,35 +1,35
1 1 #notification_area {
2 2 z-index: 10;
3 3 }
4 4
5 5 .indicator_area {
6 6 color: @navbarLinkColor;
7 7 padding: 4px 3px;
8 8 margin: 0px;
9 9 width: 11px;
10 10 z-index: 10;
11 11 text-align: center;
12 12 }
13 13
14 14 #kernel_indicator {
15 15 // Pull it to the right, outside the container boundary
16 16 margin-right: -16px;
17 17 }
18 18
19 .ipython-edit-mode:before {
19 .edit_mode_icon:before {
20 20 .icon(@pencil);
21 21 }
22 22
23 .ipython-command-mode:before {
23 .command_mode_icon:before {
24 24 .icon(' ');
25 25 }
26 26
27 .ipython-kernel-idle:before {
27 .kernel_idle_icon:before {
28 28 .icon(@circle-blank);
29 29 }
30 30
31 .ipython-kernel-busy:before {
31 .kernel_busy_icon:before {
32 32 .icon(@circle);
33 33 }
34 34
35 35
General Comments 0
You need to be logged in to leave comments. Login now