-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathmsg.py
More file actions
75 lines (61 loc) · 2.21 KB
/
Copy pathmsg.py
File metadata and controls
75 lines (61 loc) · 2.21 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
import logging
import sys
from typing import Optional
from qtpy.QtWidgets import QApplication, QMessageBox, QWidget
def _msgbox(
parent: Optional[QWidget], title: str, text: str, detailed_text: str = ""
) -> QMessageBox:
msgbox = QMessageBox(parent)
if sys.platform == "darwin":
# Window titles are ignored for macOS "Alerts"; use setText() instead.
# See https://doc.qt.io/qt-5/qmessagebox.html#the-property-based-api
msgbox.setText(title)
msgbox.setInformativeText(text)
else:
msgbox.setWindowTitle(title)
msgbox.setText(text)
msgbox.setDetailedText(detailed_text)
return msgbox
def info(
parent: Optional[QWidget], title: str, text: str, detailed_text: str = ""
) -> Optional[int]:
logging.info("%s: %s %s", title, text, detailed_text)
if not QApplication.instance():
return None
msgbox = _msgbox(parent, title, text)
msgbox.setIcon(QMessageBox.Information)
return msgbox.exec_()
def question(
parent: Optional[QWidget], title: str, text: str
) -> Optional[bool]:
if not QApplication.instance():
return None
msgbox = _msgbox(parent, title, text)
msgbox.setIcon(QMessageBox.Question)
msgbox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
msgbox.setDefaultButton(QMessageBox.Yes)
if msgbox.exec_() == QMessageBox.Yes:
return True
return False
def error(
parent: Optional[QWidget], title: str, text: str, detailed_text: str = ""
) -> Optional[int]:
logging.error("%s: %s %s", title, text, detailed_text)
if not QApplication.instance():
return None
msgbox = _msgbox(parent, title, text, detailed_text)
msgbox.setIcon(QMessageBox.Critical)
return msgbox.exec_()
def critical(title: str, text: str, detailed_text: str = "") -> None:
logging.critical("%s: %s %s", title, text, detailed_text)
if QApplication.instance():
msgbox = _msgbox(None, title, text, detailed_text)
msgbox.setIcon(QMessageBox.Critical)
msgbox.exec_()
from twisted.internet import reactor
from twisted.internet.error import ReactorNotRunning
try:
reactor.stop() # type: ignore
except ReactorNotRunning:
pass