Toggle Navigation
Hatchery
Eggs
ShowImages
__init__.py
Login
Register
__init__.py
Content
import badge import os import sys import system import ugfx import utime # Constant definitions SCREEN_WIDTH = ugfx.width() SCREEN_HEIGHT = ugfx.height() MEDIA_DIR = '/media' TXT_FONT = 'Roboto_Regular18' IMAGES = [] INDEX = 0 def action_exit(pushed): if (pushed): # go back to the home screen system.home() def show_img(): global IMAGES,INDEX,MEDIA_DIR img = IMAGES[INDEX] w = badge.png_info(MEDIA_DIR + '/' + img)[0] h = badge.png_info(MEDIA_DIR + '/' + img)[1] page_txt = str(INDEX+1) + '/' + str(len(IMAGES)) tw = ugfx.get_string_width(page_txt, 'Roboto_Regular12') th = ugfx.get_string_height(page_txt, 'Roboto_Regular12') ugfx.clear(ugfx.WHITE) ugfx.display_image(int(SCREEN_WIDTH/2 - w/2), int(SCREEN_HEIGHT/2 - h/2), MEDIA_DIR + '/' + img) ugfx.string(int(SCREEN_WIDTH - (tw+2)), int(SCREEN_HEIGHT - (th+1)), page_txt, 'Roboto_Regular12', ugfx.BLACK) ugfx.flush() def show_text(text): w = ugfx.get_string_width(text, TXT_FONT) h = ugfx.get_string_height(text, TXT_FONT) ugfx.clear(ugfx.WHITE) ugfx.string(int(SCREEN_WIDTH/2 - w/2), int(SCREEN_HEIGHT/2 - h/2), text, TXT_FONT, ugfx.BLACK) ugfx.flush() def show_next(pushed): global INDEX,IMAGES if(pushed and len(IMAGES) > 0): if(INDEX < len(IMAGES)-1): INDEX += 1 else: show_text('NO NEXT!') utime.sleep_ms(1000) print('Show next...') print(IMAGES[INDEX]) show_img() def show_prev(pushed): global INDEX,IMAGES if(pushed and len(IMAGES) > 0): if(INDEX > 0): INDEX -= 1 else: show_text('NO PREV!') utime.sleep_ms(1000) print('Show prev...') print(IMAGES[INDEX]) show_img() def main(): global IMAGES,INDEX,MEDIA_DIR # Input initializations ugfx.input_init() # Attach button actions ugfx.input_attach(ugfx.BTN_B, action_exit) ugfx.input_attach(ugfx.BTN_START, action_exit) ugfx.input_attach(ugfx.BTN_SELECT, action_exit) ugfx.input_attach(ugfx.JOY_UP, show_prev) ugfx.input_attach(ugfx.JOY_DOWN, show_next) ugfx.input_attach(ugfx.JOY_RIGHT, show_next) ugfx.input_attach(ugfx.JOY_LEFT, show_prev) IMAGES = os.listdir(MEDIA_DIR) print('Images:') print(IMAGES) if(len(IMAGES) > 0): show_img() else: show_text('No images! :(') sys.stdin.read(1) #Wait for any key action_exit(True) main()