Exemple #1
0
 def _handle_object_info_reply(self, rep):
     """
     Reimplement call tips to only show signatures, using the same style
     from our Editor and External Console too
     Note: For IPython 2-
     """
     self.log.debug("oinfo: %s", rep.get('content', ''))
     cursor = self._get_cursor()
     info = self._request_info.get('call_tip')
     if info and info.id == rep['parent_header']['msg_id'] and \
       info.pos == cursor.position():
         content = rep['content']
         if content.get('ismagic', False):
             call_info, doc = None, None
         else:
             call_info, doc = call_tip(content, format_call=True)
             if call_info is None and doc is not None:
                 name = content['name'].split('.')[-1]
                 argspec = getargspecfromtext(doc)
                 if argspec:
                     # This covers cases like np.abs, whose docstring is
                     # the same as np.absolute and because of that a proper
                     # signature can't be obtained correctly
                     call_info = name + argspec
                 else:
                     call_info = getsignaturefromtext(doc, name)
         if call_info:
             self._control.show_calltip(_("Arguments"),
                                        call_info,
                                        signature=True,
                                        color='#2D62FF')
Exemple #2
0
 def get_signature(self, content):
     """Get signature from inspect reply content"""
     data = content.get('data', {})
     text = data.get('text/plain', '')
     if text:
         text = ANSI_OR_SPECIAL_PATTERN.sub('', text)
         self._control.current_prompt_pos = self._prompt_pos
         line = self._control.get_current_line_to_cursor()
         name = line[:-1].split('(')[-1]   # Take last token after a (
         name = name.split('.')[-1]        # Then take last token after a .
         # Clean name from invalid chars
         try:
             name = self.clean_invalid_var_chars(name).split('_')[-1]
         except:
             pass
         argspec = getargspecfromtext(text)
         if argspec:
             # This covers cases like np.abs, whose docstring is
             # the same as np.absolute and because of that a proper
             # signature can't be obtained correctly
             signature = name + argspec
         else:
             signature = getsignaturefromtext(text, name)
         return signature
     else:
         return ''
Exemple #3
0
 def _handle_object_info_reply(self, rep):
     """
     Reimplement call tips to only show signatures, using the same style
     from our Editor and External Console too
     Note: For IPython 2-
     """
     self.log.debug("oinfo: %s", rep.get('content', ''))
     cursor = self._get_cursor()
     info = self._request_info.get('call_tip')
     if info and info.id == rep['parent_header']['msg_id'] and \
       info.pos == cursor.position():
         content = rep['content']
         if content.get('ismagic', False):
             call_info, doc = None, None
         else:
             call_info, doc = call_tip(content, format_call=True)
             if call_info is None and doc is not None:
                 name = content['name'].split('.')[-1]
                 argspec = getargspecfromtext(doc)
                 if argspec:
                     # This covers cases like np.abs, whose docstring is
                     # the same as np.absolute and because of that a proper
                     # signature can't be obtained correctly
                     call_info = name + argspec
                 else:
                     call_info = getsignaturefromtext(doc, name)
         if call_info:
             self._control.show_calltip(_("Arguments"), call_info,
                                        signature=True, color='#2D62FF')
