Skip to content

Commit

Permalink
Added a global grid args for grid args common to all widgets in a tem…
Browse files Browse the repository at this point in the history
…plate
  • Loading branch information
Aesonus committed Aug 23, 2022
1 parent e79492b commit 471112f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tklife"
version = "2.1.0-dev0"
version = "2.1.0-dev1"
description = "Make Tk life easier"
authors = ["Cory Laughlin <[email protected]>"]
license = "MIT"
Expand Down
25 changes: 25 additions & 0 deletions tests/test_skel.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,31 @@ def template(self):
call(skeleton), call().grid(row=1, column=1, arg4=True),
]

def test_create_all_creates_and_grids_widgets_from_template_with_global_grid_args(
self,
mock_master,
mock_controller,
mock_mixin_class,
mocked_widget):

class Tested(SkeletonMixin, mock_mixin_class):
@property
def template(self):
return (
[SkelWidget(mocked_widget, {}, {'arg1': True}), SkelWidget(
mocked_widget, {}, {'arg2': True})],
[SkelWidget(mocked_widget, {}, {'arg3': True}), SkelWidget(
mocked_widget, {}, {'arg4': True})],
)
skeleton = Tested(mock_master, mock_controller, {'garg': True})
actual = mocked_widget.mock_calls
assert actual == [
call(skeleton), call().grid(row=0, column=0, garg=True, arg1=True),
call(skeleton), call().grid(row=0, column=1, garg=True, arg2=True),
call(skeleton), call().grid(row=1, column=0, garg=True, arg3=True),
call(skeleton), call().grid(row=1, column=1, garg=True, arg4=True),
]


def test_create_all_creates_and_grids_widgets_from_template_skipping_none(
self,
Expand Down
7 changes: 4 additions & 3 deletions tklife/skel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ class SkelWidget(typing.NamedTuple):


class SkeletonMixin(abc.ABC):
def __init__(self, master: tkinter.Misc, controller: 'ControllerABC', **kwargs) -> None:
def __init__(self, master: tkinter.Misc, controller: 'ControllerABC', global_grid_args=None, **kwargs) -> None:
# Set the controller first
self.controller = controller

# Init the frame or whatever
super().__init__(master, **kwargs)

self.created: dict[str, dict] = {}
self.create_all()
self.create_all(global_grid_args if global_grid_args else {})
self.create_events()

@property
@abc.abstractmethod
def template(self) -> typing.Iterable[typing.Iterable[SkelWidget]]:
pass

def create_all(self):
def create_all(self, global_grid_args: dict):
for row_index, row in enumerate(self.template):
for col_index, skel_widget in enumerate(row):
if skel_widget is None:
Expand All @@ -40,6 +40,7 @@ def create_all(self):

w = skel_widget.widget(self, **skel_widget.init_args)
w.grid(row=row_index, column=col_index,
**global_grid_args,
**skel_widget.grid_args)
if skel_widget.label is not None:
# And what is the vardict?
Expand Down

0 comments on commit 471112f

Please sign in to comment.