Skip to content

ENH: show variable value as a tootip on mouse hover #25818

@dpturibio

Description

@dpturibio

I would like to propose an enhancement in code editor.
When you hover mouse on a variable, a tooltip is popped-up with message: "This is a (string/integer/list/bool/..etc)".

Image

It is interesting for me and the team that I work with, that the value of the variable is popped-up(if it is already on variable explorer). Otherwise, continue to show "This is a ....." message.
The reason it that when we are debugging a code, it is not so efficient to look for variables in variable explorer or type it in IPython console.

Therefore, I propose something like this bellow:

Image

I made an initial version of this changing codeeditor.py, class CodeEditor, method _handle_hove as follows:

            text = self.get_word_at(pos)
            value = None
            if text:
                try:
                    main = self.window()
                    shell = main.ipyconsole.get_current_shellwidget()
                    if shell:
                        value = shell.get_value(text)
                        if value is not None:
                            from qtpy.QtWidgets import QToolTip
                            QToolTip.showText(
                                self.mapToGlobal(pos),
                                f"{text} = {repr(value)}"
                            )
                            return
                except Exception:
                    pass

I hope I can implement this enhancement with you approval. Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions