1
0
mirror of https://github.com/ihabunek/toot synced 2025-01-11 09:03:57 +01:00
Toot-Mastodon-CLI-TUI-clien.../toot/tui/widgets.py
2019-09-03 15:40:42 +02:00

32 lines
705 B
Python

import urwid
class Clickable:
"""
Add a `click` signal which is sent when the item is activated or clicked.
TODO: make it work on widgets which have other signals.
"""
signals = ["click"]
def keypress(self, size, key):
if self._command_map[key] == urwid.ACTIVATE:
self._emit('click')
return
return key
def mouse_event(self, size, event, button, x, y, focus):
if button == 1:
self._emit('click')
return super().mouse_event(size, event, button, x, y, focus)
class SelectableText(Clickable, urwid.Text):
_selectable = True
class SelectableColumns(Clickable, urwid.Columns):
_selectable = True