Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
# -*- 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)