Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python autocomplete #997

Merged
merged 2 commits into from
Oct 18, 2021
Merged

Conversation

lassoan
Copy link
Member

@lassoan lassoan commented Oct 13, 2021

Fix incorrect autocomplete in the Python console and improve ordering of attributes in the autocomplete list.

Autocomplete returned list of attributes for non-existing members of a class. For example: `myobj.nonexisting.a` returned all the completions for `myobj.a`.
Fixed by clearing the list of completions if a non-existing attribute is used.

Also fixed the interpreter getting stuck in an error state after invalid autocomplete (or other Python errors).
Fixed by always resetting the error state before command execution and after failed command executions.
Before this change, a strict alphabetical sorting was used, which means that order of attributes was:
- uppercase letters: constants + internal classes + VTK methods
- underscore: private attributes
- lowercase letters: Python and Qt attributes and methods

For example attributes of a Qt class:

```
AllowNestedDocks
AllowTabbedDocks
AnimatedDocks
DockOption()
...
PdmPhysicalDpiY
PdmWidth
PdmWidthMM
RenderFlag()
RenderFlags()
VerticalTabs
__bool__()
__class__()
__delattr__()
__dict__
__dir__()
__doc__
__eq__()
__format__()
...
__setattr__()
__sizeof__()
__str__()
__subclasshook__()
__weakref__
acceptDrops
accessibleDescription
accessibleName
actionEvent()
addToolBar()
...
windowRole()
windowState()
windowTitle
windowTitleChanged()
windowType()
x
y
```

This means that the user must scroll through a lot of irrelevant parts before gets to method names.

After this change, attributes are grouped into the following categories and displayed in this order:
- Python and Qt attributes and methods (starts with lowercase letter)
- VTK methods + static classes and types (starts with uppercase letter, ends with parenthesis)
- constants (starts with uppercase letter, does not end with parenthesis)
- private attributes (starts with underscore)

Case insensitive comparison is used within each group.

Example:

```
acceptDrops
accessibleDescription
accessibleName
actionEvent()
actions()
activateWindow()
addAction()
...
windowType()
winId()
x
y
DockOption()
DockOptions()
PaintDeviceMetric()
RenderFlag()
RenderFlags()
AllowNestedDocks
AllowTabbedDocks
AnimatedDocks
DrawChildren
...
PdmWidthMM
VerticalTabs
__bool__()
__class__()
__delattr__()
...
__str__()
__subclasshook__()
__weakref__
```
@lassoan lassoan requested a review from jcfr October 13, 2021 15:42
@lassoan lassoan self-assigned this Oct 13, 2021
@lassoan
Copy link
Member Author

lassoan commented Oct 18, 2021

Since there are no objections and the changes are mostly trivial, I'll go on and merge this today.

@lassoan lassoan merged commit 08461b3 into commontk:master Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant