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
-
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
andlimit_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 beTrue
, with its text being the current number of page (concatenated to the number of total pages ifPageStyle.show_counter
is set to beTrue
). 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]]