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

Move schemas and related code out of Tasks #1076

Merged
merged 8 commits into from
Jan 14, 2022

Conversation

corranwebster
Copy link
Contributor

@corranwebster corranwebster commented Jan 12, 2022

Schemas are generic, this PR moves the Schema code out of pyface.tasks and into pyface.action, making it available for use outside of tasks. Additionally a version of ActionManagerBuilder is included to provide a Tasks-independent way of assembling the Schemas into action managers, which fixes #658.

Additionally, the code is slightly modified so that it does not import toolkit code as a side-effect.

The old locations are kept so imports should still work. They will be removed at some yet-to-be-determined future point.

Schemas are generic, this PR moves the Schema code out of pyface.tasks and
into pyface.action, making it available for use outside of tasks.  Additionally
a version of ActionManagerBuilder is included to provide a Tasks-indpendednt
way of assembling the Schemas into action managers.

Additionally, the code is slightly modified so that it does not import toolkit
code as a side-effect.

The old locations are kept so imports should still work.  They will be removed
at some yet-to-be-determined future point.
@corranwebster
Copy link
Contributor Author

Note that while there is a more immediate need of this change, this opens up the possibility of using Schemas in TraitsUI instead of directly creating pyface.action objects.

Copy link
Contributor

@aaronayres35 aaronayres35 left a comment

Choose a reason for hiding this comment

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

LGTM, just a few comments

manager = self._create_action_manager_recurse(schema, additions_map)
manager.controller = self.controller
return manager

def create_menu_bar_manager(self):
""" Create a menu bar manager from the task's menu bar schema and
additions.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: in create_tool_bar_managers we go through self.task.extra_actions instead of self.additions. They are equivalent, but using self.additions feels more consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be changed because if a subclass or other user of the class messes with how the additions are built then we will get inconsistent results.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought about this some more, and decided that a lot of this logic for discovering new toolbars really belonged in the base class, so I ended up creating a new get_additional_toolbar_schemas method that takes the additions and produces new objects.

Otherwise users who wanted to have multiple toolbars would need to replicate this method's behaviour.

Return a dictionary {item_id: list_of_items}, and a list containing
all the ids ordered by their appearance in the `all_items` list. The
ordered IDs are used as a replacement for an ordered dictionary, to
keep compatibility with Python <2.7 .
Copy link
Contributor

Choose a reason for hiding this comment

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

not relevant to this PR, but doing special things to keep py 2.7 compatibility could be removed / refactored at some point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes,I noticed this and decided not to mess with it in this PR.

@@ -8,6 +8,7 @@
#
# Thanks for using Enthought open source!

from contextlib import contextmanager
import unittest


Copy link
Contributor

Choose a reason for hiding this comment

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

imports from pyface.tasks.action.api below mayb should get updated to use new pyface.actions.schema.api

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep - missed this. There are more places that the imports need to be changed (eg. examples, docs).

Copy link
Contributor

@aaronayres35 aaronayres35 left a comment

Choose a reason for hiding this comment

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

Still LGTM, thanks for the updates!

Only thing I notice is that we still have aInstance("pyface.tasks.action.schema_addition.SchemaAddition") in tasks_application.py which could instead be Instance("pyface.action.schema.schema_addition.SchemaAddition")

@corranwebster
Copy link
Contributor Author

Only thing I notice is that we still have aInstance("pyface.tasks.action.schema_addition.SchemaAddition") in tasks_application.py which could instead be Instance("pyface.action.schema.schema_addition.SchemaAddition")

Good catch - my search only looked for imports.

Corrected, and I will merge after this.

@corranwebster corranwebster merged commit 5f0c094 into main Jan 14, 2022
@corranwebster corranwebster deleted the enh/move-schemas-out-of-tasks branch January 14, 2022 13:58
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.

Make TaskActionManagerBuilder._create_action_manager_recurse reusable without reference to a task
2 participants