tuikit/combobox.py
author Radek Brich <radek.brich@devl.cz>
Fri, 18 Jan 2013 22:36:50 +0100
changeset 62 2f61931520c9
parent 46 2b43a7f38c34
permissions -rw-r--r--
Rework layouts: Layout is now normal Container which places its children upon resize event. Drop TopWindow, top is now any subclass of Container. Add floater concept: floaters are widgets drawn over normal widgets, not clipped by parent. Add HScrollbar and Scrollbar abstract base class.

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

from tuikit.layout import HorizontalLayout
from tuikit.editfield import EditField
from tuikit.button import Button
from tuikit.menu import Menu
import logging


class ComboBox(HorizontalLayout):
    def __init__(self, value='', items=[]):
        HorizontalLayout.__init__(self)
        self._default_size.update(15, 1)
        self.allow_focus = True
        self.colorprefix = 'combo:'

        self._edit = EditField(value)
        self._edit.resize(self.width - 3, 1)
        self.add(self._edit, expand=True, fill=True)

        self._btn = Button('v')
        self._btn.prefix = ''
        self._btn.suffix = ''
        self._btn.resize(3, 1)
        self._btn.add_handler('click', self._on_btn_click)
        self.add(self._btn, expand=False)

        self._menu = Menu(items)
        self._menu.hide()
        self.add_floater(self._menu)

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

    def on_resize(self, ev):
        HorizontalLayout.on_resize(self, ev)
        logging.getLogger('tuikit').info('w = %s', self.width)
        self._menu.move(self.x, self.y + 1)
        self._menu.resize(w=self.width)