-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtextEditDialog.py
51 lines (40 loc) · 1.46 KB
/
textEditDialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from Qt import QtWidgets, QtGui
class TextEditDialog(QtWidgets.QDialog):
"""
Custom pop-up dialog for editing text purpose, or getting long text input
"""
def __init__(self, text='', title=''):
"""
Initializing the dialog ui elements and connect signals
:param text: str. pre-displayed text
:param title: str. dialog title
"""
super(TextEditDialog, self).__init__()
self.setWindowTitle(title)
self.ui_textEdit = QtWidgets.QPlainTextEdit(text)
self.ui_textEdit.setTabStopWidth(self.ui_textEdit.fontMetrics().width(' ') * 4)
self.ui_acceptButton = QtWidgets.QPushButton("Confirm")
layout = QtWidgets.QGridLayout()
layout.addWidget(self.ui_textEdit, 0, 0)
layout.addWidget(self.ui_acceptButton, 1, 0)
self.setLayout(layout)
self.ui_acceptButton.clicked.connect(self.onClickAccept)
def onClickAccept(self):
"""
Trigger accept event when clicking the confirm button
"""
if self.ui_textEdit.toPlainText():
self.accept()
else:
print('value cannot be empty')
def getTextEdit(self):
"""
Get the text from text edit field
:return: str. text from text edit field
"""
return self.ui_textEdit.toPlainText()
def closeEvent(self, event):
"""
Overwrite the close event as it handles accept by default
"""
self.close()