##
# @module    picture_button
# @brief     Button object with a picture
# @version   1.4
#

import gui

class Picture_Button:

    def __init__(self, x, y, image, name, callback=None, colour=(255,255,255), hidden_colour=(255,255,255)):
        self.pos = (x, y)
        self.image = image
        self.name = name
        self.callback = callback
        self.gui_l_index = None
        self.gui_col = [gui.DL_COLOR_RGB(*colour) if isinstance(colour, tuple) else colour]
        self.hidden_colour = gui.DL_COLOR_RGB(*hidden_colour) if isinstance(hidden_colour, tuple) else hidden_colour

    def generate_gui_l(self, tag):
        gui_l = [gui.DL_NOP(), self.gui_col] #first item in list can't be another list
        gui_l.extend(self.image.generate_gui_l(tag, self.pos))
        return gui_l

    def get_callback(self):
        return self.callback

    def set_hidden_colour(self, colour):
        self.hidden_colour = gui.DL_COLOR_RGB(*colour) if isinstance(colour, tuple) else colour

    def hide(self):
        if not isinstance(self.hidden_colour, int):
            raise Exception("Picture Button hide colour not set")
        self.gui_col[0] = self.hidden_colour

    def set_callback(self, callback):
        if type(self.callback) == list:
            self.set_callback_lst(callback)
        else:
            self.callback = callback
    
    def set_callback_lst(self, callback):
        self.callback[0] = callback

    def set_gui_l_index(self, index):
        self.gui_l_index = index

    def set_pos(self, pos):
        self.image.set_pos(pos)

    def set_colour(self, colour):
        self.gui_col[0] = gui.DL_COLOR_RGB(*colour) if isinstance(colour, tuple) else colour

