From 415a2b7d2c1f60723df491bc8f5b442ac5795f55 Mon Sep 17 00:00:00 2001 From: Raffaello Bonghi Date: Sun, 10 May 2020 12:20:06 +0100 Subject: [PATCH] Fix loop arrows buttons --- jtop/gui/jtopgui.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/jtop/gui/jtopgui.py b/jtop/gui/jtopgui.py index ea6ef42d..690c979b 100644 --- a/jtop/gui/jtopgui.py +++ b/jtop/gui/jtopgui.py @@ -171,8 +171,12 @@ def increase(self, loop=False): # Fix set new page self.set(idx + 1) - def decrease(self): - idx = self.n_page + 1 + def decrease(self, loop=False): + # check reset + if loop and self.n_page <= 0: + idx = len(self.pages) + 1 + else: + idx = self.n_page + 1 self.set(idx - 1) def set(self, idx): @@ -256,12 +260,10 @@ def keyboard(self, event): self.key = event if self.old_key != self.key: # keyboard check list - if self.key == ord('\t'): + if self.key == curses.KEY_LEFT: + self.decrease(loop=True) + elif self.key == curses.KEY_RIGHT or self.key == ord('\t'): self.increase(loop=True) - elif self.key == curses.KEY_LEFT: - self.decrease() - elif self.key == curses.KEY_RIGHT: - self.increase() elif self.key in [ord(str(n)) for n in range(10)]: num = int(chr(self.key)) self.set(num)