enthought / enthought/pyface

Create standard proxy traits for Qt and Wx

Open
#737 0 comments 0 reactions 0 assignees View on GitHub
difficulty: intermediate type: refactoring
Dominant language
Python
Stars
115
Forks
54
PR merge metrics
No merged PRs in 30d

Description

In many cases the traits on `Widget` and its subclasses have code that listens for changes and then calls the appropriate setter or getter, which performs the appropriate translation to toolkit method calls and values. This usually looks something like (taking the most standardized examples from `pyface.fields`):
```
def _set_control_foo(self, value):
self.control.setBar(map(value))

def _get_control_foo(self):
return reverse_map(self.control.bar())
```
where for simple values like strings and numbers, the map/reverse_map may not be needed (Wx is similar, but the methods are `SetBar` and `GetBar` and the maps will be different). Older `Widget` subclasses often have similar code, just not broken out into separate methods so cleanly).

This is essentially a property, where in addition we could parametrize the maps and the names of the methods. This is of course the core idea behind QtBinder.

It should be possible to create standard `TraitTypes` which are properties used something like:
```
_control_foo = QtProperty(name='Bar', to_qt_value=map, to_python_value=reverse_map)
```
with bonus points for having a way to specify that a property change event should fire when a signal or event fires (but this is not essential, even just a simple property type with no notification system would still have value, and could be a first step).

This would cut down on a lot of boilerplate, as then standard parametrized code will take the place of manually defined methods. This would make creating new widget types fast, improve reliability and testability, and make code more readable (with a slight overhead for new users, which could be removed by good developer documentation).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.