Skip to content

Instantly share code, notes, and snippets.

@sharkwouter
Last active August 28, 2019 12:53
Show Gist options
  • Save sharkwouter/ec465d36f6f9fd1570e17511c570f36c to your computer and use it in GitHub Desktop.
Save sharkwouter/ec465d36f6f9fd1570e17511c570f36c to your computer and use it in GitHub Desktop.
import pygame
import pygameMenu
import flatpakmanager_steamos
import pyflatpak
import math
pygame.init()
pygame.joystick.init()
joysticks = [pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count())]
for joystick in joysticks:
joystick.init()
display_list = range(49)
page = 1
page_size = 5
window_width = 1280
window_height = 720
window = pygame.display.set_mode((window_width, window_height))
def get_page_content():
global page_size
global page
global display_list
global window
global window_width
global window_height
output = []
first_index = page_size * (page - 1)
last_index = first_index + page_size
for index in range(first_index, last_index):
if not index < len(display_list):
break
output.append(display_list[index])
print(output)
return output
def create_menu(label=None, page_new=None):
global page_size
global page
global display_list
menu = pygameMenu.Menu(window, window_width, window_height,
pygameMenu.font.FONT_OPEN_SANS, "Paged Menu",
dopause=False
)
# change the page
if page_new:
print(page_new)
page = page_new
last_page = len(display_list) / page_size + 1
# make the page selector
page_list = []
for number in range(1, last_page + 1):
page_list.append(("Page {}/{}".format(number, last_page), number))
menu.add_selector("", page_list, onchange=create_menu,
selector_id='page_selector{}'.format(page))
# add buttons
for entry in get_page_content():
menu.add_option("{}".format(entry), pygameMenu.events.EXIT)
return menu
menu = create_menu()
while True:
menu.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment