From d568f8a02d91bb20b402c1af5e29ec9fd9745c9c Mon Sep 17 00:00:00 2001 From: Mike Hendricks Date: Mon, 20 May 2024 11:12:12 -0700 Subject: [PATCH] StatusLabel menu now includes the start of the cmd time being reported --- preditor/gui/console.py | 2 +- preditor/gui/status_label.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/preditor/gui/console.py b/preditor/gui/console.py index 1ee5f657..b037b0d2 100644 --- a/preditor/gui/console.py +++ b/preditor/gui/console.py @@ -358,7 +358,7 @@ def executeString(self, commandText, filename='', extraPrint=True # Report the total time it took to execute this code. if self.reportExecutionTime is not None: - self.reportExecutionTime(delta) + self.reportExecutionTime((delta, commandText)) return cmdresult, wasEval def executeCommand(self): diff --git a/preditor/gui/status_label.py b/preditor/gui/status_label.py index b7acba02..f1f17d3c 100644 --- a/preditor/gui/status_label.py +++ b/preditor/gui/status_label.py @@ -54,17 +54,28 @@ def setText(self, text): def showSeconds(self, seconds): self.times.append(seconds) - self.setText(self.secondsText(seconds)) + self.setText(self.secondsText(seconds[0])) def showMenu(self): menu = QMenu(self) if self.times: # Show the time it took to run the last X code calls + times = [] for seconds in self.times: - menu.addAction(self.secondsText(seconds)) + secs, cmd = seconds + times.append(secs) + + # Add a simplified copy of the command that was run + cmd = cmd.strip() + cmds = cmd.split("\n") + if len(cmds) > 1 or len(cmds[0]) > 50: + cmd = "{} ...".format(cmds[0][:50]) + # Escape &'s so they dont' get turned into a shortcut' + cmd = cmd.replace("&", "&&") + menu.addAction("{}: {}".format(self.secondsText(secs), cmd)) menu.addSeparator() - avg = sum(self.times) / len(self.times) + avg = sum(times) / len(times) menu.addAction("Average: {:0.04f}s".format(avg)) act = menu.addAction("Clear") act.triggered.connect(self.clearTimes)