From dfd685d2dd1bdcaeee72a9a5cb0d20d0c77d442c Mon Sep 17 00:00:00 2001 From: Daniel Morlock Date: Tue, 13 Aug 2013 11:49:45 +0200 Subject: [PATCH] Added contextmenu with filename copy action to filelabel qlabel. --- sloth/gui/controlbuttons.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/sloth/gui/controlbuttons.py b/sloth/gui/controlbuttons.py index b6190f9..4860903 100644 --- a/sloth/gui/controlbuttons.py +++ b/sloth/gui/controlbuttons.py @@ -2,6 +2,16 @@ import sys, os from PyQt4.QtGui import * from PyQt4.QtCore import * +class Label(QLabel): + + def __init__(self, *args, **kwargs): + QLabel.__init__(self, *args, **kwargs) + + def mouseReleaseEvent(self, ev): + menu = QMenu(self) + menu.addActions(self.actions()) + menu.exec_(ev.globalPos()) + class ControlButtonWidget(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) @@ -10,7 +20,11 @@ class ControlButtonWidget(QWidget): layout.setAlignment(Qt.AlignTop) self.back_button = QPushButton("<") self.forward_button = QPushButton(">") - self._label = QLabel("
") + self._label = Label("
") + self._action_copy = QAction("Copy", self._label) + self._label.addAction(self._action_copy) + self._action_copy.triggered.connect(self.copyFilename) + layout.addWidget(self.back_button) layout.addWidget(self._label) layout.addWidget(self.forward_button) @@ -21,3 +35,11 @@ class ControlButtonWidget(QWidget): def setFilename(self, filename): self._label.setText("
%s
" % (filename, )) + + @pyqtSlot() + def copyFilename(self): + doc = QTextDocument() + doc.setHtml(self._label.text()) + text = doc.toPlainText() + QApplication.clipboard().setText(text) + QApplication.clipboard().setText(text, QClipboard.Selection)