# !Currency.py.Iconbar/py

import wimp
import ConvrtW
import Update

def init():
    "Setup iconbar icon"
    global window_info, menu_iconbar
    wimp.iconbar_icon('!currency', click)
    window_info = wimp.info_window()
    menu_iconbar = wimp.menu('iconbar', ('task', ('info', window_info), 'update', 'quit'))

def click(buttons, x):
    "Handle click on iconbar"
    if buttons == 1:
        Update.update()
    elif buttons == 2:
        reopen = 1
        while reopen:
            selection, reopen = menu_iconbar.menu(x - 64, 96 + 44 * 3)
            if selection is None:
                pass
            elif selection[0] == 0:
                window_info.open_as_menu()
                reopen = 0
            elif selection[0] == 1:
                Update.update()
                reopen = 0
            elif selection[0] == 2:
                wimp.quit()
    elif buttons == 4:
        w = ConvrtW.convert_window()
        w.open_centred(-1)
        w.pane.put_caret(1)
