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

Selecting the run-time and average status menus now copies their text #19

Merged
merged 1 commit into from
Aug 20, 2024
Merged
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
15 changes: 12 additions & 3 deletions preditor/gui/status_label.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import absolute_import

from collections import deque
from functools import partial

from Qt.QtCore import QPoint, QTimer
from Qt.QtWidgets import QInputDialog, QLabel, QMenu
from Qt.QtWidgets import QApplication, QInputDialog, QLabel, QMenu


class StatusLabel(QLabel):
Expand Down Expand Up @@ -33,6 +34,10 @@ def chooseLimit(self):
if limit:
self.setLimit(limit)

def copy_action_text(self, action):
"""Copy the text of the provided action into the clipboard."""
QApplication.clipboard().setText(action.text())

def mouseReleaseEvent(self, event):
QTimer.singleShot(0, self.showMenu)
super(StatusLabel, self).mouseReleaseEvent(event)
Expand Down Expand Up @@ -72,11 +77,15 @@ def showMenu(self):
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))
act = menu.addAction("{}: {}".format(self.secondsText(secs), cmd))
# Selecting this action should copy the time it took to run
act.triggered.connect(partial(self.copy_action_text, act))

menu.addSeparator()
avg = sum(times) / len(times)
menu.addAction("Average: {:0.04f}s".format(avg))
act = menu.addAction("Average: {:0.04f}s".format(avg))
act.triggered.connect(partial(self.copy_action_text, act))

act = menu.addAction("Clear")
act.triggered.connect(self.clearTimes)

Expand Down