MCPcopy Index your code
hub / github.com/python/cpython / open_calltip

Method open_calltip

Lib/idlelib/calltip.py:57–106  ·  view source on GitHub ↗

Maybe close an existing calltip and maybe open a new calltip. Called from (force_open|try_open|refresh)_calltip_event functions.

(self, evalfuncs)

Source from the content-addressed store, hash-verified

55 self.open_calltip(False)
56
57 def open_calltip(self, evalfuncs):
58 """Maybe close an existing calltip and maybe open a new calltip.
59
60 Called from (force_open|try_open|refresh)_calltip_event functions.
61 """
62 hp = HyperParser(self.editwin, "insert")
63 sur_paren = hp.get_surrounding_brackets('(')
64
65 # If not inside parentheses, no calltip.
66 if not sur_paren:
67 self.remove_calltip_window()
68 return
69
70 # If a calltip is shown for the current parentheses, do
71 # nothing.
72 if self.active_calltip:
73 opener_line, opener_col = map(int, sur_paren[0].split('.'))
74 if (
75 (opener_line, opener_col) ==
76 (self.active_calltip.parenline, self.active_calltip.parencol)
77 ):
78 return
79
80 hp.set_index(sur_paren[0])
81 try:
82 expression = hp.get_expression()
83 except ValueError:
84 expression = None
85 if not expression:
86 # No expression before the opening parenthesis, e.g.
87 # because it's in a string or the opener for a tuple:
88 # Do nothing.
89 return
90
91 # At this point, the current index is after an opening
92 # parenthesis, in a section of code, preceded by a valid
93 # expression. If there is a calltip shown, it's not for the
94 # same index and should be closed.
95 self.remove_calltip_window()
96
97 # Simple, fast heuristic: If the preceding expression includes
98 # an opening parenthesis, it likely includes a function call.
99 if not evalfuncs and (expression.find('(') != -1):
100 return
101
102 argspec = self.fetch_tip(expression)
103 if not argspec:
104 return
105 self.active_calltip = self._calltip_window()
106 self.active_calltip.showtip(argspec, sur_paren[0], sur_paren[1])
107
108 def fetch_tip(self, expression):
109 """Return the argument list and docstring of a function or class.

Callers 4

refresh_calltip_eventMethod · 0.95
forceMethod · 0.80

Calls 9

remove_calltip_windowMethod · 0.95
set_indexMethod · 0.95
get_expressionMethod · 0.95
fetch_tipMethod · 0.95
HyperParserClass · 0.90
splitMethod · 0.45
findMethod · 0.45
showtipMethod · 0.45

Tested by 1

forceMethod · 0.64