Skip to content

Commit

Permalink
StatusLabel menu now includes the start of the cmd time being reported
Browse files Browse the repository at this point in the history
  • Loading branch information
MHendricks committed May 20, 2024
1 parent f7c068f commit d568f8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion preditor/gui/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def executeString(self, commandText, filename='<ConsolePrEdit>', 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):
Expand Down
17 changes: 14 additions & 3 deletions preditor/gui/status_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d568f8a

Please sign in to comment.