# Path: elbepack/debianize/base/tui.py
# class TUISignal(object):
#     QUIT = "on_quit"
#     CLICK = "on_click"
#     FLUSH = "on_flush"


from urwid import (
    AttrMap,
    LineBox,
    Text,
    WidgetWrap,
    connect_signal,
    emit_signal
)
from elbepack.debianize.base.tui import TUISignal





class Button(WidgetWrap):
    """
    A simple and clean button widget
    """

    signals = [TUISignal.CLICK]

    def __init__(self, text, palette, callback):
        """
        @text:  The text of show in the button.
        @palette:  A valid palette name to apply on the button.  See @TUI::palette
        @callback:  The callback to call when the button is clicked.
        """

        widget = LineBox(AttrMap(Text("[{}]".format(text), align="center"),
                                 "default", palette))
        super(Button, self).__init__(widget)
        connect_signal(self, TUISignal.CLICK, callback)

        # Very important!  This is not documented in urwid's
        # documentation!  Without this, the button would only text.
        self._w.base_widget._selectable = True

    def keypress(self, size, key):
        if key == "enter":

# Path: elbepack/debianize/base/tui.py
# class TUISignal(object):
#     QUIT = "on_quit"
#     CLICK = "on_click"
#     FLUSH = "on_flush"


# Path: elbepack/debianize/widgets/button.py
from urwid import (
    AttrMap,
    LineBox,
    Text,
    WidgetWrap,
    connect_signal,
    emit_signal
)
from elbepack.debianize.base.tui import TUISignal






class Button(WidgetWrap):
    """
    A simple and clean button widget
    """

    signals = [TUISignal.CLICK]

    def __init__(self, text, palette, callback):
        """
        @text:  The text of show in the button.
        @palette:  A valid palette name to apply on the button.  See @TUI::palette
        @callback:  The callback to call when the button is clicked.
        """

        widget = LineBox(AttrMap(Text("[{}]".format(text), align="center"),
                                 "default", palette))
        super(Button, self).__init__(widget)
        connect_signal(self, TUISignal.CLICK, callback)

        # Very important!  This is not documented in urwid's
        # documentation!  Without this, the button would only text.
        self._w.base_widget._selectable = True

    def keypress(self, size, key):
        if key == "enter":

            emit_signal(self, TUISignal.CLICK)