enthought / pyface

pyface: traits-capable windowing framework
Other
105 stars 55 forks source link

Improvements to Schemas #1095

Open corranwebster opened 2 years ago

corranwebster commented 2 years ago

Currently classes like ActionSchema do not have hooks in the default create functions to permit passing in additional keyword arguments to the factory function, see: https://github.com/enthought/pyface/blob/42fbaf6e18883b8e5a662fc9ba108fd2408c91d3/pyface/action/schema/schema.py#L98-L102

This means that you can't easily use a generic class (such as Action itself, in many cases) as the factory, because you can't pass in traits, and instead have to have a custom factory function to apply those, or subclass ActionSchema. In downstream projects we have ended up with factory function factories and Schema factories to automate the process of creating these custom things, but looking at this it would be nice to be able to say something like:

ActionSchema(id='foo', kw_args={'name': "Bar", 'on_perform': do_bar, 'tooltip': "Do bar."})

and then have these passed through. Exact syntax might vary, eg. even nicer would be:

ActionSchema(id='foo', name="Bar", on_perform=do_bar, tooltip="Do bar.")

where kwargs that aren't traits are extracted and used as arguments for the factory, but that might be too magical.

corranwebster commented 1 year ago

Investigating this - any changes we need here can be done in a largely backwards-compatible way; they include things like:

They key is to not push through null values. So this is not urgent for 8.0