PageStyleΒΆ

class pyrubrum.PageStyle(back_text: Optional[str] = 'πŸ”™', limit: Optional[int] = 2, limit_items: Optional[int] = 4, next_page_text: Optional[str] = '▢️', previous_page_text: Optional[str] = '◀️', show_counter: Optional[bool] = True, show_page: Optional[bool] = True)ΒΆ

Integrate paging into your menu in a simple way by using this class.

Parameters
  • back_text (Optional[str]) – The text which will be displayed inside the button that lets the user go back to the parent menu. Defaults to β€œπŸ”™β€.

  • limit (Optional[int]) – The limit of buttons per row. Defaults to 2.

  • limit_items (Optional[int]) – The limit of elements per page. Defaults to 4.

  • next_page_text (Optional[str]) – The text which is displayed inside the button that lets the user move on to the next page, if any. Defaults to β€œβ–ΆοΈβ€.

  • previous_page_text (Optional[str]) – The text which is displayed inside the button that lets the user go back to the previous page, if any. Defaults to β€œβ—€οΈβ€.

  • show_counter (Optional[bool]) – If there shall be the number of the total pages right next to the number of page. Defaults to True.

  • show_page (Optional[bool]) – If the number of the page shall be displayed between the two arrows for managing the motion of the pages. Defaults to True.

Warning

This implementation is not compatible with a non-parameterized handler. An handler that supports parameterization is required.

generate_page_id(handler: ParameterizedHandler, client: pyrogram.client.client.Client, context: Any, parameters: Dict[str, Any], menu: PageMenu)strΒΆ

Generate a page identifier, relying on the identifier of the provided menu, built in the following way:

page_[MENU_ID]

Hence, there is a special set of keys for parameters that is recommended not to be used in order to handle paging in a proper way. All keys starting with page_ shall then be avoided.

Parameters
  • handler (ParameterizedHandler) – The handler which coordinates the management of the menus and supports parameterization.

  • client (Client) – The client which is linked to the handler.

  • context (Union[CallbackQuery, Message]) – The context for which the button is generated.

  • parameters (Dict[str, Any]) – The parameters which were passed to the handler.

  • menu (Menu) – The menu the keyboard is being built for.

Returns

The generated page identifier.

Return type

str

generate(handler: ParameterizedHandler, client: pyrogram.client.client.Client, context: Any, parameters: Dict[str, Any], menu: Menu) → List[List[Button]]ΒΆ

Provide a keyboard which is created relying on the page provided by the parameters and is built following the limits defined during the initialization of this instance (i.e. limit and limit_items).

The page identifier is retrieved from PageStyle.generate_page_id.

If this menu has been referenced by this menu itself (i.e. the user clicked on the buttons for moving between pages), the page is set to be equal to element_id, which represents the page itself.

As a result of this, during the build of the the teleport buttons (i.e. the buttons for moving between pages) element_id is set to be equal to the page the buttons refer to (e.g. page plus one for β€œGo to the next page”).

No teleport keyboard is generated if the number of total pages is equal to one. Otherwise, three buttons are generated. The first one is built in order to let the user go back to the previous page, if any, else a null-pointer button is created, with its content being an empty character. The second one is generated if and only if PageStyle.show_menu is set to be True, with its text being the current number of page (concatenated to the number of total pages if PageStyle.show_counter is set to be True). The third one is designed for moving on to the next page, if any, and it is built following the same rules that were respected by the first button.

In the end, the keyboard is filled with all the buttons which refer to the children menus a special button for linking the user to the parent menu, if any.

Parameters
  • handler (ParameterizedHandler) – The handler which coordinates the management of the menus and supports parameterization.

  • client (Client) – The client which is linked to the handler.

  • context (Union[CallbackQuery, Message]) – The context for which the button is generated.

  • parameters (Dict[str, Any]) – The parameters which were passed to the handler.

  • menu (Menu) – The menu the keyboard is being built for.

Returns

The generated inline keyboard, which is then displayed to the user.

Return type

List[List[Button]]