|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the sub-style definition dialog. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
14 |
|
15 from E5Gui import E5MessageBox |
|
16 |
|
17 from .Ui_SubstyleDefinitionDialog import Ui_SubstyleDefinitionDialog |
|
18 |
|
19 |
|
20 class SubstyleDefinitionDialog(QDialog, Ui_SubstyleDefinitionDialog): |
|
21 """ |
|
22 Class implementing the sub-style definition dialog. |
|
23 """ |
|
24 def __init__(self, lexer, style, substyle, parent=None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param lexer reference to the lexer object |
|
29 @type PreferencesLexer |
|
30 @param style style number |
|
31 @type int |
|
32 @param substyle sub-style number |
|
33 @type int |
|
34 @param parent reference to the parent widget |
|
35 @type QWidget |
|
36 """ |
|
37 super(SubstyleDefinitionDialog, self).__init__(parent) |
|
38 self.setupUi(self) |
|
39 |
|
40 self.__lexer = lexer |
|
41 self.__style = style |
|
42 self.__substyle = substyle |
|
43 |
|
44 self.header.setText(self.tr("<h3>{0} - {1}</h3>").format( |
|
45 self.__lexer.language(), self.__lexer.description(self.__style))) |
|
46 if self.__substyle >= 0: |
|
47 # it's an edit operation |
|
48 self.descriptionEdit.setText( |
|
49 self.__lexer.description(self.__style, self.__substyle)) |
|
50 self.wordsEdit.setPlainText( |
|
51 self.__lexer.words(self.__style, self.__substyle)) |
|
52 |
|
53 def __updateOk(self): |
|
54 """ |
|
55 Private slot to update the state of the OK button. |
|
56 """ |
|
57 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
58 bool(self.descriptionEdit.text().strip()) and |
|
59 bool(self.wordsEdit.toPlainText().strip()) |
|
60 ) |
|
61 |
|
62 @pyqtSlot(str) |
|
63 def on_descriptionEdit_textChanged(self, txt): |
|
64 """ |
|
65 Private slot handling changes of the description. |
|
66 |
|
67 @param txt text of the description |
|
68 @type str |
|
69 """ |
|
70 self.__updateOk() |
|
71 |
|
72 @pyqtSlot() |
|
73 def on_wordsEdit_textChanged(self): |
|
74 """ |
|
75 Private slot handling changes of the word list. |
|
76 """ |
|
77 self.__updateOk() |
|
78 |
|
79 @pyqtSlot() |
|
80 def on_resetButton_clicked(self): |
|
81 """ |
|
82 Private slot to reset the dialog contents. |
|
83 """ |
|
84 ok = E5MessageBox.yesNo( |
|
85 self, |
|
86 self.tr("Reset Sub-Style Data"), |
|
87 self.tr("""Shall the entered sub-style data be reset?""")) |
|
88 if ok: |
|
89 if self.__substyle >= 0: |
|
90 self.descriptionEdit.setText( |
|
91 self.__lexer.description(self.__style, self.__substyle)) |
|
92 self.wordsEdit.setPlainText( |
|
93 self.__lexer.words(self.__style, self.__substyle)) |
|
94 else: |
|
95 self.descriptionEdit.clear() |
|
96 self.wordsEdit.clear() |
|
97 |
|
98 @pyqtSlot() |
|
99 def on_defaultButton_clicked(self): |
|
100 """ |
|
101 Private slot to set the dialog contents to default values. |
|
102 """ |
|
103 filled = bool(self.descriptionEdit.text().strip()) or \ |
|
104 bool(self.wordsEdit.toPlainText().strip()) |
|
105 if filled: |
|
106 ok = E5MessageBox.yesNo( |
|
107 self, |
|
108 self.tr("Set Sub-Style Data to Default"), |
|
109 self.tr("""Shall the sub-style data be set to default""" |
|
110 """ values?""")) |
|
111 else: |
|
112 ok = True |
|
113 if ok: |
|
114 if self.__substyle >= 0: |
|
115 self.descriptionEdit.setText(self.__lexer.defaultDescription( |
|
116 self.__style, self.__substyle)) |
|
117 self.wordsEdit.setPlainText(self.__lexer.defaultWords( |
|
118 self.__style, self.__substyle)) |
|
119 else: |
|
120 self.descriptionEdit.clear() |
|
121 self.wordsEdit.clear() |
|
122 |
|
123 def getData(self): |
|
124 """ |
|
125 Public method to get the entered data. |
|
126 |
|
127 @return tuple containing the sub-style description and words list. |
|
128 @rtype tuple of (str, str) |
|
129 """ |
|
130 return ( |
|
131 self.descriptionEdit.text().strip(), |
|
132 self.wordsEdit.toPlainText().strip(), |
|
133 ) |