Show More
@@ -8,19 +8,20 b'' | |||||
8 | //============================================================================ |
|
8 | //============================================================================ | |
9 | // Tooltip |
|
9 | // Tooltip | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
||||
12 | // Todo : |
|
|||
13 | // use codemirror highlight example to |
|
|||
14 | // highlight the introspection request and introspect on mouse hove ... |
|
|||
15 | // |
|
|||
16 | // |
|
11 | // | |
|
12 | // you can set the autocall time by setting `IPython.notebook.time_before_tooltip` in ms | |||
|
13 | ||||
17 | var IPython = (function (IPython) { |
|
14 | var IPython = (function (IPython) { | |
18 |
|
15 | |||
19 | var utils = IPython.utils; |
|
16 | var utils = IPython.utils; | |
20 |
|
17 | |||
|
18 | // tooltip constructor | |||
21 | var Tooltip = function (notebook) { |
|
19 | var Tooltip = function (notebook) { | |
22 | this.tooltip = $('#tooltip'); |
|
|||
23 | var that = this; |
|
20 | var that = this; | |
|
21 | ||||
|
22 | // handle to html | |||
|
23 | this.tooltip = $('#tooltip'); | |||
|
24 | var tooltip = this.tooltip; | |||
24 | this._hidden = true; |
|
25 | this._hidden = true; | |
25 |
|
26 | |||
26 | // variable for consecutive call |
|
27 | // variable for consecutive call | |
@@ -35,16 +36,14 b' var IPython = (function (IPython) {' | |||||
35 | this.buttons = $('<div/>') |
|
36 | this.buttons = $('<div/>') | |
36 | .addClass('tooltipbuttons'); |
|
37 | .addClass('tooltipbuttons'); | |
37 |
|
38 | |||
38 |
// will contain the docstring |
|
39 | // will contain the docstring | |
39 | this.text = $('<div/>') |
|
40 | this.text = $('<div/>') | |
40 | .addClass('tooltiptext') |
|
41 | .addClass('tooltiptext') | |
41 | .addClass('smalltooltip'); |
|
42 | .addClass('smalltooltip'); | |
42 |
|
||||
43 | var tooltip = this.tooltip; |
|
|||
44 |
|
43 | |||
45 |
|
|
44 | // build the buttons menu on the upper right | |
46 |
|
45 | |||
47 |
|
|
46 | // expand the tooltip to see more | |
48 | var expandlink=$('<a/>').attr('href',"#") |
|
47 | var expandlink=$('<a/>').attr('href',"#") | |
49 | .addClass("ui-corner-all") //rounded corner |
|
48 | .addClass("ui-corner-all") //rounded corner | |
50 | .attr('role',"button") |
|
49 | .attr('role',"button") | |
@@ -79,7 +78,7 b' var IPython = (function (IPython) {' | |||||
79 | closelink.click(function(){ |
|
78 | closelink.click(function(){ | |
80 | that.remove_and_cancel_tooltip(true); |
|
79 | that.remove_and_cancel_tooltip(true); | |
81 | }); |
|
80 | }); | |
82 |
|
81 | |||
83 | //construct the tooltip |
|
82 | //construct the tooltip | |
84 | // add in the reverse order you want them to appear |
|
83 | // add in the reverse order you want them to appear | |
85 | this.buttons.append(closelink); |
|
84 | this.buttons.append(closelink); | |
@@ -88,13 +87,16 b' var IPython = (function (IPython) {' | |||||
88 |
|
87 | |||
89 | // we need a phony element to make the small arrow |
|
88 | // we need a phony element to make the small arrow | |
90 | // of the tooltip in css |
|
89 | // of the tooltip in css | |
91 |
// we |
|
90 | // we will move the arrow later | |
92 | this.arrow = $('<div/>').addClass('pretooltiparrow'); |
|
91 | this.arrow = $('<div/>').addClass('pretooltiparrow'); | |
93 | this.tooltip.append(this.buttons); |
|
92 | this.tooltip.append(this.buttons); | |
94 | this.tooltip.append(this.arrow); |
|
93 | this.tooltip.append(this.arrow); | |
95 | this.tooltip.append(this.text); |
|
94 | this.tooltip.append(this.text); | |
96 | }; |
|
95 | }; | |
97 |
|
96 | |||
|
97 | // will resend the request on behalf on the cell which invoked the tooltip | |||
|
98 | // to show in it in pager. This is done so to be sure of having the same | |||
|
99 | // result as invoking `something?` | |||
98 | Tooltip.prototype.showInPager = function() |
|
100 | Tooltip.prototype.showInPager = function() | |
99 | { |
|
101 | { | |
100 | var msg_id = IPython.notebook.kernel.execute(that.name+"?"); |
|
102 | var msg_id = IPython.notebook.kernel.execute(that.name+"?"); | |
@@ -103,7 +105,7 b' var IPython = (function (IPython) {' | |||||
103 | this._cmfocus(); |
|
105 | this._cmfocus(); | |
104 | } |
|
106 | } | |
105 |
|
107 | |||
106 |
|
108 | // grow the tooltip verticaly | ||
107 | Tooltip.prototype.expand = function(){ |
|
109 | Tooltip.prototype.expand = function(){ | |
108 | this.text.removeClass('smalltooltip'); |
|
110 | this.text.removeClass('smalltooltip'); | |
109 | this.text.addClass('bigtooltip'); |
|
111 | this.text.addClass('bigtooltip'); | |
@@ -124,11 +126,6 b' var IPython = (function (IPython) {' | |||||
124 | this._hidden = true; |
|
126 | this._hidden = true; | |
125 | } |
|
127 | } | |
126 |
|
128 | |||
127 | //TODO, try to diminish the number of parameters. |
|
|||
128 | Tooltip.prototype.request_tooltip_after_time = function (pre_cursor,time){ |
|
|||
129 | }; |
|
|||
130 |
|
||||
131 |
|
||||
132 | Tooltip.prototype.remove_and_cancel_tooltip = function(force) { |
|
129 | Tooltip.prototype.remove_and_cancel_tooltip = function(force) { | |
133 | // note that we don't handle closing directly inside the calltip |
|
130 | // note that we don't handle closing directly inside the calltip | |
134 | // as in the completer, because it is not focusable, so won't |
|
131 | // as in the completer, because it is not focusable, so won't | |
@@ -143,18 +140,22 b' var IPython = (function (IPython) {' | |||||
143 | this._consecutive_conter = 0; |
|
140 | this._consecutive_conter = 0; | |
144 | } |
|
141 | } | |
145 |
|
142 | |||
|
143 | // cancel autocall done after '(' for example. | |||
146 | Tooltip.prototype.cancel_pending = function(){ |
|
144 | Tooltip.prototype.cancel_pending = function(){ | |
147 | if (this.tooltip_timeout != null){ |
|
145 | if (this.tooltip_timeout != null){ | |
148 | clearTimeout(this.tooltip_timeout); |
|
146 | clearTimeout(this.tooltip_timeout); | |
149 | this.tooltip_timeout = null; |
|
147 | this.tooltip_timeout = null; | |
150 | } |
|
148 | } | |
151 | } |
|
149 | } | |
152 |
|
150 | |||
|
151 | // will trigger tooltip after timeout | |||
153 | Tooltip.prototype.pending = function(cell,text) |
|
152 | Tooltip.prototype.pending = function(cell,text) | |
154 | { |
|
153 | { | |
155 | var that = this; |
|
154 | var that = this; | |
156 | this.tooltip_timeout = setTimeout(function(){that.request(cell)} , IPython.notebook.time_before_tooltip); |
|
155 | this.tooltip_timeout = setTimeout(function(){that.request(cell)} , IPython.notebook.time_before_tooltip); | |
157 | } |
|
156 | } | |
|
157 | ||||
|
158 | // make an imediate completion request | |||
158 | Tooltip.prototype.request = function(cell) |
|
159 | Tooltip.prototype.request = function(cell) | |
159 | { |
|
160 | { | |
160 | this.cancel_pending(); |
|
161 | this.cancel_pending(); | |
@@ -187,7 +188,7 b' var IPython = (function (IPython) {' | |||||
187 | { |
|
188 | { | |
188 | console.log('should open in pager'); |
|
189 | console.log('should open in pager'); | |
189 | this._old_cell = null ; |
|
190 | this._old_cell = null ; | |
190 |
this._cancel_stick |
|
191 | this._cancel_stick(); | |
191 | this._old_request = null ; |
|
192 | this._old_request = null ; | |
192 | this._consecutive_conter = 0; |
|
193 | this._consecutive_conter = 0; | |
193 | this.showInPager(); |
|
194 | this.showInPager(); | |
@@ -205,26 +206,31 b' var IPython = (function (IPython) {' | |||||
205 | } |
|
206 | } | |
206 | IPython.notebook.request_tool_tip(cell, text); |
|
207 | IPython.notebook.request_tool_tip(cell, text); | |
207 | } |
|
208 | } | |
|
209 | ||||
|
210 | // cancel the option of having the tooltip to stick | |||
208 | Tooltip.prototype.cancel_stick = function() |
|
211 | Tooltip.prototype.cancel_stick = function() | |
209 | { |
|
212 | { | |
210 | clearTimeout(this._stick_timeout); |
|
213 | clearTimeout(this._stick_timeout); | |
211 | this._sticky = false; |
|
214 | this._sticky = false; | |
212 | } |
|
215 | } | |
213 |
|
216 | |||
214 | Tooltip.prototype.stick = function() |
|
217 | // put the tooltip in a sicky state for 10 seconds | |
|
218 | // it won't be removed by remove_and_cancell() unless you called with | |||
|
219 | // the first parameter set to true. | |||
|
220 | // remove_and_cancell_tooltip(true) | |||
|
221 | Tooltip.prototype.stick = function() | |||
215 | { |
|
222 | { | |
216 | console.log('tooltip will stick for at least 10 sec'); |
|
223 | console.log('tooltip will stick for at least 10 sec'); | |
217 |
var that = this; |
|
224 | var that = this; | |
218 | this._sticky = true; |
|
225 | this._sticky = true; | |
219 | this._stick_timeout = setTimeout( function(){ |
|
226 | this._stick_timeout = setTimeout( function(){ | |
220 | that._sticky = false; |
|
227 | that._sticky = false; | |
221 | console.log('tooltip will not stick anymore'); |
|
228 | console.log('tooltip will not stick anymore'); | |
222 | }, 10*1000 |
|
229 | }, 10*1000 | |
223 | ); |
|
230 | ); | |
224 |
|
||||
225 |
|
||||
226 | } |
|
231 | } | |
227 |
|
232 | |||
|
233 | // should be called with the kernel reply to actually show the tooltip | |||
228 | Tooltip.prototype.show = function(reply, codecell) |
|
234 | Tooltip.prototype.show = function(reply, codecell) | |
229 | { |
|
235 | { | |
230 | // move the bubble if it is not hidden |
|
236 | // move the bubble if it is not hidden | |
@@ -242,12 +248,12 b' var IPython = (function (IPython) {' | |||||
242 | var xinit = pos.x; |
|
248 | var xinit = pos.x; | |
243 | var xinter = o.left + (xinit-o.left)/w*(w-450); |
|
249 | var xinter = o.left + (xinit-o.left)/w*(w-450); | |
244 | var posarrowleft = xinit - xinter; |
|
250 | var posarrowleft = xinit - xinter; | |
245 |
|
251 | |||
246 |
|
252 | |||
247 | if( this._hidden == false) |
|
253 | if( this._hidden == false) | |
248 | { |
|
254 | { | |
249 | this.tooltip.animate({'left' : xinter-30+'px','top' :(pos.yBot+10)+'px'}); |
|
255 | this.tooltip.animate({'left' : xinter-30+'px','top' :(pos.yBot+10)+'px'}); | |
250 |
} else |
|
256 | } else | |
251 | { |
|
257 | { | |
252 | this.tooltip.css({'left' : xinter-30+'px'}); |
|
258 | this.tooltip.css({'left' : xinter-30+'px'}); | |
253 | this.tooltip.css({'top' :(pos.yBot+10)+'px'}); |
|
259 | this.tooltip.css({'top' :(pos.yBot+10)+'px'}); | |
@@ -277,25 +283,15 b' var IPython = (function (IPython) {' | |||||
277 | this.text.append(pre); |
|
283 | this.text.append(pre); | |
278 | // keep scroll top to be sure to always see the first line |
|
284 | // keep scroll top to be sure to always see the first line | |
279 | this.text.scrollTop(0); |
|
285 | this.text.scrollTop(0); | |
280 |
|
||||
281 |
|
||||
282 | } |
|
|||
283 |
|
||||
284 | Tooltip.prototype.showInPager = function(text){ |
|
|||
285 | var msg_id = IPython.notebook.kernel.execute(this.name+"?"); |
|
|||
286 | IPython.notebook.msg_cell_map[msg_id] = IPython.notebook.get_selected_cell().cell_id; |
|
|||
287 | this.remove_and_cancel_tooltip(true); |
|
|||
288 | this._cmfocus(); |
|
|||
289 | } |
|
286 | } | |
290 |
|
287 | |||
|
288 | // convenient funciton to have the correct codemirror back into focus | |||
291 | Tooltip.prototype._cmfocus = function() |
|
289 | Tooltip.prototype._cmfocus = function() | |
292 | { |
|
290 | { | |
293 | var cm = this.code_mirror; |
|
291 | var cm = this.code_mirror; | |
294 | setTimeout(function(){cm.focus();}, 50); |
|
292 | setTimeout(function(){cm.focus();}, 50); | |
295 | } |
|
293 | } | |
296 |
|
294 | |||
297 |
|
||||
298 | IPython.Tooltip = Tooltip; |
|
295 | IPython.Tooltip = Tooltip; | |
299 |
|
||||
300 | return IPython; |
|
296 | return IPython; | |
301 | }(IPython)); |
|
297 | }(IPython)); |
General Comments 0
You need to be logged in to leave comments.
Login now