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

Qt InstanceEditor button should never be the default #1498

Merged
merged 1 commit into from
Feb 16, 2021

Conversation

corranwebster
Copy link
Contributor

Fixes #1475.

Not sure how to test this apart from a manual check.

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure how I can test this PR manually. Is there an example I can run on the main branch vs this branch to compare?

@rahulporuri rahulporuri self-requested a review January 25, 2021 05:39
@corranwebster
Copy link
Contributor Author

I don't have a complete minimal example put together, but #1475 has a sketch of the sort of thing that is needed to make the problem occur in the View. I'll see if I have time to flesh that out into a stand-alone example today, which I will add to the issue.

@corranwebster
Copy link
Contributor Author

corranwebster commented Feb 2, 2021

The following stripped-down example illustrates the issue:


from traits.api import Any, Code, HasStrictTraits, Instance, Str
from traitsui.api import (
    Action, InstanceEditor, Item, Menu, MenuBar, VGroup, View
)
from traitsui.instance_choice import InstanceChoiceItem


RunAction = Action(name="Run", action="do_run")

DEFAULT_SCRIPT = '''
def transform(data):
    return None
'''


class Transform(HasStrictTraits):

    title = Str()

    script = Code(DEFAULT_SCRIPT)

    def run(self, data):
        namespace = {}
        exec(self.script, namespace)
        transform = namespace["transform"]
        return transform(data)


class SimpleTransformView(HasStrictTraits):

    transform = Instance(Transform, ())

    data = Any

    result = Any

    def do_run(self):
        self.result = self.transform.run(self.data)

    traits_view = View(
        VGroup(
            Item(
                "transform",
                editor=InstanceEditor(
                    label="Edit...",
                    kind='modal',
                ),
            ),
            Item('data'),
            Item('result', style='readonly'),
        ),
        menubar=MenuBar(
            Menu(RunAction, name="Run"),
        ),
        buttons=[
            RunAction,
        ],
        default_button=RunAction,
        resizable=True,
        title="Analysis",
    )

if __name__ == "__main__":
    view = SimpleTransformView()
    view.configure_traits()

Without the fix, this produces the following UI (note the "Edit" is blue, indicating that it is the default on OS X):
image

With the fix, we get the following UI (note the "Run" is blue, indicating that it is the default on OS X):
image

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I tested the example - #1498 (comment) - against PyQt4, PyQt5 and PySide2 and it works as expected (Run is active/enabled instead of Edit).

@rahulporuri rahulporuri added this to Sprint 1 : Jan 4 2021 - Jan 22 2021 in Enthought OSS Q1 2021 Feb 16, 2021
@corranwebster corranwebster merged commit a4be4b5 into master Feb 16, 2021
Enthought OSS Q1 2021 automation moved this from Sprint 1 : Jan 4 2021 - Jan 22 2021 to Done Feb 16, 2021
@corranwebster corranwebster deleted the fix/qt-instance-editor-button-default branch February 16, 2021 08:44
@rahulporuri rahulporuri moved this from Done to Sprint 3 : Feb 8 2021 - Feb 19 2021 in Enthought OSS Q1 2021 Feb 22, 2021
@rahulporuri rahulporuri moved this from Sprint 3 : Feb 8 2021 - Feb 19 2021 to Sprint 1 : Jan 4 2021 - Jan 22 2021 in Enthought OSS Q1 2021 Feb 22, 2021
@rahulporuri rahulporuri removed this from Sprint 1 : Jan 4 2021 - Jan 22 2021 in Enthought OSS Q1 2021 Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

InstanceEditor button is default in Qt when it should not be
2 participants