import PySimpleGUI as sg

"""
    Demo - Can Buttons

    How to use an Image element to make Can Buttons.

    The metadata for the Image Element holds the current button state.  In this case the state is an offset into a list of button images.

    The technique is much like the toggle buttons except you can have more than 2 states.

    A Custom Titlebar was used to make the overall appearance cleaner while still providing the ability to easily exit.

    Copyright 2022 PySimpleGUI
"""


def main():
    boost_images = (can_boost_off, can_boost_blue, can_boost_green)
    seat_images = (can_seat_off, can_seat_red)
    sg.theme('black')
    sg.theme_background_color('#222222')
    sg.theme_text_color('#888888')
    sg.set_options(titlebar_background_color=sg.theme_background_color(), titlebar_text_color=sg.theme_text_color(), use_custom_titlebar=True, titlebar_icon=sg.BLANK_BASE64)

    layout = [[sg.Im(boost_images[0], k='-BOOST-', enable_events=True, metadata=0), sg.Im(seat_images[0], enable_events=True, k='-SEAT-', metadata=0)]]

    window = sg.Window('', layout)
    while True:
        event, values = window.read()
        if event == sg.WIN_CLOSED or event == 'Exit':
            break
        if event == '-SEAT-':
            window[event].metadata = (window[event].metadata + 1) % len(seat_images)
            window[event].update(seat_images[window[event].metadata])
        if event == '-BOOST-':
            window[event].metadata = (window[event].metadata + 1) % len(boost_images)
            window[event].update(boost_images[window[event].metadata])
    window.close()


if __name__ == '__main__':

    can_boost_off = b'[encoded data, 20664 characters]'
    can_boost_blue = b'[encoded data, 29324 characters]'
    can_boost_green = b'[encoded data, 30012 characters]'
    can_seat_off = b'[encoded data, 19360 characters]'
    can_seat_red = b'[encoded data, 28292 characters]'
    main()
