Initial commit
This commit is contained in:
0
keyboards/__init__.py
Normal file
0
keyboards/__init__.py
Normal file
0
keyboards/default/__init__.py
Normal file
0
keyboards/default/__init__.py
Normal file
0
keyboards/inline/__init__.py
Normal file
0
keyboards/inline/__init__.py
Normal file
1
keyboards/inline/callbacks.py
Normal file
1
keyboards/inline/callbacks.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
21
keyboards/inline/consts.py
Normal file
21
keyboards/inline/consts.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from typing import List, Tuple, Dict
|
||||
|
||||
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from aiogram.utils.callback_data import CallbackData
|
||||
|
||||
from . import utils
|
||||
|
||||
|
||||
class InlineConstructor:
|
||||
@staticmethod
|
||||
def _create_kb(actions: List[Tuple[str, Dict[str, str], CallbackData]], schema: List[int]) -> InlineKeyboardMarkup:
|
||||
btns = []
|
||||
for a, b, c in actions:
|
||||
btns.append(
|
||||
InlineKeyboardButton(
|
||||
text=a,
|
||||
callback_data=c.new(**b)
|
||||
)
|
||||
)
|
||||
kb = utils.misc.arrange_inline_schema(btns, schema)
|
||||
return kb
|
||||
1
keyboards/inline/utils/__init__.py
Normal file
1
keyboards/inline/utils/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import misc
|
||||
17
keyboards/inline/utils/misc.py
Normal file
17
keyboards/inline/utils/misc.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from typing import List
|
||||
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
|
||||
def arrange_inline_schema(buttons: List[InlineKeyboardButton], count: List[int]) -> InlineKeyboardMarkup:
|
||||
kb = InlineKeyboardMarkup()
|
||||
btns = buttons
|
||||
kb.row_width = max(count)
|
||||
if sum(count) != len(buttons):
|
||||
raise ValueError('Количество кнопок не совпадает со схемой')
|
||||
tmplist = [[InlineKeyboardButton('') for _ in range(count[i])] for i in range(len(count))]
|
||||
for a in range(len(tmplist)):
|
||||
for b in range(len(tmplist[a])):
|
||||
tmplist[a][b] = btns.pop(0)
|
||||
kb.inline_keyboard = tmplist
|
||||
return kb
|
||||
Reference in New Issue
Block a user