1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 from python_qt_binding.QtCore import Qt
34 from python_qt_binding.QtGui import QPixmap
35
36 try:
37 from python_qt_binding.QtGui import QCheckBox, QPushButton, QSpacerItem, QSizePolicy, QTextEdit, QDialog
38 from python_qt_binding.QtGui import QDialogButtonBox, QVBoxLayout, QHBoxLayout, QLabel, QStyle, QStyleOption, QApplication
39 except:
40 from python_qt_binding.QtWidgets import QCheckBox, QPushButton, QSpacerItem, QSizePolicy, QTextEdit, QDialog
41 from python_qt_binding.QtWidgets import QDialogButtonBox, QVBoxLayout, QHBoxLayout, QLabel, QStyle, QStyleOption, QApplication
42
43
44 IGNORED_ERRORS = []
48 ''' '''
49
50 - def __init__(self, title, text, detailed_text=""):
51 self.title = title
52 self.value = text
53 self.detailed_text = detailed_text
54
56 return repr(self.text) + ":::" + self.detailed_text
57
60
61 NoIcon = 0
62 Information = 1
63 Warning = 2
64 Critical = 3
65 Question = 4
66
67 NoButton = 0
68 Ok = 1
69 Open = 2
70 Save = 4
71 Cancel = 8
72 Close = 16
73 Discard = 32
74 Apply = 64
75 Reset = 128
76 RestoreDefaults = 256
77 Help = 512
78 SaveAll = 1024
79 Yes = 2048
80 YesToAll = 4096
81 No = 8192
82 NoToAll = 16384
83 Abort = 32768
84 Retry = 65536
85 Ignore = 131072
86 Avoid = 262144
87
88 - def __init__(self, icon, title, text, detailed_text="", buttons=Cancel | Ok, parent=None):
89 QDialog.__init__(self, parent=parent)
90 self.setWindowFlags(self.windowFlags() & ~Qt.WindowTitleHint)
91 self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint & ~Qt.WindowMinimizeButtonHint)
92 self.setObjectName('MessageBox')
93 self._use_checkbox = True
94 self.text = text
95 self.verticalLayout = QVBoxLayout(self)
96 self.verticalLayout.setObjectName("verticalLayout")
97 self.verticalLayout.setContentsMargins(1, 1, 1, 1)
98
99 self.horizontalLayout = QHBoxLayout()
100 self.horizontalLayout.setObjectName("horizontalLayout")
101 self.horizontalLayout.setContentsMargins(1, 1, 1, 1)
102
103 pixmap = None
104 style_option = QStyleOption()
105 if icon == self.NoIcon:
106 pass
107 elif icon == self.Question:
108 pixmap = QApplication.style().standardPixmap(QStyle.SP_MessageBoxQuestion, style_option)
109 elif icon == self.Information:
110 pixmap = QApplication.style().standardPixmap(QStyle.SP_MessageBoxInformation, style_option)
111 elif icon == self.Warning:
112 pixmap = QPixmap(":icons/crystal_clear_warning_56.png")
113 elif icon == self.Critical:
114 pixmap = QApplication.style().standardPixmap(QStyle.SP_MessageBoxCritical, style_option)
115 spacerItem = QSpacerItem(10, 60, QSizePolicy.Minimum, QSizePolicy.Minimum)
116 self.horizontalLayout.addItem(spacerItem)
117 self.icon_label = QLabel()
118 if pixmap is not None:
119 self.icon_label.setPixmap(pixmap)
120 self.icon_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
121 self.horizontalLayout.addWidget(self.icon_label)
122 spacerItem = QSpacerItem(10, 60, QSizePolicy.Minimum, QSizePolicy.Minimum)
123 self.horizontalLayout.addItem(spacerItem)
124
125 self.message_label = QLabel(text)
126 self.message_label.setWordWrap(True)
127 self.message_label.setScaledContents(True)
128 self.message_label.setOpenExternalLinks(True)
129 self.horizontalLayout.addWidget(self.message_label)
130 self.verticalLayout.addLayout(self.horizontalLayout)
131
132
133 self.buttonBox = QDialogButtonBox(self)
134 self.buttonBox.setObjectName("buttonBox")
135 self.buttonBox.setOrientation(Qt.Horizontal)
136
137 self._accept_button = None
138 self._reject_button = None
139 self._buttons = buttons
140 self._create_buttons(buttons)
141 self.buttonBox.accepted.connect(self.accept)
142 self.buttonBox.rejected.connect(self.reject)
143 self.verticalLayout.addWidget(self.buttonBox)
144
145 if detailed_text:
146 self.btn_show_details = QPushButton(self.tr('Details...'))
147 self.btn_show_details.setCheckable(True)
148 self.btn_show_details.setChecked(True)
149 self.btn_show_details.toggled.connect(self.on_toggled_details)
150 self.buttonBox.addButton(self.btn_show_details, QDialogButtonBox.ActionRole)
151
152 self.textEdit = textEdit = QTextEdit(self)
153 textEdit.setObjectName("textEdit")
154 textEdit.setReadOnly(True)
155 textEdit.setText(detailed_text)
156
157 self.verticalLayout.addWidget(self.textEdit)
158 self.resize(480, self.verticalLayout.totalSizeHint().height())
159 buttons_in_box = self.buttonBox.buttons()
160 if buttons_in_box:
161 self.buttonBox.buttons()[0].setFocus()
162
172
182
184 if checked:
185 self.verticalLayout.addWidget(self.textEdit)
186 else:
187 self.verticalLayout.removeWidget(self.textEdit)
188 self.textEdit.setVisible(checked)
189 if not self.isMaximized():
190 self.setMinimumSize(self.verticalLayout.totalMinimumSize())
191 self.resize(self._current_size.width(), self.verticalLayout.totalSizeHint().height())
192
193 @staticmethod
194 - def about(parent, title, text, detailed_text='', buttons=Close):
203
204 @staticmethod
214
215 @staticmethod
225
226 @staticmethod
227 - def warning(parent, title, text, detailed_text='', buttons=Ok):
236
237 @staticmethod
238 - def critical(parent, title, text, detailed_text='', buttons=Ok):
247
249 if not self.isMaximized():
250 self._current_size = event.size()
251
252
253
254
255
261
263 if self.result() == 0:
264 if self._accept_button is not None:
265 self.setResult(self._accept_button)
266 else:
267 self.setResult(1)
268 self.accepted.emit()
269 if self.isModal():
270 self.hide()
271
273 if self.result() == 0:
274 if self._reject_button is not None:
275 self.setResult(self._reject_button)
276 self.rejected.emit()
277 self.hide()
278
282
284 self.setAttribute(Qt.WA_DeleteOnClose, True)
285 QDialog.closeEvent(self, event)
286
287
288
289
290
383
386
389
392
395
398
401
404
407
410
413
416
419
422
425
428
431
434
437
441
450