31 600: "DemiBold", |
32 600: "DemiBold", |
32 700: "Bold", |
33 700: "Bold", |
33 800: "ExtraBold", |
34 800: "ExtraBold", |
34 900: "Black", |
35 900: "Black", |
35 } |
36 } |
36 |
37 |
37 def __init__(self, parent=None): |
38 def __init__(self, parent=None): |
38 """ |
39 """ |
39 Constructor |
40 Constructor |
40 |
41 |
41 @param parent parent widget (QWidget) |
42 @param parent parent widget (QWidget) |
42 """ |
43 """ |
43 super().__init__(parent) |
44 super().__init__(parent) |
44 self.setupUi(self) |
45 self.setupUi(self) |
45 |
46 |
46 self.bTest = self.buttonBox.addButton( |
47 self.bTest = self.buttonBox.addButton( |
47 self.tr("Test"), QDialogButtonBox.ButtonRole.ActionRole) |
48 self.tr("Test"), QDialogButtonBox.ButtonRole.ActionRole |
48 |
49 ) |
|
50 |
49 self.font = None |
51 self.font = None |
50 self.fontOptions = { |
52 self.fontOptions = { |
51 "noNativeDialog": False, |
53 "noNativeDialog": False, |
52 "scalableFonts": False, |
54 "scalableFonts": False, |
53 "nonScalableFonts": False, |
55 "nonScalableFonts": False, |
54 "monospacedFonts": False, |
56 "monospacedFonts": False, |
55 "proportionalFonts": False, |
57 "proportionalFonts": False, |
56 } |
58 } |
57 |
59 |
58 msh = self.minimumSizeHint() |
60 msh = self.minimumSizeHint() |
59 self.resize(max(self.width(), msh.width()), msh.height()) |
61 self.resize(max(self.width(), msh.width()), msh.height()) |
60 |
62 |
61 def on_buttonBox_clicked(self, button): |
63 def on_buttonBox_clicked(self, button): |
62 """ |
64 """ |
63 Private slot called by a button of the button box clicked. |
65 Private slot called by a button of the button box clicked. |
64 |
66 |
65 @param button button that was clicked (QAbstractButton) |
67 @param button button that was clicked (QAbstractButton) |
66 """ |
68 """ |
67 if button == self.bTest: |
69 if button == self.bTest: |
68 self.on_bTest_clicked() |
70 self.on_bTest_clicked() |
69 |
71 |
70 @pyqtSlot() |
72 @pyqtSlot() |
71 def on_bTest_clicked(self): |
73 def on_bTest_clicked(self): |
72 """ |
74 """ |
73 Private method to test the selected options. |
75 Private method to test the selected options. |
74 """ |
76 """ |
85 options |= QFontDialog.FontDialogOption.NonScalableFonts |
87 options |= QFontDialog.FontDialogOption.NonScalableFonts |
86 if self.fontOptions["monospacedFonts"]: |
88 if self.fontOptions["monospacedFonts"]: |
87 options |= QFontDialog.FontDialogOption.MonospacedFonts |
89 options |= QFontDialog.FontDialogOption.MonospacedFonts |
88 if self.fontOptions["proportionalFonts"]: |
90 if self.fontOptions["proportionalFonts"]: |
89 options |= QFontDialog.FontDialogOption.ProportionalFonts |
91 options |= QFontDialog.FontDialogOption.ProportionalFonts |
90 QFontDialog.getFont( |
92 QFontDialog.getFont(self.font, self, self.eCaption.text(), options) |
91 self.font, |
93 |
92 self, |
|
93 self.eCaption.text(), |
|
94 options |
|
95 ) |
|
96 |
|
97 def on_eVariable_textChanged(self, text): |
94 def on_eVariable_textChanged(self, text): |
98 """ |
95 """ |
99 Private slot to handle the textChanged signal of eVariable. |
96 Private slot to handle the textChanged signal of eVariable. |
100 |
97 |
101 @param text the new text (string) |
98 @param text the new text (string) |
102 """ |
99 """ |
103 if not text: |
100 if not text: |
104 self.bTest.setEnabled(True) |
101 self.bTest.setEnabled(True) |
105 else: |
102 else: |
106 self.bTest.setEnabled(False) |
103 self.bTest.setEnabled(False) |
107 |
104 |
108 @pyqtSlot() |
105 @pyqtSlot() |
109 def on_fontButton_clicked(self): |
106 def on_fontButton_clicked(self): |
110 """ |
107 """ |
111 Private slot to handle the button press to select a font via a |
108 Private slot to handle the button press to select a font via a |
112 font selection dialog. |
109 font selection dialog. |
117 font, ok = QFontDialog.getFont(self.font) |
114 font, ok = QFontDialog.getFont(self.font) |
118 if ok: |
115 if ok: |
119 self.font = font |
116 self.font = font |
120 else: |
117 else: |
121 self.font = None |
118 self.font = None |
122 |
119 |
123 @pyqtSlot() |
120 @pyqtSlot() |
124 def on_optionsButton_clicked(self): |
121 def on_optionsButton_clicked(self): |
125 """ |
122 """ |
126 Private slot to handle the selection of font dialog options. |
123 Private slot to handle the selection of font dialog options. |
127 """ |
124 """ |
128 from .FontDialogOptionsDialog import FontDialogOptionsDialog |
125 from .FontDialogOptionsDialog import FontDialogOptionsDialog |
|
126 |
129 dlg = FontDialogOptionsDialog(self.fontOptions, self) |
127 dlg = FontDialogOptionsDialog(self.fontOptions, self) |
130 if dlg.exec() == QDialog.DialogCode.Accepted: |
128 if dlg.exec() == QDialog.DialogCode.Accepted: |
131 self.fontOptions = dlg.getOptions() |
129 self.fontOptions = dlg.getOptions() |
132 |
130 |
133 def getCode(self, indLevel, indString): |
131 def getCode(self, indLevel, indString): |
134 """ |
132 """ |
135 Public method to get the source code. |
133 Public method to get the source code. |
136 |
134 |
137 @param indLevel indentation level (int) |
135 @param indLevel indentation level (int) |
138 @param indString string used for indentation (space or tab) (string) |
136 @param indString string used for indentation (space or tab) (string) |
139 @return generated code (string) |
137 @return generated code (string) |
140 """ |
138 """ |
141 # calculate our indentation level and the indentation string |
139 # calculate our indentation level and the indentation string |
142 il = indLevel + 1 |
140 il = indLevel + 1 |
143 istring = il * indString |
141 istring = il * indString |
144 estring = os.linesep + indLevel * indString |
142 estring = os.linesep + indLevel * indString |
145 |
143 |
146 # generate the code |
144 # generate the code |
147 resvar = self.eResultVar.text() |
145 resvar = self.eResultVar.text() |
148 if not resvar: |
146 if not resvar: |
149 resvar = "font" |
147 resvar = "font" |
150 title = self.eCaption.text() |
148 title = self.eCaption.text() |
154 parent = "None" |
152 parent = "None" |
155 elif self.parentOther.isChecked(): |
153 elif self.parentOther.isChecked(): |
156 parent = self.parentEdit.text() |
154 parent = self.parentEdit.text() |
157 if parent == "": |
155 if parent == "": |
158 parent = "None" |
156 parent = "None" |
159 |
157 |
160 code = '{0}, ok = QFontDialog.getFont('.format(resvar) |
158 code = "{0}, ok = QFontDialog.getFont(".format(resvar) |
161 if self.eVariable.text() or self.font is not None: |
159 if self.eVariable.text() or self.font is not None: |
162 if title or parent != "None": |
160 if title or parent != "None": |
163 code += '{0}{1}'.format(os.linesep, istring) |
161 code += "{0}{1}".format(os.linesep, istring) |
164 if not self.eVariable.text(): |
162 if not self.eVariable.text(): |
165 if self.font is not None: |
163 if self.font is not None: |
166 code += ( |
164 code += 'QFont(["{0}"], {1:d}, QFont.Weight.{2}, {3})'.format( |
167 'QFont(["{0}"], {1:d}, QFont.Weight.{2}, {3})' |
165 self.font.family(), |
168 .format( |
166 self.font.pointSize(), |
169 self.font.family(), |
167 FontDialogWizardDialog.FontWeight2Code[self.font.weight()], |
170 self.font.pointSize(), |
168 "True" if self.font.italic() else "False", |
171 FontDialogWizardDialog.FontWeight2Code[ |
|
172 self.font.weight()], |
|
173 "True" if self.font.italic() else "False") |
|
174 ) |
169 ) |
175 else: |
170 else: |
176 code += self.eVariable.text() |
171 code += self.eVariable.text() |
177 if title: |
172 if title: |
178 code += ',{0}{1}{2}'.format( |
173 code += ",{0}{1}{2}".format(os.linesep, istring, parent) |
179 os.linesep, istring, parent) |
174 code += ',{0}{1}self.tr("{2}")'.format(os.linesep, istring, title) |
180 code += ',{0}{1}self.tr("{2}")'.format( |
|
181 os.linesep, istring, title) |
|
182 elif parent != "None": |
175 elif parent != "None": |
183 code += ',{0}{1}{2}'.format( |
176 code += ",{0}{1}{2}".format(os.linesep, istring, parent) |
184 os.linesep, istring, parent) |
|
185 if any(self.fontOptions.values()): |
177 if any(self.fontOptions.values()): |
186 options = [] |
178 options = [] |
187 if self.fontOptions["noNativeDialog"]: |
179 if self.fontOptions["noNativeDialog"]: |
188 options.append( |
180 options.append("QFontDialog.FontDialogOption.DontUseNativeDialog") |
189 "QFontDialog.FontDialogOption.DontUseNativeDialog") |
|
190 if self.fontOptions["scalableFonts"]: |
181 if self.fontOptions["scalableFonts"]: |
191 options.append( |
182 options.append("QFontDialog.FontDialogOption.ScalableFonts") |
192 "QFontDialog.FontDialogOption.ScalableFonts") |
|
193 if self.fontOptions["nonScalableFonts"]: |
183 if self.fontOptions["nonScalableFonts"]: |
194 options.append( |
184 options.append("QFontDialog.FontDialogOption.NonScalableFonts") |
195 "QFontDialog.FontDialogOption.NonScalableFonts") |
|
196 if self.fontOptions["monospacedFonts"]: |
185 if self.fontOptions["monospacedFonts"]: |
197 options.append( |
186 options.append("QFontDialog.FontDialogOption.MonospacedFonts") |
198 "QFontDialog.FontDialogOption.MonospacedFonts") |
|
199 if self.fontOptions["proportionalFonts"]: |
187 if self.fontOptions["proportionalFonts"]: |
200 options.append( |
188 options.append("QFontDialog.FontDialogOption.ProportionalFonts") |
201 "QFontDialog.FontDialogOption.ProportionalFonts") |
189 fontOptionsString = " |{0}{1}".format(os.linesep, istring).join(options) |
202 fontOptionsString = ( |
190 code += ",{0}{1}{2}".format(os.linesep, istring, fontOptionsString) |
203 ' |{0}{1}'.format(os.linesep, istring).join(options) |
191 code += "{0}){0}".format(estring) |
204 ) |
192 |
205 code += ',{0}{1}{2}'.format( |
|
206 os.linesep, istring, fontOptionsString) |
|
207 code += '{0}){0}'.format(estring) |
|
208 |
|
209 return code |
193 return code |