Exemple #4
0
 def get_signature(self, content):
     """Get signature from inspect reply content"""
     data = content.get('data', {})
     text = data.get('text/plain', '')
     if text:
         text = ANSI_OR_SPECIAL_PATTERN.sub('', text)
         self._control.current_prompt_pos = self._prompt_pos
         line = self._control.get_current_line_to_cursor()
         name = line[:-1].split('(')[-1]   # Take last token after a (
         name = name.split('.')[-1]        # Then take last token after a .
         # Clean name from invalid chars
         try:
             name = self.clean_invalid_var_chars(name).split('_')[-1]
         except:
             pass
         argspec = getargspecfromtext(text)
         if argspec:
             # This covers cases like np.abs, whose docstring is
             # the same as np.absolute and because of that a proper
             # signature can't be obtained correctly
             signature = name + argspec
         else:
             signature = getsignaturefromtext(text, name)
         return signature
     else:
         return ''
    def show_object_info(self, text, call=False, force=False):
        """Show signature calltip and/or docstring in the Object Inspector"""
        text = to_text_string(text)  # Useful only for ExternalShellBase

        # Show docstring
        insp_enabled = self.inspector_enabled or force
        if force and self.inspector is not None:
            self.inspector.dockwidget.setVisible(True)
            self.inspector.dockwidget.raise_()
        if insp_enabled and (self.inspector is not None) and \
           (self.inspector.dockwidget.isVisible()):
            # ObjectInspector widget exists and is visible
            self.inspector.set_shell(self)
            self.inspector.set_object_text(text, ignore_unknown=False)
            self.setFocus()  # if inspector was not at top level, raising it to
            # top will automatically give it focus because of
            # the visibility_changed signal, so we must give
            # focus back to shell

        # Show calltip
        if call and self.calltips:
            # Display argument list if this is a function call
            iscallable = self.iscallable(text)
            if iscallable is not None:
                if iscallable:
                    arglist = self.get_arglist(text)
                    name = text.split('.')[-1]
                    argspec = signature = ''
                    if isinstance(arglist, bool):
                        arglist = []
                    if arglist:
                        argspec = '(' + ''.join(arglist) + ')'
                    else:
                        doc = self.get__doc__(text)
                        if doc is not None:
                            # This covers cases like np.abs, whose docstring is
                            # the same as np.absolute and because of that a
                            # proper signature can't be obtained correctly
                            argspec = getargspecfromtext(doc)
                            if not argspec:
                                signature = getsignaturefromtext(doc, name)
                    if argspec or signature:
                        if argspec:
                            tiptext = name + argspec
                        else:
                            tiptext = signature
                        self.show_calltip(_("Arguments"),
                                          tiptext,
                                          signature=True,
                                          color='#2D62FF')
Exemple #6
0
 def show_object_info(self, text, call=False, force=False):
     """Show signature calltip and/or docstring in the Object Inspector"""
     text = to_text_string(text) # Useful only for ExternalShellBase
     
     # Show docstring
     insp_enabled = self.inspector_enabled or force
     if force and self.inspector is not None:
         self.inspector.dockwidget.setVisible(True)
         self.inspector.dockwidget.raise_()
     if insp_enabled and (self.inspector is not None) and \
        (self.inspector.dockwidget.isVisible()):
         # ObjectInspector widget exists and is visible
         self.inspector.set_shell(self)
         self.inspector.set_object_text(text, ignore_unknown=False)
         self.setFocus() # if inspector was not at top level, raising it to
                         # top will automatically give it focus because of
                         # the visibility_changed signal, so we must give
                         # focus back to shell
     
     # Show calltip
     if call and self.calltips:
         # Display argument list if this is a function call
         iscallable = self.iscallable(text)
         if iscallable is not None:
             if iscallable:
                 arglist = self.get_arglist(text)
                 name =  text.split('.')[-1]
                 argspec = signature = ''
                 if isinstance(arglist, bool):
                     arglist = []
                 if arglist:
                     argspec = '(' + ''.join(arglist) + ')'
                 else:
                     doc = self.get__doc__(text)
                     if doc is not None:
                         # This covers cases like np.abs, whose docstring is
                         # the same as np.absolute and because of that a
                         # proper signature can't be obtained correctly
                         argspec = getargspecfromtext(doc)
                         if not argspec:
                             signature = getsignaturefromtext(doc, name)
                 if argspec or signature:
                     if argspec:
                         tiptext = name + argspec
                     else:
                         tiptext = signature
                     self.show_calltip(_("Arguments"), tiptext,
                                       signature=True, color='#2D62FF')
