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