Closed mwerezak closed 3 years ago
def setup_widget(self, person: Person): --> def setup_widget(self, person: Person, **kw):
strip the KW you want from the init of the widget, and pass a clean kwarg dict with only DPG stuff you allow for change at init i.e. things like "parent" to the DPG API for widget create.
Thanks, it works! Here's the full implementation:
class UserWidget(Widget, ItemWidget):
def __init__(self, *args: Any, parent: str = None, before: str = None, name_id: str = None, **kwargs: Any):
super().__init__(parent=parent, before=before, name_id=name_id)
self.__setup_content__(*args, **kwargs)
dpgcore.end()
def __setup_add_widget__(self, dpg_args) -> None:
for kw in ('before', 'parent'):
if dpg_args[kw] is None:
del dpg_args[kw]
dpgcore.add_group(self.id, **dpg_args)
@abstractmethod
def __setup_content__(self, *args, **kwargs) -> None:
"""The contents of the UserWidget should be added here."""
...
I thought my issues had something to do with the fact that I was "runtime" adding the PersonInfo (using add_to()
).
But it seems like even if you use parent
the group still goes on the parent stack and can have other widgets added like normal?
So I had misattributed that. In reality it was my kw handling causing the problem.
Implemented UserWidget
. I also have plans to implement a similar thing for custom containers where you can specify which part of the custom widget will hold any children that get added. But that won't be possible until 0.7 so for now I'm calling this complete.
Allow users to easily reuse the widget object API.
Goal is something like: