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

Allow popup display of completions in EnumEditor #454

Closed
corranwebster opened this issue Apr 19, 2018 · 1 comment
Closed

Allow popup display of completions in EnumEditor #454

corranwebster opened this issue Apr 19, 2018 · 1 comment

Comments

@corranwebster
Copy link
Contributor

Via @chenqi0805 and @ERAnderson - the ability to have a popup showing potential completions in an EnumEditor as the user types is useful when there are potentially a large number of completions:

image

This can be achieved in Qt with a handler which sets the completer mode on the control; but it would be nice to have this exposed as an option in the Editor.

@corranwebster
Copy link
Contributor Author

Code from @ERAnderson:

""" EnumEditor with auto drop down for completion - quick hack """

from pyface.qt import QtGui
from traits.api import HasTraits, Enum, List
from traitsui.api import Item, Group, View, EnumEditor, Handler


class QTEnumDropHandler(Handler):

    def init(self, info):

        for value_editor in info.ui._editors:
            if value_editor.name == 'enum_value':
                break
        else:
            ValueError("'enum_value' editor not found in search element")

        control = value_editor.control

        control.completer().setCompletionMode(
            QtGui.QCompleter.CompletionMode.PopupCompletion)

        return True


class EnumEditorDemo(HasTraits):
    """ Defines the main EnumEditor demo class. """

    # Define possible values for enum
    name_list = List(['A-495', 'A-498', 'R-1226', 'TS-17', 'TS-18',
                      'Foo', 'frombicator_a', 'whitzlegidget', 'splatzleblock',
                      'frombicator_b', 'foozalator'])

    # Define an Enum trait to view
    enum_value = Enum(values='name_list')

    def default_traits_view(self):

        enum_group = Group(
            Item('enum_value',
                 editor=EnumEditor(
                     name='name_list',
                     evaluate=True,
                 ),
                 label='Drop down with completion'),

        )

        return View(
            enum_group,
            title='EnumEditor',
            buttons=['OK'],
            resizable=True,
            handler=QTEnumDropHandler(),
        )


# Create the demo:
demo = EnumEditorDemo()


# Run the demo (if invoked from the command line):
if __name__ == '__main__':
    demo.configure_traits()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant