Ticket #8210 (closed: wontfix)

Opened 7 years ago

Last modified 5 years ago

Filter QObject/QWidget inherited methods as tab completion options on MantidPlot objects

Reported by: Russell Taylor Owned by: Russell Taylor
Priority: major Milestone: Release 3.2
Component: GUI Keywords: IPython
Cc: Blocked By:
Blocking: Tester: Michael Reuter

Description

#4311 fixed the issue of missing tab-completion options on our wrapped _qti objects in MantidPlot. By modifying dir to return relevant methods from the wrapped object you see those methods instead of the methods of the proxy object (QtProxyObject).

However, the methods that we've defined are rather swamped by the inherited QObject/QWidget ones and it would be nice to filter those out as users should very rarely need them. Code something like this would filter the list:

heldobjectmethods = dir(self._getHeldObject())
qwidgetmethods = dir(QtGui.QWidget)
return [m for m in heldobjectmethods if m not in qwidgetmethods]

However, this doesn't completely work because IPython explicitly goes looking for base class methods and adds them to its completions options. In this case, it adds all the QObject methods as this is the base of QtProxyObject.

There is a possibility to have IPython look at the all attribute for the completion options - and in this case it would not add base class methods. This requires adjusting the IPython configuration programmatically. In doing so, we would not want to prevent the user from being able to configure their IPython options themselves.

Change History

comment:1 Changed 7 years ago by Russell Taylor

  • Milestone changed from Release 3.1 to Backlog

comment:2 Changed 7 years ago by Russell Taylor

  • Milestone changed from Backlog to Release 3.2

comment:3 Changed 7 years ago by Nick Draper

  • Status changed from new to assigned

Bulk move of tickets out of triage (new) to assigned at the introduction of the triage state

comment:4 Changed 6 years ago by Russell Taylor

BTW, the places in IPython that implement the behaviour described above are core/completer.py & utils/dir2.py

comment:5 Changed 6 years ago by Russell Taylor

The changes required to get this working are.....

In the QtProxyObject class of mantidplotpy/proxies.py:

  • Add the following method:
    def _set__all__(self):
        heldobjectmethods = dir(self._getHeldObject())
        qwidgetmethods = dir(QtGui.QWidget)
        self.__all__ = [m for m in heldobjectmethods if m not in qwidgetmethods]
    
  • Call that method in __init__, after self.__obj has been set.

Then at the end of the __init__ of MantidIPythonWidget in ipython_widget/mantid_ipython_widget.py, add:

from IPython.config.loader import Config
ip = shell.get_ipython()
c = ip.Completer
cfg = Config()
cfg.IPCompleter.limit_to__all__ = True
c.update_config(cfg)

comment:6 Changed 6 years ago by Russell Taylor

  • Status changed from assigned to verify
  • Resolution set to wontfix

I've gone off this one. Yes, the list of completions can be long but I think we should stick with full disclosure. Filtering out hides things like show/hide etc. that could be useful, while showing methods on, e.g., MDIWindow that aren't particularly aimed at the end user.

The way to do is recorded above just in case anyone ever wants to come back to it.

comment:7 Changed 6 years ago by Michael Reuter

  • Status changed from verify to verifying
  • Tester set to Michael Reuter

comment:8 Changed 6 years ago by Michael Reuter

  • Status changed from verifying to closed

I happen to agree that full disclosure is the way to go. Other projects follow the same rule with their inherited objects.

comment:9 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 9055

Note: See TracTickets for help on using tickets.