| 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 |
from PyQt5.QtGui import QPalette, QColor, QPixmap, QIcon |
| 26 |
from PyQt5.QtWidgets import QApplication, QSplashScreen |
| 27 |
from PyQt5.QtCore import QLocale, QTranslator, QLibraryInfo, Qt, pyqtSignal |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class App(QApplication): |
| 32 |
|
| 33 |
, |
| 34 |
|
| 35 |
fenetre_principale = None |
| 36 |
|
| 37 |
_print_signal = pyqtSignal(str) |
| 38 |
|
| 39 |
def __init__(self, args=[], **kw): |
| 40 |
QApplication.__init__(self, args) |
| 41 |
locale = QLocale.system().name() |
| 42 |
translator=QTranslator () |
| 43 |
translator.load("qt_" + locale, |
| 44 |
QLibraryInfo.location(QLibraryInfo.TranslationsPath)) |
| 45 |
self.installTranslator(translator) |
| 46 |
self._print_signal.connect(self._print) |
| 47 |
|
| 48 |
self.setAttribute(Qt.AA_DontUseNativeMenuBar) |
| 49 |
|
| 50 |
def boucle(self): |
| 51 |
self.exec_() |
| 52 |
|
| 53 |
def nom(self, nom=''): |
| 54 |
self.setApplicationName(nom) |
| 55 |
|
| 56 |
def icone(self, path): |
| 57 |
from ..pylib.fonctions import path2 |
| 58 |
self.setWindowIcon(QIcon(path2(path))) |
| 59 |
|
| 60 |
def vers_presse_papier(self, texte): |
| 61 |
self.clipboard().setText(texte) |
| 62 |
return True |
| 63 |
|
| 64 |
def safe_print(self, texte): |
| 65 |
"""Thread-safe print(). |
| 66 |
|
| 67 |
En dehors de la thread principale, il faut impérativement utiliser |
| 68 |
cette méthode au lieu de `print()` (notamment parce que print() |
| 69 |
peut provoquer des accès concurrents au fichier de log en écriture). |
| 70 |
""" |
| 71 |
self._print_signal.emit(texte) |
| 72 |
|
| 73 |
def safe_print_error(self): |
| 74 |
"""Thread-safe print_error(). |
| 75 |
|
| 76 |
En dehors de la thread principale, il faut impérativement utiliser |
| 77 |
cette méthode au lieu de `print_error()`. |
| 78 |
""" |
| 79 |
from ..pylib.fonctions import extract_error |
| 80 |
self._print_signal.emit(extract_error()) |
| 81 |
|
| 82 |
def _print(self, texte): |
| 83 |
print(texte) |
| 84 |
|
| 85 |
|
| 86 |
app = App() |
| 87 |
|
| 88 |
white_palette = QPalette() |
| 89 |
white = QColor(Qt.white) |
| 90 |
white_palette.setColor(QPalette.Window, white) |
| 91 |
white_palette.setColor(QPalette.AlternateBase, white) |
| 92 |
|
| 93 |
def splash(path): |
| 94 |
"Create and display the splash screen. Credits: Eli Bendersky ([email protected])" |
| 95 |
splash_pix = QPixmap(path) |
| 96 |
splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint) |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
splash.show() |
| 101 |
return splash |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|