コード例 #1
0
 def __init__(self, checked_text: Text, unchecked_text: Text,
              id: str,
              on_state_changed: Optional[OnStateChanged] = None,
              default: bool = False,
              when: Union[str, Callable] = None):
     text = Case({True: checked_text, False: unchecked_text}, selector=self._is_text_checked)
     super().__init__(text, id, self._on_click, when)
     self.default = default
     self.on_state_changed = on_state_changed
コード例 #2
0
ファイル: select.py プロジェクト: prostmich/aiogram_dialog
 def __init__(self,
              checked_text: Text,
              unchecked_text: Text,
              id: str,
              item_id_getter: ItemIdGetter,
              items: Union[str, Sequence],
              on_state_changed: Optional[OnStateChanged] = None,
              when: Union[str, Callable] = None):
     text = Case({
         True: checked_text,
         False: unchecked_text
     },
                 selector=self._is_text_checked)
     super().__init__(text, id, item_id_getter, items, self._on_click, when)
     self.on_state_changed = on_state_changed
コード例 #3
0
 def __init__(self,
              checked_text: Text,
              unchecked_text: Text,
              id: str,
              on_click: Union[OnStateChanged, WidgetEventProcessor,
                              None] = None,
              on_state_changed: Union[OnStateChanged, WidgetEventProcessor,
                                      None] = None,
              when: Union[str, Callable] = None):
     super().__init__(id, when)
     self.text = Case({
         True: checked_text,
         False: unchecked_text
     },
                      selector=self._is_text_checked)
     self.on_click = ensure_event_processor(on_click)
     self.on_state_changed = ensure_event_processor(on_state_changed)
     self._callback_data_prefix = f"{self.widget_id}:"
コード例 #4
0
 def __init__(self,
              checked_text: Text,
              unchecked_text: Text,
              id: str,
              item_id_getter: ItemIdGetter,
              items: Union[str, Sequence],
              on_click: Union[OnItemClick, WidgetEventProcessor,
                              None] = None,
              on_state_changed: Union[OnItemStateChanged,
                                      WidgetEventProcessor, None] = None,
              when: Union[str, Callable] = None):
     text = Case({
         True: checked_text,
         False: unchecked_text
     },
                 selector=self._is_text_checked)
     super().__init__(text, id, item_id_getter, items, self._process_click,
                      when)
     self.on_item_click = ensure_event_processor(on_click)
     self.on_state_changed = ensure_event_processor(on_state_changed)
コード例 #5
0
 def __init__(self, checked_text: Text, unchecked_text: Text,
              id: str,
              item_id_getter: ItemIdGetter,
              items: Union[str, List],
              multiple: bool = False,
              min_selected: int = 0,
              max_selected: int = 0,
              on_state_changed: Optional[OnStateChanged] = None,
              when: Union[str, Callable] = None):
     super().__init__(id, when)
     self.text = Case({True: checked_text, False: unchecked_text}, selector=self._is_text_checked)
     self.widget_id = id
     self.on_state_changed = on_state_changed
     self.callback_data_prefix = id + ":"
     self.item_id_getter = item_id_getter
     self.multiple = multiple
     self.min_selected = min_selected
     self.max_selected = max_selected
     if isinstance(items, str):
         self.items_getter = itemgetter(items)
     else:
         self.items_getter = get_identity(items)
コード例 #6
0
from typing import Dict

from aiogram_dialog import DialogManager
from aiogram_dialog.widgets.text import Multi, Const, Format, Case


# let's assume this is our window data getter
async def get_data(**kwargs):
    return {"color": "red", "number": 42}


# This will produce text `Square`
text = Case(
    {
        "red": Const("Square"),
        "green": Const("Unicorn"),
        "blue": Const("Moon"),
    },
    selector="color",
)


# This one will produce text `42 is even!`
def parity_selector(data: Dict, case: Case, manager: DialogManager):
    return data["number"] % 2


text2 = Case(
    {
        0: Format("{number} is even!"),
        1: Const("It is Odd"),
    },