7 Module implementing the color dialog wizard dialog. |
7 Module implementing the color dialog wizard dialog. |
8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt4.QtCore import qVersion, pyqtSlot |
12 from PyQt4.QtCore import pyqtSlot |
13 from PyQt4.QtGui import QColor, QColorDialog, QDialog, qRgba, QDialogButtonBox |
13 from PyQt4.QtGui import QColor, QColorDialog, QDialog, QDialogButtonBox |
14 |
14 |
15 from E5Gui import E5MessageBox |
15 from E5Gui import E5MessageBox |
16 |
16 |
17 from .Ui_ColorDialogWizardDialog import Ui_ColorDialogWizardDialog |
17 from .Ui_ColorDialogWizardDialog import Ui_ColorDialogWizardDialog |
18 |
18 |
63 if coStr.startswith('#'): |
58 if coStr.startswith('#'): |
64 coStr = "QColor('{0}')".format(coStr) |
59 coStr = "QColor('{0}')".format(coStr) |
65 else: |
60 else: |
66 coStr = "QColor({0})".format(coStr) |
61 coStr = "QColor({0})".format(coStr) |
67 try: |
62 try: |
68 if self.rQt45.isChecked(): |
63 exec('from PyQt4.QtCore import Qt;' |
69 exec('QColorDialog.getColor({0}, None, "{1}")'.format( |
64 ' QColorDialog.getColor({0}, None, "{1}")'.format( |
70 coStr, self.eTitle.text())) |
65 coStr, self.eTitle.text())) |
71 else: |
|
72 exec('QColorDialog.getColor({0})'.format(coStr)) |
|
73 except: |
66 except: |
74 E5MessageBox.critical(self, |
67 E5MessageBox.critical(self, |
75 self.trUtf8("QColorDialog Wizard Error"), |
68 self.trUtf8("QColorDialog Wizard Error"), |
76 self.trUtf8("""<p>The colour <b>{0}</b> is not valid.</p>""") |
69 self.trUtf8("""<p>The colour <b>{0}</b> is not valid.</p>""") |
77 .format(coStr)) |
70 .format(coStr)) |
78 |
71 |
79 elif self.rRGBA.isChecked(): |
72 elif self.rRGBA.isChecked(): |
80 if self.rQt45.isChecked(): |
73 QColorDialog.getColor( |
81 QColorDialog.getColor( |
74 QColor(self.sRed.value(), self.sGreen.value(), |
82 QColor(self.sRed.value(), self.sGreen.value(), |
75 self.sBlue.value(), self.sAlpha.value()), |
83 self.sBlue.value(), self.sAlpha.value()), |
76 None, self.eTitle.text(), |
84 None, self.eTitle.text(), |
77 QColorDialog.ColorDialogOptions(QColorDialog.ShowAlphaChannel)) |
85 QColorDialog.ColorDialogOptions(QColorDialog.ShowAlphaChannel)) |
|
86 else: |
|
87 rgba = qRgba(self.sRed.value(), self.sGreen.value(), |
|
88 self.sBlue.value(), self.sAlpha.value()) |
|
89 QColorDialog.getRgba(rgba) |
|
90 |
78 |
91 def on_eRGB_textChanged(self, text): |
79 def on_eRGB_textChanged(self, text): |
92 """ |
80 """ |
93 Private slot to handle the textChanged signal of eRGB. |
81 Private slot to handle the textChanged signal of eRGB. |
94 |
82 |
116 if not text or text.startswith('Qt.') or text.startswith('#'): |
104 if not text or text.startswith('Qt.') or text.startswith('#'): |
117 self.bTest.setEnabled(True) |
105 self.bTest.setEnabled(True) |
118 else: |
106 else: |
119 self.bTest.setEnabled(False) |
107 self.bTest.setEnabled(False) |
120 |
108 |
121 def on_rQt45_toggled(self, on): |
|
122 """ |
|
123 Private slot to handle the toggled signal of the rQt45 radio button. |
|
124 |
|
125 @param on toggle state (boolean) (ignored) |
|
126 """ |
|
127 self.titleGroup.setEnabled(on) |
|
128 |
|
129 def getCode(self, indLevel, indString): |
109 def getCode(self, indLevel, indString): |
130 """ |
110 """ |
131 Public method to get the source code. |
111 Public method to get the source code. |
132 |
112 |
133 @param indLevel indentation level (int) |
113 @param indLevel indentation level (int) |
147 col = self.eColor.currentText() |
127 col = self.eColor.currentText() |
148 if col.startswith('#'): |
128 if col.startswith('#'): |
149 code += 'QColor("{0}")'.format(col) |
129 code += 'QColor("{0}")'.format(col) |
150 else: |
130 else: |
151 code += 'QColor({0})'.format(col) |
131 code += 'QColor({0})'.format(col) |
152 if self.rQt45.isChecked(): |
132 code += ', None,{0}'.format(os.linesep) |
153 code += ', None,{0}'.format(os.linesep) |
133 code += '{0}self.trUtf8("{1}"),{2}'.format( |
154 code += '{0}self.trUtf8("{1}"),{2}'.format( |
134 istring, self.eTitle.text(), os.linesep) |
155 istring, self.eTitle.text(), os.linesep) |
135 code += \ |
156 code += \ |
136 '{0}QColorDialog.ColorDialogOptions(QColorDialog.ShowAlphaChannel)'\ |
157 '{0}QColorDialog.ColorDialogOptions(QColorDialog.ShowAlphaChannel)'\ |
137 .format(istring) |
158 .format(istring) |
|
159 code += '){0}'.format(estring) |
138 code += '){0}'.format(estring) |
160 elif self.rRGBA.isChecked(): |
139 elif self.rRGBA.isChecked(): |
161 if self.rQt45.isChecked(): |
140 code += 'getColor(' |
162 code += 'getColor(' |
141 if not self.eRGB.text(): |
163 if not self.eRGB.text(): |
142 code += 'QColor({0:d}, {1:d}, {2:d}, {3:d}),{4}'.format( |
164 code += 'QColor({0:d}, {1:d}, {2:d}, {3:d}),{4}'.format( |
143 self.sRed.value(), self.sGreen.value(), self.sBlue.value(), |
165 self.sRed.value(), self.sGreen.value(), self.sBlue.value(), |
144 self.sAlpha.value(), os.linesep) |
166 self.sAlpha.value(), os.linesep) |
|
167 else: |
|
168 code += '{0},{1}'.format(self.eRGB.text(), os.linesep) |
|
169 code += '{0}None,{1}'.format(istring, os.linesep) |
|
170 code += '{0}self.trUtf8("{1}"),{2}'.format( |
|
171 istring, self.eTitle.text(), os.linesep) |
|
172 code += \ |
|
173 '{0}QColorDialog.ColorDialogOptions(QColorDialog.ShowAlphaChannel)'\ |
|
174 .format(istring) |
|
175 code += '){0}'.format(estring) |
|
176 else: |
145 else: |
177 code += 'getRgba(' |
146 code += '{0},{1}'.format(self.eRGB.text(), os.linesep) |
178 if not self.eRGB.text(): |
147 code += '{0}None,{1}'.format(istring, os.linesep) |
179 code += 'qRgba({0:d}, {1:d}, {2:d}, {3:d})'.format( |
148 code += '{0}self.trUtf8("{1}"),{2}'.format( |
180 self.sRed.value(), self.sGreen.value(), self.sBlue.value(), |
149 istring, self.eTitle.text(), os.linesep) |
181 self.sAlpha.value()) |
150 code += \ |
182 else: |
151 '{0}QColorDialog.ColorDialogOptions(QColorDialog.ShowAlphaChannel)'\ |
183 code += self.eRGB.text() |
152 .format(istring) |
184 code += '){0}'.format(estring) |
153 code += '){0}'.format(estring) |
185 |
154 |
186 return code |
155 return code |