Selection now returns to last selection when pressing down from info box

pull/42/head
aristocratos 2020-08-05 21:56:13 +02:00
parent 9621b21025
commit c9c61a9d24
1 changed files with 11 additions and 4 deletions

View File

@ -1847,6 +1847,7 @@ class ProcBox(Box):
select_max: int = 0 select_max: int = 0
selected: int = 0 selected: int = 0
selected_pid: int = 0 selected_pid: int = 0
last_selection: int = 0
filtering: bool = False filtering: bool = False
moved: bool = False moved: bool = False
start: int = 1 start: int = 1
@ -1897,6 +1898,9 @@ class ProcBox(Box):
elif cls.selected > 1: elif cls.selected > 1:
cls.selected -= 1 cls.selected -= 1
elif key == "down": elif key == "down":
if cls.selected == 0 and ProcCollector.detailed and cls.last_selection:
cls.selected = cls.last_selection
cls.last_selection = 0
if cls.selected == cls.select_max and cls.start < ProcCollector.num_procs - cls.select_max + 1: if cls.selected == cls.select_max and cls.start < ProcCollector.num_procs - cls.select_max + 1:
cls.start += 1 cls.start += 1
elif cls.selected < cls.select_max: elif cls.selected < cls.select_max:
@ -1929,6 +1933,7 @@ class ProcBox(Box):
Key.list.insert(0, "enter") Key.list.insert(0, "enter")
return return
elif new_sel > 0 and new_sel != cls.selected: elif new_sel > 0 and new_sel != cls.selected:
if cls.last_selection: cls.last_selection = 0
cls.selected = new_sel cls.selected = new_sel
elif key == "mouse_unselect": elif key == "mouse_unselect":
cls.selected = 0 cls.selected = 0
@ -3035,7 +3040,7 @@ class ProcCollector(Collector): #! add interrupt on _collect and _draw
nonlocal infolist, proc_per_cpu, search, out nonlocal infolist, proc_per_cpu, search, out
name: str; threads: int; username: str; mem: float; cpu: float name: str; threads: int; username: str; mem: float; cpu: float
cont: bool = True cont: bool = True
getinfo: Union[Dict, None] getinfo: Dict = {}
if cls.collect_interrupt: return if cls.collect_interrupt: return
try: try:
name = psutil.Process(pid).name() name = psutil.Process(pid).name()
@ -3046,11 +3051,11 @@ class ProcCollector(Collector): #! add interrupt on _collect and _draw
name = "" name = ""
if pid in infolist: if pid in infolist:
getinfo = infolist[pid] getinfo = infolist[pid]
else:
getinfo = None
if search and not found: if search and not found:
for value in [ name, str(pid), getinfo["username"] if getinfo else "" ]: if "username" in getinfo and isinstance(getinfo["username"], float): getinfo["username"] = ""
if "cmdline" in getinfo and isinstance(getinfo["cmdline"], float): getinfo["cmdline"] = ""
for value in [ name, str(pid), getinfo.get("username", ""), " ".join(getinfo.get("cmdline", "")) ]:
for s in search.split(","): for s in search.split(","):
if s.strip() in value: if s.strip() in value:
found = True found = True
@ -4015,10 +4020,12 @@ def process_keys():
elif key == "enter": elif key == "enter":
if ProcBox.selected > 0 and ProcCollector.detailed_pid != ProcBox.selected_pid and psutil.pid_exists(ProcBox.selected_pid): if ProcBox.selected > 0 and ProcCollector.detailed_pid != ProcBox.selected_pid and psutil.pid_exists(ProcBox.selected_pid):
ProcCollector.detailed = True ProcCollector.detailed = True
ProcBox.last_selection = ProcBox.selected
ProcBox.selected = 0 ProcBox.selected = 0
ProcCollector.detailed_pid = ProcBox.selected_pid ProcCollector.detailed_pid = ProcBox.selected_pid
ProcBox.resized = True ProcBox.resized = True
elif ProcCollector.detailed: elif ProcCollector.detailed:
ProcBox.last_selection = 0
ProcCollector.detailed = False ProcCollector.detailed = False
ProcCollector.detailed_pid = None ProcCollector.detailed_pid = None
ProcBox.resized = True ProcBox.resized = True