|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2020 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to show some plain text. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot |
|
11 from PyQt6.QtGui import QGuiApplication |
|
12 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
|
13 |
|
14 from .Ui_EricPlainTextDialog import Ui_EricPlainTextDialog |
|
15 |
|
16 |
|
17 class EricPlainTextDialog(QDialog, Ui_EricPlainTextDialog): |
|
18 """ |
|
19 Class implementing a dialog to show some plain text. |
|
20 """ |
|
21 def __init__(self, title="", text="", readOnly=True, parent=None): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param title title of the dialog (defaults to "") |
|
26 @type str (optional) |
|
27 @param text text to be shown (defaults to "") |
|
28 @type str (optional) |
|
29 @param readOnly flag indicating a read-only dialog (defaults to True) |
|
30 @type bool (optional) |
|
31 @param parent reference to the parent widget (defaults to None) |
|
32 @type QWidget (optional) |
|
33 """ |
|
34 super().__init__(parent) |
|
35 self.setupUi(self) |
|
36 |
|
37 self.copyButton = self.buttonBox.addButton( |
|
38 self.tr("Copy to Clipboard"), |
|
39 QDialogButtonBox.ButtonRole.ActionRole) |
|
40 self.copyButton.clicked.connect(self.on_copyButton_clicked) |
|
41 |
|
42 self.setWindowTitle(title) |
|
43 self.textEdit.setPlainText(text) |
|
44 self.textEdit.setReadOnly(readOnly) |
|
45 |
|
46 @pyqtSlot() |
|
47 def on_copyButton_clicked(self): |
|
48 """ |
|
49 Private slot to copy the text to the clipboard. |
|
50 """ |
|
51 txt = self.textEdit.toPlainText() |
|
52 cb = QGuiApplication.clipboard() |
|
53 cb.setText(txt) |
|
54 |
|
55 def toPlainText(self): |
|
56 """ |
|
57 Public method to get the plain text. |
|
58 |
|
59 @return contents of the plain text edit |
|
60 @rtype str |
|
61 """ |
|
62 return self.textEdit.toPlainText() |