Skip to content
Snippets Groups Projects

Refactor Cart into checkerboard table

Merged Mateusz Kudela requested to merge mkudela/issue-173 into develop
Compare and Show latest version
1 file
+ 11
7
Compare changes
  • Side-by-side
  • Inline
@@ -214,7 +214,7 @@ class CartTable(CliveCheckerboardTable):
@staticmethod
def _create_widget_id_to_focus(event: CartItem.Focus | CartItem.Move) -> str:
assert event.button_to_focus is not None, "Button to focus has to be passed to get it's id."
return event.button_to_focus
return f"#{event.button_to_focus}"
def _disable_appropriate_button(self, widget: CartItem) -> None:
if len(self.app.world.profile.cart) > 0 and widget.reactive_idx == 0:
@@ -247,13 +247,17 @@ class CartTable(CliveCheckerboardTable):
for cells, data in [(to_cells, from_data), (from_cells, to_data)]:
for cell, value in zip(cells, data):
cell.update_content(value) # type: ignore[arg-type]
assert isinstance(value, str), "New value for cell has to be a string."
cell.update_content(value)
async def _remove_operation_from_everywhere(self, widget: CartItem) -> None:
self._rows.remove(widget)
await widget.remove()
self.profile.cart.remove(widget.operation)
@on(CartItem.Delete)
async def remove_item(self, event: CartItem.Delete) -> None:
self._rows.remove(event.widget)
await event.widget.remove()
self.profile.cart.remove(event.widget.operation)
await self._remove_operation_from_everywhere(event.widget)
self._handle_remove_event(triggering_widget=event.widget)
self.app.trigger_profile_watchers()
self._disable_appropriate_button(event.widget)
@@ -272,7 +276,7 @@ class CartTable(CliveCheckerboardTable):
self.app.set_focus(cart_item)
if event.button_to_focus:
button_id = self._create_widget_id_to_focus(event)
cart_item.query_one(f"#{button_id}").focus()
cart_item.query_one(button_id).focus()
@on(CartItem.Focus)
def focus_item(self, event: CartItem.Focus) -> None:
@@ -281,7 +285,7 @@ class CartTable(CliveCheckerboardTable):
self.app.set_focus(cart_item)
if event.button_to_focus:
button_id = self._create_widget_id_to_focus(event)
cart_item.query_one(f"#{button_id}").focus()
cart_item.query_one(button_id).focus()
class Cart(BaseScreen):
Loading