new completer for qtconsole. #1851

Merged
merged 7 commits into from Jun 10, 2012

4 participants

@Carreau
IPython member

add a completer to the qtconsole that is navigable by arrows keys and
tab. One need to call it twice to get it on focus and be able to select
completion with Return. looks like zsh completer, not the gui drop down
list of --gui-completer.

This also try to split the completion logic from console_widget, and try
to keep the old completer qui around. The plain completer that never
takes focus back, and the QlistWidget completer.

to switch between the 3, the --gui-completion flag as been changed to
take an argument (plain, droplist, ncurses).

ipython qtconsole --gui-completion=ncurses
In[1]: r <tab> <tab> <tab> <down> <right> <right>

capture

As I'm not 100% sure of how the completion logic in the qtconsole works, i'd like you thought/testing on it.

@fperez
IPython member

My first instinct here is to say awesome! But I'd like the eyes of our Qt gurus, @jdmarch, @epatters, any opinion here?

@punchagan

It looks like a cool addition. I was just trying it out and --gui-completion=droplist crashes IPython with AttributeError: 'RichIPythonWidget' object has no attribute '_text_edit'. I can send you a full traceback, but it should be easy to reproduce.

@Carreau
IPython member

Thanks, I'll fix that, I also still have to clean some code and deduplicate some other.

@Carreau
IPython member

fix the --gui-completion=droplist ( already exist in master as just --gui-completion).
And also a bug where Ctrl+Gor esc wouldn't worked after invoking the completer.

@ellisonbg
IPython member

I tested this out and functionally this is great. I really like it. The only glitch I saw is the following: when the list of completions is longer than the size of the terminal (from enthought.traits import api; api.<tab>), it works fine for the entries that show at the top. But for entries that you have to scroll down to reach, it doesn't work.

@Carreau
IPython member

I'll take a look, or limit the number of completion.
I have a cleaner version that reuse more code, i'll push later.

@Carreau
IPython member

rebased on top of #1875 to share more code with columnize. and limit the number of completion lines to 9.

@fperez
IPython member

Mmh, it seems to me in the last revision you forgot to add a file, perhaps?

With this branch, it simply doesn't start for me at all:

dreamweaver[junk]> ipython qtconsole
Traceback (most recent call last):
  File "/home/fperez/usr/bin/ipython", line 7, in <module>
    launch_new_instance()
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 365, in launch_new_instance
    app.initialize()
  File "<string>", line 2, in initialize
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/config/application.py", line 84, in catch_config_error
    return method(app, *args, **kwargs)
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 290, in initialize
    super(TerminalIPythonApp, self).initialize(argv)
  File "<string>", line 2, in initialize
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/config/application.py", line 84, in catch_config_error
    return method(app, *args, **kwargs)
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/core/application.py", line 325, in initialize
    self.parse_command_line(argv)
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 285, in parse_command_line
    return super(TerminalIPythonApp, self).parse_command_line(argv)
  File "<string>", line 2, in parse_command_line
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/config/application.py", line 84, in catch_config_error
    return method(app, *args, **kwargs)
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/config/application.py", line 420, in parse_command_line
    return self.initialize_subcommand(subc, subargv)
  File "<string>", line 2, in initialize_subcommand
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/config/application.py", line 84, in catch_config_error
    return method(app, *args, **kwargs)
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/config/application.py", line 352, in initialize_subcommand
    subapp = import_item(subapp)
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/utils/importstring.py", line 40, in import_item
    module = __import__(package,fromlist=[obj])
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/frontend/qt/console/qtconsoleapp.py", line 63, in <module>
    from IPython.frontend.qt.console.frontend_widget import FrontendWidget
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/frontend/qt/console/frontend_widget.py", line 22, in <module>
    from history_console_widget import HistoryConsoleWidget
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/frontend/qt/console/history_console_widget.py", line 6, in <module>
    from console_widget import ConsoleWidget
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/frontend/qt/console/console_widget.py", line 26, in <module>
    from completion_plain import CompletionPlain
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/frontend/qt/console/completion_plain.py", line 3, in <module>
    import IPython.utils.html_utils as html_utils
ImportError: No module named html_utils
@Carreau
IPython member

Sorry, I think I was tired, I rebased a remote branch that I forgot to push from work, so many things were missing, and the .pyc files still present made it work at home...

Should be fixed now, It also allowed me to simplifie more things.

@fperez
IPython member

When the list of completions doesn't fit in a single group, there's no way to show the rest (and no indication there are more). How about putting at the end a 'more' entry that loads a new page? If a second page is loaded, then there should be a way to go back to the first.

Try it with import numpy as np, np.<tab>, you only see the first set...

Carreau added some commits Jun 6, 2012
@Carreau Carreau re-write columnize, with intermediate step.
fix test that where wrong, add some others.

fix #1860
981ef5c
@Carreau Carreau fix docstring, and debug leftover 4659fca
@Carreau Carreau new completer for qtconsole.
add a completer to the qtconsole that is navigable by arraow keys and
tab. One need to call it twice to get it on focus and be able to select
completion with Return. looks like zsh completer, not the gui drop down
list of --gui-completer.

This also try to split the completion logic from console_widget, and try
to keep the old completer qui around. The plain completer that never
takes focus back, and the QlistWidget completer.

to switch between the 3, the --gui-completion flag as been changed to
take an argument (plain, droplist, ncurses).
1422d27
@Carreau Carreau fix gui=droplist 3cb4e60
@Carreau Carreau fix Ctrl+G/esc intercepted bug f7faea8
@Carreau Carreau add option to choose for empty ef8d7e2
@Carreau Carreau new completer for qtconsole
add a completer to the qtconsole that is navigable by arrows keys and
tab. One need to call it twice to get it on focus and be able to select
completion with Return. looks like zsh completer, not the gui drop down
list of --gui-completer.

This also try to split the completion logic from console_widget, and try
to keep the old completer qui around. The plain completer that never
takes focus back, and the QlistWidget completer.

to switch between the 3, the --gui-completion flag as been changed to
take an argument (plain, droplist, ncurses)

completer also autoscroll and show `...` when rows are hidden
68781aa
@Carreau
IPython member

how does this look like ?
cap
If you try to go up or down it scrolls. of course the ... disapears when at top or bottom...

I rebase and squash because the rebased on top of #1875 was painfull.

@ellisonbg
IPython member
@Carreau
IPython member

Thanks, it took me several shot to have it right. If someone want to modifie to add PgUp/PgDown, go ahead, I just need a break from this one for a few days, and i'm not ready to try to make it work 'as you type', but it should be doable.
We can keep this for SciPy sprint.

@fperez
IPython member

Beautiful!! You've done a terrific job here, and I commend you for it. Many thanks for your patience with all my minute requirements.

I'm going to merge this now, as it's really a great improvement, to reduce the chance of conflicts. We can always do another round of improvements on it later from master.

Thanks again for your great work!

@fperez fperez merged commit 45d28c5 into ipython:master Jun 10, 2012
@Carreau
IPython member

It was really bugging me because I'm really used to it in zsh, so it is also really a relief for me to be able to tabs through completion.
I hope that it will be one of the many details that will make IPython aven more impressive at SciPy. BTW, i've been selected for the sponsorship, and I'm now waiting for the detail to prepare my trip. So I'll be there to give you a hand for the presentation :-)

See you there.

@fperez
IPython member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment