Exemple #1
0
class ActivitiesList(TKUtils.ScrollContainer()):
    def __init__(self, master, commands):
        cnf, canvas_cnf, viewport_cnf, scrollbar_cnf = {}, {}, {}, {}

        cnf['bd'] = 2
        cnf['bg'] = 'grey'
        cnf['relief'] = 'flat'

        canvas_cnf['width'] = 920
        canvas_cnf['height'] = 360

        scrollbar_cnf['bd'] = 4
        scrollbar_cnf['bg'] = 'grey'
        scrollbar_cnf['relief'] = 'flat'

        super().__init__(master=master,
                         cnf=cnf,
                         cs_cnf=canvas_cnf,
                         vt_cnf=viewport_cnf,
                         sr_cnf=scrollbar_cnf)
        self.pack(expand=True)

        self.commands = commands
        self.label_list = []

    def create_activity_label(self, activity):
        # Container
        cnf, pack = {}, {}

        cnf['bd'] = 1
        cnf['bg'] = 'grey'

        label_container =\
            TKUtils.get_container(master=self.viewport, cnf=cnf, pack=pack)

        # Label
        cnf, pack = {}, {}

        cnf['text'] = activity['title']
        cnf['bg'] = 'blue'
        cnf['fg'] = 'white'
        cnf['width'] = 93
        cnf['height'] = 2

        pack['side'] = 'left'

        label_container.label =\
            TKUtils.get_label(master=label_container, cnf=cnf, pack=pack)

        # Raffle Button
        cnf, pack, defs = {}, {}, {}

        defs['type'] = 'activity'
        defs['value'] = activity

        cnf['text'] = 'O'
        cnf['bg'] = 'orange'
        cnf['width'] = 2
        cnf['command'] = lambda evt=None: self.commands['raffle'](defs=defs)

        pack['side'] = 'left'

        label_container.button =\
            TKUtils.get_button(master=label_container, cnf=cnf, pack=pack)

        # Remove Button
        cnf, pack = {}, {}

        cnf['text'] = 'X'
        cnf['bg'] = 'red'
        cnf['width'] = 2
        cnf['command'] =\
            lambda evt=None: self.commands['remove'](activity['activity_id'])

        pack['side'] = 'right'

        label_container.button =\
            TKUtils.get_button(master=label_container, cnf=cnf, pack=pack)

        self.label_list.append(label_container)
Exemple #2
0
class Listagem(TKUtils.ScrollContainer()):
    def __init__(self, master):
        cnf, canvas_cnf, viewport_cnf, scrollbar_cnf = {}, {}, {}, {}

        cnf['bd'] = 2
        cnf['bg'] = 'grey'
        cnf['relief'] = 'flat'

        canvas_cnf['width'] = 920
        canvas_cnf['height'] = 360

        scrollbar_cnf['bd'] = 4
        scrollbar_cnf['bg'] = 'grey'
        scrollbar_cnf['relief'] = 'flat'

        super().__init__(master=master,
                         cnf=cnf,
                         cs_cnf=canvas_cnf,
                         vt_cnf=viewport_cnf,
                         sr_cnf=scrollbar_cnf)

    def iniciar(self):
        self.pack(expand=True)

    def criar_container(self, master):
        cnf = {}

        cnf['bd'] = 1
        cnf['bg'] = 'grey'

        container = TKUtils.obter_container(master=master, cnf=cnf)

        return container

    def criar_label(self, master, cnf={}, pack={}):
        cnf['fg'] = 'white'
        cnf['height'] = 2

        pack['side'] = 'left'

        label = TKUtils.obter_label(master=master, cnf=cnf, pack=pack)

        return label

    def criar_botao_sortear(self, master, valor, cnf={}, pack={}):
        desativado = isinstance(valor, dict) and valor['em_uso']

        cnf['text'] = 'O'
        cnf['bg'] = 'grey' if desativado else 'orange'
        cnf['state'] = 'disabled' if desativado else 'normal'
        cnf['width'] = 2
        cnf['command'] = lambda evt=None: self.eventos['sortear'](valor=valor)

        pack['side'] = 'left'

        botao = TKUtils.obter_botao(master=master, cnf=cnf, pack=pack)

        return botao

    def criar_botao_remover(self, master, id_do_elemento, cnf={}, pack={}):
        cnf['text'] = 'X'
        cnf['bg'] = 'red'
        cnf['width'] = 2
        cnf['command'] = lambda evt=None: self.eventos['remover'](
            id_do_elemento)

        pack['side'] = 'right'

        botao = TKUtils.obter_botao(master=master, cnf=cnf, pack=pack)

        return botao