mirror of
https://github.com/wassname/sloth.git
synced 2026-08-14 12:50:50 +08:00
Added contextmenu with filename copy action to filelabel qlabel.
This commit is contained in:
committed by
Mika Fischer
parent
ac2a99ae33
commit
dfd685d2dd
@@ -2,6 +2,16 @@ import sys, os
|
|||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore 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):
|
class ControlButtonWidget(QWidget):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QWidget.__init__(self, parent)
|
QWidget.__init__(self, parent)
|
||||||
@@ -10,7 +20,11 @@ class ControlButtonWidget(QWidget):
|
|||||||
layout.setAlignment(Qt.AlignTop)
|
layout.setAlignment(Qt.AlignTop)
|
||||||
self.back_button = QPushButton("<")
|
self.back_button = QPushButton("<")
|
||||||
self.forward_button = QPushButton(">")
|
self.forward_button = QPushButton(">")
|
||||||
self._label = QLabel("<center><b></b></center>")
|
self._label = Label("<center><b></b></center>")
|
||||||
|
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.back_button)
|
||||||
layout.addWidget(self._label)
|
layout.addWidget(self._label)
|
||||||
layout.addWidget(self.forward_button)
|
layout.addWidget(self.forward_button)
|
||||||
@@ -21,3 +35,11 @@ class ControlButtonWidget(QWidget):
|
|||||||
|
|
||||||
def setFilename(self, filename):
|
def setFilename(self, filename):
|
||||||
self._label.setText("<center><b>%s</b></center>" % (filename, ))
|
self._label.setText("<center><b>%s</b></center>" % (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)
|
||||||
|
|||||||
Reference in New Issue
Block a user