##// END OF EJS Templates
Clear window title when kernel is restarted...
Takafumi Arakaki -
Show More
@@ -1,123 +1,125
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Copyright (C) 2008-2011 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
13
14 var utils = IPython.utils;
14 var utils = IPython.utils;
15
15
16
16
17 var NotificationWidget = function (selector) {
17 var NotificationWidget = function (selector) {
18 this.selector = selector;
18 this.selector = selector;
19 this.timeout = null;
19 this.timeout = null;
20 this.busy = false;
20 this.busy = false;
21 if (this.selector !== undefined) {
21 if (this.selector !== undefined) {
22 this.element = $(selector);
22 this.element = $(selector);
23 this.style();
23 this.style();
24 this.bind_events();
24 this.bind_events();
25 }
25 }
26 };
26 };
27
27
28
28
29 NotificationWidget.prototype.style = function () {
29 NotificationWidget.prototype.style = function () {
30 this.element.addClass('ui-widget ui-widget-content ui-corner-all');
30 this.element.addClass('ui-widget ui-widget-content ui-corner-all');
31 this.element.addClass('border-box-sizing');
31 this.element.addClass('border-box-sizing');
32 };
32 };
33
33
34
34
35 NotificationWidget.prototype.bind_events = function () {
35 NotificationWidget.prototype.bind_events = function () {
36 var that = this;
36 var that = this;
37 // Kernel events
37 // Kernel events
38 $([IPython.events]).on('status_idle.Kernel',function () {
38 $([IPython.events]).on('status_idle.Kernel',function () {
39 IPython.save_widget.update_document_title();
39 IPython.save_widget.update_document_title();
40 if (that.get_message() === 'Kernel busy') {
40 if (that.get_message() === 'Kernel busy') {
41 that.element.fadeOut(100, function () {
41 that.element.fadeOut(100, function () {
42 that.element.html('');
42 that.element.html('');
43 });
43 });
44 };
44 };
45 });
45 });
46 $([IPython.events]).on('status_busy.Kernel',function () {
46 $([IPython.events]).on('status_busy.Kernel',function () {
47 window.document.title='(Busy) '+window.document.title;
47 window.document.title='(Busy) '+window.document.title;
48 that.set_message("Kernel busy");
48 that.set_message("Kernel busy");
49 });
49 });
50 $([IPython.events]).on('status_restarting.Kernel',function () {
50 $([IPython.events]).on('status_restarting.Kernel',function () {
51 IPython.save_widget.update_document_title();
51 that.set_message("Restarting kernel",500);
52 that.set_message("Restarting kernel",500);
52 });
53 });
53 $([IPython.events]).on('status_interrupting.Kernel',function () {
54 $([IPython.events]).on('status_interrupting.Kernel',function () {
54 that.set_message("Interrupting kernel",500);
55 that.set_message("Interrupting kernel",500);
55 });
56 });
56 $([IPython.events]).on('status_dead.Kernel',function () {
57 $([IPython.events]).on('status_dead.Kernel',function () {
57 IPython.notebook.kernel.stop_channels();
58 IPython.notebook.kernel.stop_channels();
58 var dialog = $('<div/>');
59 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 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 $(document).append(dialog);
61 dialog.dialog({
62 dialog.dialog({
62 resizable: false,
63 resizable: false,
63 modal: true,
64 modal: true,
64 title: "Dead kernel",
65 title: "Dead kernel",
65 buttons : {
66 buttons : {
66 "Restart": function () {
67 "Restart": function () {
68 IPython.save_widget.update_document_title();
67 that.set_message("Restarting kernel",500);
69 that.set_message("Restarting kernel",500);
68 IPython.notebook.start_kernel();
70 IPython.notebook.start_kernel();
69 $(this).dialog('close');
71 $(this).dialog('close');
70 },
72 },
71 "Continue running": function () {
73 "Continue running": function () {
72 $(this).dialog('close');
74 $(this).dialog('close');
73 }
75 }
74 }
76 }
75 });
77 });
76 });
78 });
77 // Notebook events
79 // Notebook events
78 $([IPython.events]).on('notebook_loading.Notebook', function () {
80 $([IPython.events]).on('notebook_loading.Notebook', function () {
79 that.set_message("Loading notebook",500);
81 that.set_message("Loading notebook",500);
80 });
82 });
81 $([IPython.events]).on('notebook_loaded.Notebook', function () {
83 $([IPython.events]).on('notebook_loaded.Notebook', function () {
82 that.set_message("Notebook loaded",500);
84 that.set_message("Notebook loaded",500);
83 });
85 });
84 $([IPython.events]).on('notebook_saving.Notebook', function () {
86 $([IPython.events]).on('notebook_saving.Notebook', function () {
85 that.set_message("Saving notebook",500);
87 that.set_message("Saving notebook",500);
86 });
88 });
87 $([IPython.events]).on('notebook_saved.Notebook', function () {
89 $([IPython.events]).on('notebook_saved.Notebook', function () {
88 that.set_message("Notebook saved",500);
90 that.set_message("Notebook saved",500);
89 });
91 });
90 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
92 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
91 that.set_message("Notebook save failed",500);
93 that.set_message("Notebook save failed",500);
92 });
94 });
93 };
95 };
94
96
95
97
96 NotificationWidget.prototype.set_message = function (msg, timeout) {
98 NotificationWidget.prototype.set_message = function (msg, timeout) {
97 var that = this;
99 var that = this;
98 this.element.html(msg);
100 this.element.html(msg);
99 this.element.fadeIn(100);
101 this.element.fadeIn(100);
100 if (this.timeout !== null) {
102 if (this.timeout !== null) {
101 clearTimeout(this.timeout);
103 clearTimeout(this.timeout);
102 this.timeout = null;
104 this.timeout = null;
103 };
105 };
104 if (timeout !== undefined) {
106 if (timeout !== undefined) {
105 this.timeout = setTimeout(function () {
107 this.timeout = setTimeout(function () {
106 that.element.fadeOut(100, function () {that.element.html('');});
108 that.element.fadeOut(100, function () {that.element.html('');});
107 that.timeout = null;
109 that.timeout = null;
108 }, timeout)
110 }, timeout)
109 };
111 };
110 };
112 };
111
113
112
114
113 NotificationWidget.prototype.get_message = function () {
115 NotificationWidget.prototype.get_message = function () {
114 return this.element.html();
116 return this.element.html();
115 };
117 };
116
118
117
119
118 IPython.NotificationWidget = NotificationWidget;
120 IPython.NotificationWidget = NotificationWidget;
119
121
120 return IPython;
122 return IPython;
121
123
122 }(IPython));
124 }(IPython));
123
125
General Comments 0
You need to be logged in to leave comments. Login now