tuttle-dev / tuttle

🪰 Tuttle - time and money management for freelancers
GNU General Public License v3.0
62 stars 12 forks source link

To OOP or not to OOP? #133

Closed clstaudt closed 1 year ago

clstaudt commented 1 year ago

Pick the better implementation:

A)

def get_dropdown(
    lbl: str,
    on_change: Callable,
    items: List[str],
    hint: Optional[str] = "",
    width: Optional[int] = None,
    initial_value: Optional[str] = None,
):
    options = []
    for item in items:
        options.append(
            dropdown.Option(
                text=item,
            )
        )
    return Dropdown(
        label=lbl,
        hint_text=hint,
        options=options,
        text_size=fonts.BODY_1_SIZE,
        label_style=TextStyle(size=fonts.BODY_2_SIZE),
        on_change=on_change,
        width=width,
        value=initial_value,
        content_padding=padding.all(dimens.SPACE_XS),
        error_style=TextStyle(size=fonts.BODY_2_SIZE, color=colors.ERROR_COLOR),
    )

B)

class StandardDropdown(Dropdown):
    def __init__(
        self,
        lbl: str,
        on_change: Callable,
        items: List[Union[str, dropdown.Option]],
        hint: Optional[str] = "",
        width: Optional[int] = None,
        initial_value: Optional[str] = None,
    ):
        options = []
        for item in items:
            options.append(
                dropdown.Option(
                    text=item,
                )
            )

        super().__init__(
            label=lbl,
            hint_text=hint,
            options=options,
            text_size=fonts.BODY_1_SIZE,
            label_style=TextStyle(size=fonts.BODY_2_SIZE),
            on_change=on_change,
            width=width,
            value=initial_value,
            content_padding=padding.all(dimens.SPACE_XS),
            error_style=TextStyle(size=fonts.BODY_2_SIZE, color=colors.ERROR_COLOR),
        )
vlad-ed-git commented 1 year ago

@clstaudt for these views, A is better. because we want to be able to just do views.get_dropdown() in our Ui without having to instantiate a class object every time you set a view.

clstaudt commented 1 year ago

Can't follow that explanation, can you rephrase?

vlad-ed-git commented 1 year ago

If we make the view a class, suppose it's a drop-down. Then to add it to a column, we have to do

  1. Instantiate the class
  2. Pass the object to the column e.g. drop_down = views.TuttleDropdown() column.controls = [drop_down]

The current option is just column.controls = [views.getDropdown()]

On Friday, January 13, 2023, Christian Staudt @.***> wrote:

Can't follow that explanation, can you rephrase?

— Reply to this email directly, view it on GitHub https://github.com/tuttle-dev/tuttle/issues/133#issuecomment-1380819861, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJGBW6YUIRPZ3KTLTS7L373WSBDV5ANCNFSM6AAAAAATYL3VLA . You are receiving this because you modified the open/close state.Message ID: @.***>

clstaudt commented 1 year ago
column.controls = [views.TuttleDropdown()]