def __init__(self): from editxt.platform.views import ListView eventize(self) self._items = KVOList() self.view = ListView(self._items, [{"name": "value", "title": None}]) self.select_range = None
class AutoCompleteMenu(object): class events: double_click = eventize.call("view.on.double_click", dispatch=False) items_changed = eventize.attr("fire_items_changed") selection_changed = eventize.call("setup_selection_changed") fire_items_changed = None def __init__(self): from editxt.platform.views import ListView eventize(self) self._items = KVOList() self.view = ListView(self._items, [{"name": "value", "title": None}]) self.select_range = None def setup_selection_changed(self, callback): def adapt(items): callback([x.value for x in items]) self.view.on.selection_changed(adapt) @property def scroller(self): return self.view.scroll @property def preferred_height(self): return self.view.preferred_height def __bool__(self): return bool(self._items) @property def title(self): return self.view.title @title.setter def title(self, value): self.view.title = value @property def items(self): return [i.value for i in self._items] @items.setter def items(self, items): self._items[:] = [KVOProxy(Completion(v)) for v in items] self.select_range = None if self.fire_items_changed is not None: self.fire_items_changed() def select(self, index): self.view.select(index) def select_next(self): index = self.view.selected_row if index > -1 and index < len(self._items) - 1: self.view.select(index + 1) else: self.view.select(0) def select_prev(self): index = self.view.selected_row if index > 0: self.view.select(index - 1) else: self.view.select(len(self._items) - 1) @property def selected_item(self): row = self.view.selected_row return self._items[row].value if row > -1 else None