[IPython-User] More candidates in qtconsole auto-completion

Matthias BUSSONNIER bussonniermatthias@gmail....
Fri Sep 21 02:31:09 CDT 2012

Le 21 sept. 2012 à 06:12, klo uo a écrit :

> This is example for auto-completion in IPython terminal console:
> ========================================
> In [3]: api.
> api.AdaptToWordStr                 api.GetMutableIterator             api.PrintVariables
> api.AllWordConfidences             api.GetPageSegMode                 api.ProcessPage
> api.AnalyseLayout                  api.GetRegions                     api.ProcessPages
> api.Clear                          api.GetStringVariable              api.ReadConfigFile
> api.ClearAdaptiveClassifier        api.GetStrips                      api.ReadDebugConfigFile
> api.DeleteBlockList                api.GetTextDirection               api.Recognize
> api.DetectOS                       api.GetTextlines                   api.RecognizeForChopTest
> api.DumpPGM                        api.GetThresholdedImage            api.RunAdaptiveClassifier
> api.End                            api.GetThresholdedImageScaleFactor api.SetDebugVariable
> api.FindLinesCreateBlockList       api.GetUNLVText                    api.SetImage
> api.FindRowForBox                  api.GetUTF8Text                    api.SetInputName
> api.GetBlockTextOrientations       api.GetUnichar                     api.SetOutputName
> api.GetBoolVariable                api.GetVariableAsString            api.SetPageSegMode
> api.GetBoxText                     api.GetWords                       api.SetRectangle
> api.GetConnectedComponents         api.Init                           api.SetSourceResolution
> api.GetCubeRecoContext             api.InitForAnalysePage             api.SetVariable
> api.GetDawg                        api.InitLangMod                    api.TesseractRect
> api.GetDoubleVariable              api.InitTruthCallback              api.Version
> api.GetFeaturesForBlob             api.IsValidWord                    api.oem
> api.GetHOCRText                    api.MakeTBLOB                      api.set_min_orientation_margin
> api.GetInitLanguagesAsString       api.MakeTessOCRRow                 api.tesseract
> api.GetIntVariable                 api.MeanTextConf                   api.this
> api.GetIterator                    api.NormalizeTBLOB
> api.GetLoadedLanguagesAsVector     api.NumDawgs
> ========================================
> This is in IPython qtconsole:
> ========================================
> In [3]: api.
> AdaptToWordStr                  GetUTF8Text                 tesseract
> AllWordConfidences              GetUnichar                  this
> AnalyseLayout                   GetVariableAsString           
> Clear                           GetWords            
> ClearAdaptiveClassifier         Init                
> DeleteBlockList                 InitForAnalysePage  
> DetectOS                        InitLangMod         
> DumpPGM                         InitTruthCallback   
> ...                             ...                         ...
> ========================================
> I believe it's because of the initial size of IPython qtconsole window upon startup, which I resized afterwards before entering commands, but it had no effect.

Yes, it is hard coded, not related to the qtconsole size. 
You would have to update the width of the completion_widget when resizing windows for the number of columns.
This should not be too hard, just to bind the correct signal.
The number of rows could just be made a Trait to be configurable[*]. 

One of the reason to keep a "low" number of column is that with ultra wide qtconsole navigation become a pain. 
For example, with 16 completions, with 4 by 4 any item is at Manhattan distance of less than 4 than any other, instead of 8 for 1x16
But I guess the current behavior could be improved for sure.

> Also in qtconsole we can use TAB once again (after evoking auto-completion) and enter in some kind of table mode, which traverses by row while table is made alphabetical by column. It would be more intuitive when table would be generated alphabetically by row,
I assure you that is would not be as you more easily see the differences when items are order vertically.

api.getString                   api.getStrings


especially for non native english readers. 

It would have been much more easier on implementation side to do so, but common shell like bash or zsh
came across the same problem and decided to do it by column so I think this is the good choice. 

> as that's how cursor TAB interaction has been made.

There is no good answer with how tab works. 
The behavior I came up with is quite tricky

you might have seen that when going over the
(1) edge on right it goes to next line, 
(2) at the end of a column with arrow it goes to next column.

The problem here, is that when you have few completion (one line).
You obviously want tab to cycle through your completions. 

So either you have it go horizontally, or vertically. 
Well obviously if vertical you want (2) otherwise you are stuck with the current completion when pressing tab.

But this come with 2 drawbacks. 
  * First is that sometime tab make the cursor go horizontally (one completion line) , sometime vertically (several line completion), 
              and trust me your brain get confused and your visual memory hurts a lot. 
  * with several line completion (lets say 30) keeping tab press make the completion scroll, so it's unreadable

But his is what zsh does, and it drives (at least me) crazy.

Horizontal does indeed not cycle alphabetically, but is it really useful when you look for something ?
You can still use the arrow keys if you want to move vertically.

Writing this was much more complicated to do than I first thought, but I'll be happy if you find a better solution than mine. 

If you wan't to give a shot a making things configurable, or write your on completer-gui, take a look at 
ipython/IPython/frontend/qt/console/console_widget.py  :  L96

> Anyhow, can I configure qtconsole to roll more candidates on auto-completion?
Well, for now you will have to digg in the code a little.
but keep us informed or send a PR if you get something, or need more pointers. 

[*] I'm not sure it will be strait forward to make it configurable as it inherit from QWidget, and you will have to set the metaclass to something like  MetaQObjectHasTraits

> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20120921/7c588a94/attachment-0001.html 

More information about the IPython-User mailing list