Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StatusLabel menu now includes the start of the cmd time being reported #16

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion preditor/scintilla/documenteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

import six
from PyQt5.Qsci import QsciScintilla
from PyQt5.QtCore import QTextCodec
from Qt import QtCompat
from Qt.QtCore import Property, QFile, QPoint, Qt, QTextCodec, Signal
from Qt.QtCore import Property, QFile, QPoint, Qt, Signal
from Qt.QtGui import QColor, QFont, QFontMetrics, QIcon
from Qt.QtWidgets import (
QAction,
Expand Down