Esempio n. 1
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 ''
Esempio n. 2
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')
Esempio n. 3
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 ''
Esempio n. 4
0
    def show_object_info(self, text, call=False, force=False):
        """Show signature calltip and/or docstring in the Help plugin"""
        text = to_text_string(text)

        # Show docstring
        help_enabled = self.help_enabled or force
        if force and self.help is not None:
            self.help.dockwidget.setVisible(True)
            self.help.dockwidget.raise_()
        if help_enabled and (self.help is not None) and \
           (self.help.dockwidget.isVisible()):
            # Help widget exists and is visible
            if hasattr(self, 'get_doc'):
                self.help.set_shell(self)
            else:
                self.help.set_shell(self.parent())
            self.help.set_object_text(text, ignore_unknown=False)
            self.setFocus()  # if help 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')
Esempio n. 5
0
    def show_object_info(self, text, call=False, force=False):
        """Show signature calltip and/or docstring in the Help plugin"""
        text = to_text_string(text)

        # Show docstring
        help_enabled = self.help_enabled or force
        if force and self.help is not None:
            self.help.dockwidget.setVisible(True)
            self.help.dockwidget.raise_()
        if help_enabled and (self.help is not None) and \
           (self.help.dockwidget.isVisible()):
            # Help widget exists and is visible
            if hasattr(self, 'get_doc'):
                self.help.set_shell(self)
            else:
                self.help.set_shell(self.parent())
            self.help.set_object_text(text, ignore_unknown=False)
            self.setFocus() # if help 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')