Skip to content

Commit

Permalink
add docs strings to deltachat_cursed/cards_widget.py
Browse files Browse the repository at this point in the history
  • Loading branch information
adbenitez committed Apr 4, 2024
1 parent d9838a3 commit a09dacd
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions deltachat_cursed/cards_widget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Card layout widget, a stack of widgets only one is visible at a time"""
"""Cards layout widget, a stack of widgets, only one is visible at a time"""

from collections import OrderedDict
from typing import Dict

import urwid
Expand All @@ -9,20 +8,28 @@


class CardsWidget(urwid.WidgetPlaceholder):
"""Card layout widget, a stack of widgets only one is visible at a time"""
"""Cards layout widget, a stack of widgets, only one of them is visible at a time"""

original_widget: urwid.Widget

def __init__(self) -> None:
super().__init__(EMPTY)
self.cards: Dict[str, urwid.Widget] = OrderedDict()
self.cards: Dict[str, urwid.Widget] = {}

def add(self, name: str, widget: urwid.Widget) -> None:
"""Add a new widget to the stack.
The name must be an unique string ID to identify the item.
"""
self.cards[name] = widget

def remove(self, name: str) -> urwid.Widget:
"""Remove an item from the stack corresponding to the given name."""
widget = self.cards.pop(name)
if widget is self.original_widget: # noqa
if widget is self.original_widget:
self.original_widget = EMPTY
return widget

def show(self, name: str) -> None:
"""Show the widget corresponding to the given name."""
self.original_widget = self.cards[name]

0 comments on commit a09dacd

Please sign in to comment.