import PySimpleGUI as sg
import datetime

sg.SYMBOL_CHECK_SMALL = '✓'     # can remove line if using later PySimpleGUI version that has this symbol defined

menu_sizes_original = ['Large::Large', 'Medium::Medium', 'Small::Small']
menu_sizes = menu_sizes_original
max_digits = 8


def right_click_meny_new_size(window, new_size):
    current_size = window.metadata          # Window's metadata has the subsample value
    menu = window.RightClickMenu            # Dangerous operation... directly accessing the right click menu with assumption same for entire window
    menu_sizes[current_size - 1] = menu_sizes[current_size - 1][1:]                 # Remove checkmark from previous item
    menu_sizes[new_size - 1] = sg.SYMBOL_CHECK_SMALL + menu_sizes[new_size - 1]     # Add checkmark to new item
    sg.user_settings_set_entry('-subsample-', new_size)
    [window[('-IMAGE-', i)].set_right_click_menu(menu) for i in range(max_digits)]  # Set right click menu for all image elements
    window.metadata = new_size              # Store the new subsample value as the Window's metadata

def main():

    base64_digits = {'0':i0, '1':i1, '2':i2, '3':i3, '4':i4, '5':i5, '6':i6, '7':i7, '8':i8, '9':i9, ':':colon, ' ':blank, '.':dot}

    subsample = sg.user_settings_get_entry('-subsample-', 2)
    location =sg.user_settings_get_entry('-location-', (None, None))
    alpha = sg.user_settings_get_entry('-alpha-', 0.9)
    menu_sizes[subsample-1] = sg.SYMBOL_CHECK_SMALL + menu_sizes[subsample-1]
    right_click_menu = [[''], ['Version',  'Edit Me', 'Save Location', 'Size', menu_sizes, 'Alpha', [str(x) for x in range(1, 11)], 'Exit', ]]

    layout = [[sg.Image(blank, key=('-IMAGE-', i), p=0, subsample=subsample) for i in range(max_digits)]]

    window = sg.Window('', layout, background_color='black', no_titlebar=True, grab_anywhere=True, right_click_menu=right_click_menu, location=location, keep_on_top=True, enable_close_attempted_event=True, alpha_channel=alpha, metadata=subsample)

    while True:
        event, values = window.read(timeout=300)
        if event in (sg.WIN_CLOSED, 'Exit', sg.WIN_CLOSE_ATTEMPTED_EVENT):
            if event != sg.WIN_CLOSED:
                sg.user_settings_set_entry('-location-', window.current_location())
            break
        # Update the Image Elements with current time
        date = datetime.datetime.now()
        time_string = f'{date:%I}:{date:%M}:{date:%S}'
        subsample = window.metadata
        for i, c in enumerate(time_string):
            window[('-IMAGE-', i)].update(base64_digits[c], subsample=subsample)

        # Process the event
        if event == sg.TIMEOUT_EVENT:       # if a timeout, then do nothing (saves a TINY amount of time not checking all the if statements...)
            pass
        elif event == 'Edit Me':
            sg.execute_editor(__file__)
        elif event.startswith('Version'):
            sg.popup_scrolled(sg.get_versions(), non_blocking=True, keep_on_top=True, grab_anywhere=False, location=window.current_location())
        elif event in [str(x) for x in range(1,11)]:            # Alpha channel selected
            window.set_alpha(int(event)/10)
            sg.user_settings_set_entry('-alpha-', int(event)/10)
        elif event.endswith('Small'):                           # Size changed to Small
            right_click_meny_new_size(window, 3)
        elif event.endswith('Medium'):                          # Size changed to Medium
            right_click_meny_new_size(window, 2)
        elif event.endswith('Large'):                           # Size changed to Large
            right_click_meny_new_size(window, 1)
        elif event == 'Save Location':                          # Gernally not neeeded since save on exit, but may make user feel better
            sg.user_settings_set_entry('-location-', window.current_location())

    window.close()

if __name__ == '__main__':

    i0 = b'[encoded data, 6248 characters]'
    i1 = b'iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAAAAADji6uXAAAACXBIWXMAAAsSAAALEgHS3X78AAAJQ0lEQVRo3u1a2XLbSBKsrEYDBEhKlj2H54qY/f9/2oiN2I3YWVsjiQdIHF25D42LliyRsPymflBIDAKFujKzCoI8cwCAJPs/KBQRgQAipAgUFj+jUAhBvJAUgfTfPznuJYOT38fPowmBcw7SWxQIFP3fOLliPIk8e04v6R+ZIEQE6pwLwQY3oNFjighERZ7wUJ83yMdOx5CZUARQhYh0YUc83UWQOR4K+aV5DCEUIc04/QqHZ2T/xYsMcmIyWgOF6G9kQpj1Dgli6fTftyct4sUUcvJ7rNQYPwEEXTghgvhDxqp+MiUve4iT3wHG4unizZObgv1nT9o6w8O+TLr7AooYNFIEEACkCAWm0rfjc+ZeLpquLtk/HgRD1KhQCEESpxUTgzvPoALRBDhYN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uFEwmtaXL1f5V6sbY510wbitUPa7WT7d0/OL1fLhYqqc845nRNTPUd3969okqxYL9JEgIg3enlEX3ytHsdMxJ1yslherxaJAJo455wCr2xw8v6YItIJKBFo4lTn2HuxSk9ypM4vvCJAXaIqnNGG57RFjzVGuCTzKoFQn4Dh+zR+V/ukmLg08ypB1KVOGQzfxcNxQwHnM+9Aijo3/uPL6xocJ0tF4tLUJeo0FswsaDtPRHUvD51LvCYKETGLEvhirDlHJnYbDFXnfaou4oxCnxmsX8tDjZYUEowyA0nPLZr4Ve3/S6KtD7tjHb4+dX6bhxjfI9OCABKqcnuoDa8O3gMdIr78AC0Ei69/ytpmsOEZBtETcNwyGUUYqnJ3qFqO3PyaIYWAEMIMdXMsfYq0Lh8+b8r2jO3ozByCIgbS6nK3hEi5vbvdHGoKvkMfAoAYRWBom7omkbfH3e192c4BmrNEFOIwY2yrctu0dV1u7m43h0a+S0gpFt+3mNj2vwV8ka3++a//3G7KSgTfhZ46tiDbu3/X9wvvs78+fbo9HBuZc5JzkI0iwiCyxe5/gEdZlmVlLebQ08UHfdpVZA60vZ2383beztt5O29H5P846rF0SjSNtwAAAABJRU5ErkJggg=='
    i2 = b'[encoded data, 5796 characters]'
    i3 = b'[encoded data, 5324 characters]'
    i4 = b'[encoded data, 5636 characters]'
    i5 = b'[encoded data, 5288 characters]'
    i6 = b'[encoded data, 5908 characters]'
    i7 = b'[encoded data, 4700 characters]'
    i8 = b'[encoded data, 6468 characters]'
    i9 = b'[encoded data, 5056 characters]'
    blank = b'iVBORw0KGgoAAAANSUhEUgAAAHAAAABwBAMAAAA0zul4AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJUExURQAAAAsLCwEBASarxPMAAAAJcEhZcwAACxEAAAsRAX9kX5EAAAAnSURBVFjD7c0hAQAACAOwV6AB/VOiSIDAbAUWAAC4qn5IAQAAYCUD5JkAMsfpUwIAAAAASUVORK5CYII='
    colon = b'iVBORw0KGgoAAAANSUhEUgAAAHA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