src/eric7/Plugins/WizardPlugins/FontDialogWizard/FontDialogWizardDialog.py

Fri, 25 Oct 2024 17:58:59 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 25 Oct 2024 17:58:59 +0200
branch
eric7
changeset 11006
a671918232f3
parent 10439
21c28b0f9e41
child 11090
f5f5f5803935
permissions
-rw-r--r--

Modified modal dialog usage to always include a valid parent (needed for Wayland).

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
10439
21c28b0f9e41 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10437
diff changeset
3 # Copyright (c) 2003 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the font dialog wizard dialog.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
12 from PyQt6.QtCore import pyqtSlot
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
13 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QFontDialog
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
15 from .Ui_FontDialogWizardDialog import Ui_FontDialogWizardDialog
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
17
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class FontDialogWizardDialog(QDialog, Ui_FontDialogWizardDialog):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 Class implementing the font dialog wizard dialog.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
21
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 It displays a dialog for entering the parameters
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 for the QFontDialog code generator.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
25
8324
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
26 FontWeight2Code = {
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
27 100: "Thin",
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
28 200: "ExtraLight",
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
29 300: "Light",
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
30 400: "Normal",
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
31 500: "Medium",
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
32 600: "DemiBold",
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
33 700: "Bold",
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
34 800: "ExtraBold",
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
35 900: "Black",
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
36 }
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
37
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 def __init__(self, parent=None):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
41
10437
2f70ca07f0af Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
42 @param parent parent widget
2f70ca07f0af Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
43 @type QWidget
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
45 super().__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.setupUi(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
47
2893
150de635fa29 Some changes to code generation wizards.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
48 self.bTest = self.buttonBox.addButton(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
49 self.tr("Test"), QDialogButtonBox.ButtonRole.ActionRole
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
50 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
51
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.font = None
8410
f8d97f05f883 Started improving the Font Dialog Wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8324
diff changeset
53 self.fontOptions = {
f8d97f05f883 Started improving the Font Dialog Wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8324
diff changeset
54 "noNativeDialog": False,
f8d97f05f883 Started improving the Font Dialog Wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8324
diff changeset
55 "scalableFonts": False,
f8d97f05f883 Started improving the Font Dialog Wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8324
diff changeset
56 "nonScalableFonts": False,
f8d97f05f883 Started improving the Font Dialog Wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8324
diff changeset
57 "monospacedFonts": False,
f8d97f05f883 Started improving the Font Dialog Wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8324
diff changeset
58 "proportionalFonts": False,
f8d97f05f883 Started improving the Font Dialog Wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8324
diff changeset
59 }
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
60
3366
6084bb3c3911 Made some changes to have a bunch of dialogs with correct sizes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
61 msh = self.minimumSizeHint()
6084bb3c3911 Made some changes to have a bunch of dialogs with correct sizes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
62 self.resize(max(self.width(), msh.width()), msh.height())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
63
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 def on_buttonBox_clicked(self, button):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 Private slot called by a button of the button box clicked.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
67
10437
2f70ca07f0af Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
68 @param button button that was clicked
2f70ca07f0af Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
69 @type QAbstractButton
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 if button == self.bTest:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.on_bTest_clicked()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
73
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 @pyqtSlot()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 def on_bTest_clicked(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 Private method to test the selected options.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 if self.font is None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 QFontDialog.getFont()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 else:
8413
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
82 options = QFontDialog.FontDialogOption(0)
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
83 if any(self.fontOptions.values()):
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
84 if self.fontOptions["noNativeDialog"]:
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
85 options |= QFontDialog.FontDialogOption.DontUseNativeDialog
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
86 if self.fontOptions["scalableFonts"]:
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
87 options |= QFontDialog.FontDialogOption.ScalableFonts
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
88 if self.fontOptions["nonScalableFonts"]:
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
89 options |= QFontDialog.FontDialogOption.NonScalableFonts
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
90 if self.fontOptions["monospacedFonts"]:
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
91 options |= QFontDialog.FontDialogOption.MonospacedFonts
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
92 if self.fontOptions["proportionalFonts"]:
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
93 options |= QFontDialog.FontDialogOption.ProportionalFonts
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
94 QFontDialog.getFont(self.font, self, self.eCaption.text(), options)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
95
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 def on_eVariable_textChanged(self, text):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 Private slot to handle the textChanged signal of eVariable.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
99
10437
2f70ca07f0af Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
100 @param text the new text
2f70ca07f0af Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
101 @type str
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 if not text:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 self.bTest.setEnabled(True)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 self.bTest.setEnabled(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
107
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 @pyqtSlot()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 def on_fontButton_clicked(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
2893
150de635fa29 Some changes to code generation wizards.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
111 Private slot to handle the button press to select a font via a
150de635fa29 Some changes to code generation wizards.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
112 font selection dialog.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 if self.font is None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 font, ok = QFontDialog.getFont()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 font, ok = QFontDialog.getFont(self.font)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 if ok:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.font = font
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 self.font = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
122
8413
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
123 @pyqtSlot()
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
124 def on_optionsButton_clicked(self):
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
125 """
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
126 Private slot to handle the selection of font dialog options.
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
127 """
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
128 from .FontDialogOptionsDialog import FontDialogOptionsDialog
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
129
11006
a671918232f3 Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10439
diff changeset
130 dlg = FontDialogOptionsDialog(self.fontOptions, parent=self)
8413
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
131 if dlg.exec() == QDialog.DialogCode.Accepted:
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
132 self.fontOptions = dlg.getOptions()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
133
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 def getCode(self, indLevel, indString):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 Public method to get the source code.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
137
10437
2f70ca07f0af Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
138 @param indLevel indentation level
2f70ca07f0af Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
139 @type int
2f70ca07f0af Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
140 @param indString string used for indentation (space or tab)
2f70ca07f0af Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
141 @type str
2f70ca07f0af Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
142 @return generated code
2f70ca07f0af Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
143 @rtype str
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 """
3125
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
145 # calculate our indentation level and the indentation string
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
146 il = indLevel + 1
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
147 istring = il * indString
446
69aac6eeba9b Changed the wizards code generation to eliminate not needed backslashes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 425
diff changeset
148 estring = os.linesep + indLevel * indString
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
149
96
9624a110667d Started to clean up the code supported by py3flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
150 # generate the code
3124
a01e410893ac Extended the dialog wizards to generate code for the result variable(s).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2893
diff changeset
151 resvar = self.eResultVar.text()
a01e410893ac Extended the dialog wizards to generate code for the result variable(s).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2893
diff changeset
152 if not resvar:
a01e410893ac Extended the dialog wizards to generate code for the result variable(s).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2893
diff changeset
153 resvar = "font"
3125
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
154 title = self.eCaption.text()
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
155 if self.parentSelf.isChecked():
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
156 parent = "self"
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
157 elif self.parentNone.isChecked():
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
158 parent = "None"
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
159 elif self.parentOther.isChecked():
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
160 parent = self.parentEdit.text()
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
161 if parent == "":
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
162 parent = "None"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
163
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
164 code = "{0}, ok = QFontDialog.getFont(".format(resvar)
3125
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
165 if self.eVariable.text() or self.font is not None:
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
166 if title or parent != "None":
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
167 code += "{0}{1}".format(os.linesep, istring)
3125
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
168 if not self.eVariable.text():
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
169 if self.font is not None:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
170 code += 'QFont(["{0}"], {1:d}, QFont.Weight.{2}, {3})'.format(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
171 self.font.family(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
172 self.font.pointSize(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
173 FontDialogWizardDialog.FontWeight2Code[self.font.weight()],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
174 "True" if self.font.italic() else "False",
8324
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
175 )
3125
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
176 else:
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
177 code += self.eVariable.text()
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
178 if title:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
179 code += ",{0}{1}{2}".format(os.linesep, istring, parent)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
180 code += ',{0}{1}self.tr("{2}")'.format(os.linesep, istring, title)
3125
385a62b53725 Extended some dialog wizards to generate code for the parent widget and extended the QFontDialog wizard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3124
diff changeset
181 elif parent != "None":
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
182 code += ",{0}{1}{2}".format(os.linesep, istring, parent)
8413
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
183 if any(self.fontOptions.values()):
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
184 options = []
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
185 if self.fontOptions["noNativeDialog"]:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
186 options.append("QFontDialog.FontDialogOption.DontUseNativeDialog")
8413
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
187 if self.fontOptions["scalableFonts"]:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
188 options.append("QFontDialog.FontDialogOption.ScalableFonts")
8413
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
189 if self.fontOptions["nonScalableFonts"]:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
190 options.append("QFontDialog.FontDialogOption.NonScalableFonts")
8413
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
191 if self.fontOptions["monospacedFonts"]:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
192 options.append("QFontDialog.FontDialogOption.MonospacedFonts")
8413
65ed18753c40 Font Dialog Wizard: enhanced the wizard to allow the selection of font dialog options.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8410
diff changeset
193 if self.fontOptions["proportionalFonts"]:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
194 options.append("QFontDialog.FontDialogOption.ProportionalFonts")
9433
6df1aeaa4529 Adjusted some wizard code generators to output Black compatible code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
195 fontOptionsString = "{0}{1}| ".format(os.linesep, istring).join(options)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
196 code += ",{0}{1}{2}".format(os.linesep, istring, fontOptionsString)
9433
6df1aeaa4529 Adjusted some wizard code generators to output Black compatible code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
197 code += ",{0}){0}".format(estring)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
198
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 return code

eric ide

mercurial