Skip to content

Draft: Autocompletion improvements for PythonShell and pvpython

This MR build upon !6917 (merged) and extends it to cover more autocomplete cases in the Python Shell of the ParaView GUI. In particular, the following cases will be autocompleted (some already present in current master)

  1. Sphere(R<TAB>) (autocompletes properties of Sphere starting with R)
  2. s.<TAB> (s is a proxy)
  3. s = Sph<TAB>
  4. s = Sphere(Radius=1,End<TAB>
  5. Connect(ds_<TAB> (or for any free function in general)
  6. S<TAB> (proxy or free functions)

In the case of proxies we use the new function paraview.simple.ListProperties(s) to get the available properties. For free functions we utilize Python's inspect module.

Also, we add preliminary support for autocompletion in pvpython for Linux and MacOS. Unfortunately, not all parts that go into the autocompletion features of the Python Shell in the GUI are exposed in python and they are also tied to Qt. So we need to re-implement some functionality. In particular, for pvpython we build a custom completer based on readline via the native Python library . Tokenizing the promt and identifying the context for completion is done only at a coarse level and it is not complete yet but it offers basic new functionality for pvpython. Currently it supports everything in the above list besides case 3.

Next Steps

  1. Tokenizing the current prompt while taking into consideration every possible case is a complex task an possibly unnecessary since pvpython/ python shell propmts are (usually) short. How much should be explore/ What are all the completion cases to consider ?
  2. readline is a UNIX utility. What about Windows ? There are thirdparty implementations which we need to evaluate and vendor.
  3. Could we move all completion logic into python or at least python-accessible classes so we can reuse as much as possible ?

Merge request reports

Loading