1 | from PyQt5 import QtCore |
---|
2 | from PyQt5 import QtGui |
---|
3 | from PyQt5 import QtWidgets |
---|
4 | |
---|
5 | import sas.sasview |
---|
6 | |
---|
7 | from sas.qtgui.Plotting.UI.AddTextUI import Ui_AddText |
---|
8 | |
---|
9 | class AddText(QtWidgets.QDialog, Ui_AddText): |
---|
10 | """ Simple GUI for a single line text query """ |
---|
11 | def __init__(self, parent=None): |
---|
12 | super(AddText, self).__init__(parent) |
---|
13 | self.setupUi(self) |
---|
14 | # disable the context help icon |
---|
15 | self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint) |
---|
16 | |
---|
17 | self._font = QtGui.QFont() |
---|
18 | self._color = "black" |
---|
19 | self.btnFont.clicked.connect(self.onFontChange) |
---|
20 | self.btnColor.clicked.connect(self.onColorChange) |
---|
21 | |
---|
22 | def text(self): |
---|
23 | return self.textEdit.toPlainText() |
---|
24 | |
---|
25 | def font(self): |
---|
26 | return self._font |
---|
27 | |
---|
28 | def color(self): |
---|
29 | return self._color |
---|
30 | |
---|
31 | def onFontChange(self, event): |
---|
32 | """ |
---|
33 | Pop up the standard Qt Font change dialog |
---|
34 | """ |
---|
35 | self._font, ok = QtWidgets.QFontDialog.getFont(parent=self) |
---|
36 | if ok: |
---|
37 | self.textEdit.setFont(self._font) |
---|
38 | |
---|
39 | def onColorChange(self, event): |
---|
40 | """ |
---|
41 | Pop up the standard Qt color change dialog |
---|
42 | """ |
---|
43 | # Pick up the chosen color |
---|
44 | self._color = QtWidgets.QColorDialog.getColor(parent=self) |
---|
45 | # Update the text control |
---|
46 | palette = QtGui.QPalette() |
---|
47 | palette.setColor(QtGui.QPalette.Text, self._color) |
---|
48 | self.textEdit.setPalette(palette) |
---|
49 | |
---|
50 | # Save the color as #RRGGBB |
---|
51 | self._color = str(self._color.name()) |
---|