Exemple #7
0
 def get_signature(self, content):
     """Get signature from inspect reply content"""
     data = content.get('data', {})
     text = data.get('text/plain', '')
     if text:
         text = ANSI_OR_SPECIAL_PATTERN.sub('', text)
         line = self._control.get_current_line_to_cursor()
         name = line[:-1].split('.')[-1]
         argspec = getargspecfromtext(text)
         if argspec:
             # This covers cases like np.abs, whose docstring is
             # the same as np.absolute and because of that a proper
             # signature can't be obtained correctly
             signature = name + argspec
         else:
             signature = getsignaturefromtext(text, name)
         return signature
     else:
         return ''
 def get_signature(self, content):
     """Get signature from inspect reply content"""
     data = content.get('data', {})
     text = data.get('text/plain', '')
     if text:
         text = ANSI_OR_SPECIAL_PATTERN.sub('', text)
         line = self._control.get_current_line_to_cursor()
         name = line[:-1].split('.')[-1]
         argspec = getargspecfromtext(text)
         if argspec:
             # This covers cases like np.abs, whose docstring is
             # the same as np.absolute and because of that a proper
             # signature can't be obtained correctly
             signature = name + argspec
         else:
             signature = getsignaturefromtext(text, name)
         return signature
     else:
         return ''
Exemple #9
0
 def _handle_object_info_reply(self, rep):
     """
     Reimplement call tips to only show signatures, using the same style
     from our Editor and External Console too.
     """
     self.log.debug("oinfo: %s", rep.get('content', ''))
     cursor = self._get_cursor()
     info = self._request_info.get('call_tip')
     if info and info.id == rep['parent_header']['msg_id'] and \
             info.pos == cursor.position():
         # Get the information for a call tip.  For now we format the call
         # line as string, later we can pass False to format_call and
         # syntax-highlight it ourselves for nicer formatting in the
         # calltip.
         content = rep['content']
         # if this is from pykernel, 'docstring' will be the only key
         if content.get('ismagic', False):
             # Don't generate a call-tip for magics. Ideally, we should
             # generate a tooltip, but not on ( like we do for actual
             # callables.
             call_info, doc = None, None
         else:
             call_info, doc = call_tip(content, format_call=True)
             if call_info is None and doc is not None:
                 name = content['name'].split('.')[-1]
                 argspec = getargspecfromtext(doc)
                 if argspec:
                     # This covers cases like np.abs, whose docstring is
                     # the same as np.absolute and because of that a proper
                     # signature can't be obtained correctly
                     call_info = name + argspec
                 else:
                     call_info = getsignaturefromtext(doc, name)
         if call_info:
             self._control.show_calltip(_("Arguments"),
                                        call_info,
                                        signature=True,
                                        color='#2D62FF')
Exemple #10
0
 def _handle_object_info_reply(self, rep):
     """
     Reimplement call tips to only show signatures, using the same style
     from our Editor and External Console too.
     """
     self.log.debug("oinfo: %s", rep.get('content', ''))
     cursor = self._get_cursor()
     info = self._request_info.get('call_tip')
     if info and info.id == rep['parent_header']['msg_id'] and \
             info.pos == cursor.position():
         # Get the information for a call tip.  For now we format the call
         # line as string, later we can pass False to format_call and
         # syntax-highlight it ourselves for nicer formatting in the
         # calltip.
         content = rep['content']
         # if this is from pykernel, 'docstring' will be the only key
         if content.get('ismagic', False):
             # Don't generate a call-tip for magics. Ideally, we should
             # generate a tooltip, but not on ( like we do for actual
             # callables.
             call_info, doc = None, None
         else:
             call_info, doc = call_tip(content, format_call=True)
             if call_info is None and doc is not None:
                 name = content['name'].split('.')[-1]
                 argspec = getargspecfromtext(doc)
                 if argspec:
                     # This covers cases like np.abs, whose docstring is
                     # the same as np.absolute and because of that a proper
                     # signature can't be obtained correctly
                     call_info = name + argspec
                 else:
                     call_info = getsignaturefromtext(doc, name)
         if call_info:
             self._control.show_calltip(_("Arguments"), call_info,
                                        signature=True, color='#2D62FF')