pylibui icon indicating copy to clipboard operation
pylibui copied to clipboard

use of properties instead of setters/getters in wrapper

Open superzazu opened this issue 8 years ago • 1 comments

Hello,

As the pylibui wrapper is supposed to be pythonic, I thought it would be great to use the properties instead of defining setValue/getValue-like methods.

Here is a little implementation example for checkboxes checked attribute:

    @property
    def checked(self):
        """
        Returns whether the checkbox is checked or not.

        :return: bool
        """
        return libui.uiCheckboxChecked(self.control)

    @checked.setter
    def checked(self, checked):
        """
        Sets whether the checkbox is checked or not.

        :param checked: bool
        :return: None
        """
        libui.uiCheckboxSetChecked(self.control, checked)

That way, that would allow us to do things like:

if my_checkbox.checked:
    my_checkbox.checked = False

instead of...

if my_checkbox.getChecked():
    my_checkbox.setChecked(False)

What do you think ? Should I make a PR for this ?

Have a good day, Nicolas.

superzazu avatar Jun 14 '16 15:06 superzazu

I think it's a good idea, but we should let it mature a little bit until we implement more things in pylibui. My rationale is that somewhere in the future we may have to decide which functions are worth wrapping as properties and which functions not and until then we won't be sure which things are common on the api.

For now, let's keep this issue open, but it's more important to continue implementing the libui ctypes wrapping functions so that we can match libui's functionality.

joaoventura avatar Jun 16 '16 14:06 joaoventura