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

Add custom widget without forking project and modifying __init__.py #143

Closed
brian-romanowski-nuance opened this issue Jul 29, 2021 · 2 comments
Assignees
Labels
Core Add for issues having to do with core functions Feature Request Add for a new feature request
Milestone

Comments

@brian-romanowski-nuance

Is your feature request related to a problem? Please describe.
I'm new to py_cui so apologies if I'm jumping the gun here. I'm interested in building a custom widget but, according to the documentation, it's necessary to edit the py_cui/init.py source code to add a add_my_widget() function. It'd be nice to allow extending the main py_cui release without needing to build a custom version of the package.

Describe the solution you'd like
Is it possible to define a generic function for adding custom widgets? Like:

def add_custom_widget(self, widget_class, title, row, column, row_span=1, column_span=1, padx=1, pady=0, is_selectable=True, **kwargs):
    id = 'Widget{}'.format(len(self.get_widgets().keys()))
    new_widget = widget_class(id, 
                                            title, 
                                            self._grid, 
                                            row, 
                                            column, 
                                            row_span, 
                                            column_span, 
                                            padx, 
                                            pady, 
                                            self._logger,
                                            **kwargs)
    self.get_widgets()[id] = new_widget
    if is_selectable and self._selected_widget is None:
        self.set_selected_widget(id)
    self._logger.debug('Adding widget {} w/ ID {} of type {}'.format(title, id, str(type(new_widget))))
    return new_widget

A side benefit is that the existing add_* functions could just call this function, which would remove some of the repeated code. The main benefit is that projects could add their own custom widgets without modifying the core py_cui code.

@brian-romanowski-nuance brian-romanowski-nuance added the Feature Request Add for a new feature request label Jul 29, 2021
@jwlodek
Copy link
Owner

jwlodek commented Jul 29, 2021

This is a fantastic idea! I was thinking about how to allow something like this for a while, but didn't come up with just adding an add_generic_widget function. The whole add_* functions were a relic of the original version of py_cui prior to even being made public on github. I had considered changing the entire structure of the interface to something where instead of adding the widget to the parent, you would instantiate widgets directly and pass the parent interface as an argument, but at this point it was too big of a breaking change. I like this solution though, since it wouldn't break any compatibility.

At the moment I want to finish the already selected for development stuff for the next release that has already taken longer than I wanted, but this will be first on the list once I get to the next version. Of course if you would like to try yourself a PR would be welcome. Current development is on the v0.1.4 branch, so you'd probably want to start from there.

@jwlodek jwlodek added this to the v0.1.5 milestone Jul 29, 2021
@jwlodek jwlodek added the Core Add for issues having to do with core functions label Jul 29, 2021
@brian-romanowski-nuance
Copy link
Author

Great! I'd like to keep playing around with the framework and to understand it a bit better before making a contribution, at least for a few more days. I'm up for making a PR eventually but please don't wait for me if you want to make the change sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Add for issues having to do with core functions Feature Request Add for a new feature request
Projects
None yet
Development

No branches or pull requests

2 participants