tuikit/combobox.py
author Radek Brich <radek.brich@devl.cz>
Sat, 05 Jan 2013 23:00:41 +0100
changeset 52 50a1857557da
parent 46 2b43a7f38c34
child 62 2f61931520c9
permissions -rw-r--r--
Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.

# -*- coding: utf-8 -*-

from tuikit.container import Container
from tuikit.editfield import EditField
from tuikit.button import Button
from tuikit.menu import Menu


class ComboBox(Container):
    def __init__(self, width=15, value='', items=[]):
        Container.__init__(self, width, 1)

        self.allow_focus = True

        self.colorprefix = 'combo:'

        self._edit = EditField(width - 3, value)
        self.add(self._edit)

        self._btn = Button('v')
        self._btn.prefix = ''
        self._btn.suffix = ''
        self._btn.x = width - 3
        self._btn.width = 3
        self._btn.add_handler('click', self._on_btn_click)
        self.add(self._btn)

        self._menu = Menu(items)
        self._menu.hide()
        self._menu.allow_layout = False

    def _set_top(self, value):
        Container._set_top(self, value)
        self.top.add(self._menu)

    def _on_btn_click(self, ev):
        self._menu.show()