Creates google-like navigation menu using python-telegram-bot wrapper
Project description
python telegram bot menu pagination
Description
Makes a google style pagination line for a list of items.
In other words it builds a menu for navigation if you have a lot of search results or whatever list of anything
Installation
pip install ptb-menu-navigation
or if you are working with source code and use Poetry tool:
make install
Usage
from paginator import get_menu
Use get_menu
function to create a line of pages
Example:
from paginator import get_menu
from dataclasses import dataclass
# Define initial menu settings in the dataclass.
@dataclass
class Menu:
items_per_page: int = 10
pages_per_line: int = 3
navigation_signature: str = '±'
page_label: str = ' p. '
# Add the initial call of get_menu
def handling_input(update, context):
# ...
# On first invocation
navigation = get_menu(total_items=len(search_results),
current_page=1,
menu_settings=Menu)
# ...
# Add a callback to handle a page switching
def navigate(update, context):
# ...
navigation = get_menu(total_items=len(search_results),
current_page=int(current_page),
menu_settings=Menu)
# ...
where search_results
is a list of strings and current_page
is a number extracted from a callback_data
.
See examples/search_bot.py
Demo bot launch
Create a .env
file with a TOKEN
variable
inside of an /examples
for launching
the
demo bot.
eg:
TOKEN=<YOUR_TELEGRAM_BOT_TOKEN_FROM_BOT_FATHER>
You may also provide some additional menu values in the same .env
file:
ITEMS_PER_PAGE=1
PAGES_PER_LINE=1
NAVIGATION_SIGNATURE="±"
PAGE_LABEL=" p. "
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ptb-menu-pagination-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4170cf25ca2f29ce5e2364837b2f707226c735ed51365879db92ab081fad6a5 |
|
MD5 | 2cc1c0a745cb9f63639a7fd2349b52e0 |
|
BLAKE2b-256 | 78708b3b1dc957cbb56d6904df934669da9dec5dca2341a5d3a5ab93df173380 |
Hashes for ptb_menu_pagination-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 062b0097e5958d791e1d4889b6894e8a42585a103f0ba4b318c8ca258cdf828b |
|
MD5 | 2a76680bd067f6c6afa419ccf543163b |
|
BLAKE2b-256 | 225f86da202fb95a7037acbae61430983e380d9cbef8d66f4086b7e15cc1e023 |