Plugins/WizardPlugins/FontDialogWizard/FontDialogWizardDialog.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the font dialog wizard dialog.
8 """
9
10 import os
11
12 from PyQt4.QtCore import *
13 from PyQt4.QtGui import *
14
15 from Ui_FontDialogWizardDialog import Ui_FontDialogWizardDialog
16
17 class FontDialogWizardDialog(QDialog, Ui_FontDialogWizardDialog):
18 """
19 Class implementing the font dialog wizard dialog.
20
21 It displays a dialog for entering the parameters
22 for the QFontDialog code generator.
23 """
24 def __init__(self, parent=None):
25 """
26 Constructor
27
28 @param parent parent widget (QWidget)
29 """
30 QDialog.__init__(self, parent)
31 self.setupUi(self)
32
33 self.bTest = \
34 self.buttonBox.addButton(self.trUtf8("Test"), QDialogButtonBox.ActionRole)
35
36 self.font = None
37
38 def on_buttonBox_clicked(self, button):
39 """
40 Private slot called by a button of the button box clicked.
41
42 @param button button that was clicked (QAbstractButton)
43 """
44 if button == self.bTest:
45 self.on_bTest_clicked()
46
47 @pyqtSlot()
48 def on_bTest_clicked(self):
49 """
50 Private method to test the selected options.
51 """
52 if self.font is None:
53 QFontDialog.getFont()
54 else:
55 QFontDialog.getFont(self.font)
56
57 def on_eVariable_textChanged(self, text):
58 """
59 Private slot to handle the textChanged signal of eVariable.
60
61 @param text the new text (string)
62 """
63 if not text:
64 self.bTest.setEnabled(True)
65 else:
66 self.bTest.setEnabled(False)
67
68 @pyqtSlot()
69 def on_fontButton_clicked(self):
70 """
71 Private slot to handle the button press to select a font via a font selection
72 dialog.
73 """
74 if self.font is None:
75 font, ok = QFontDialog.getFont()
76 else:
77 font, ok = QFontDialog.getFont(self.font)
78 if ok:
79 self.font = font
80 else:
81 self.font = None
82
83 def getCode(self, indLevel, indString):
84 """
85 Public method to get the source code.
86
87 @param indLevel indentation level (int)
88 @param indString string used for indentation (space or tab) (string)
89 @return generated code (string)
90 """
91 # calculate our indentation level and the indentation string
92 il = indLevel + 1
93 istring = il * indString
94
95 # now generate the code
96 code = 'QFontDialog.getFont('
97 if not self.eVariable.text():
98 if self.font is not None:
99 code += 'QFont("%s", %d, %d, %d)' % \
100 (self.font.family(), self.font.pointSize(),
101 self.font.weight(), self.font.italic())
102 else:
103 code += self.eVariable.text()
104 code += ')%s' % os.linesep
105
106 return code

eric ide

mercurial