mirror of
https://github.com/XuehaiPan/nvitop.git
synced 2026-05-22 06:05:47 -06:00
feat(gui/messagebox): add mouse click support
Signed-off-by: Xuehai Pan <XuehaiPan@pku.edu.cn>
This commit is contained in:
parent
f9c9412618
commit
207d163fec
1 changed files with 20 additions and 2 deletions
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
|
||||
|
||||
import curses
|
||||
import time
|
||||
from functools import partial
|
||||
|
||||
from nvitop.gui.library.displayable import Displayable
|
||||
|
|
@ -49,6 +51,7 @@ class MessageBox(Displayable): # pylint: disable=too-many-instance-attributes
|
|||
self.yes = yes
|
||||
self.cancel = cancel
|
||||
self.no = no # pylint: disable=invalid-name
|
||||
self.timestamp = time.monotonic()
|
||||
|
||||
self.name_len = max(8, max(len(option.name) for option in options))
|
||||
for option in self.options:
|
||||
|
|
@ -90,6 +93,15 @@ class MessageBox(Displayable): # pylint: disable=too-many-instance-attributes
|
|||
]
|
||||
self.lines = lines
|
||||
|
||||
@property
|
||||
def current(self):
|
||||
return self._current
|
||||
|
||||
@current.setter
|
||||
def current(self, value):
|
||||
self._current = value
|
||||
self.timestamp = time.monotonic()
|
||||
|
||||
def draw(self):
|
||||
self.set_base_attr(attr=0)
|
||||
self.color_reset()
|
||||
|
|
@ -119,8 +131,10 @@ class MessageBox(Displayable): # pylint: disable=too-many-instance-attributes
|
|||
0 <= current < self.num_options
|
||||
and x_option_start - 3 <= x < x_option_start + self.name_len + 3
|
||||
):
|
||||
self.current = current
|
||||
self.xy_mouse = None
|
||||
if self.current == current and time.monotonic() >= self.timestamp + 0.5:
|
||||
curses.ungetch(ord('\n'))
|
||||
else:
|
||||
self.current = current
|
||||
|
||||
option = self.options[self.current]
|
||||
x_option_start = x_start + 6 + self.current * (self.name_len + 6)
|
||||
|
|
@ -140,6 +154,10 @@ class MessageBox(Displayable): # pylint: disable=too-many-instance-attributes
|
|||
attr['attr'] |= self.get_fg_bg_attr(attr='standout | bold')
|
||||
self.color_at(y, x, **attr)
|
||||
|
||||
def finalize(self):
|
||||
self.xy_mouse = None
|
||||
super().finalize()
|
||||
|
||||
def press(self, key):
|
||||
self.root.keymaps.use_keymap('messagebox')
|
||||
self.root.press(key)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue