Debian Codegraph @

wxgeometrie/GUI/app.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 ##--------------------------------------##
4 # WxGeometrie #
5 ##--------------------------------------##
6 # WxGeometrie
7 # Dynamic geometry, graph plotter, and more for french mathematic teachers.
8 # Copyright (C) 2005-2013 Nicolas Pourcelot
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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 # La fenètre principale s'enregistre au lancement,
34 # afin qu'on puisse facilement la retrouver.
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 # Pour Mac OS X
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 ##splash.setAttribute(Qt.WA_TranslucentBackground)
98 # XXX: Doesn't work currently: https://bugreports.qt.nokia.com//browse/QTBUG-12820
99 # See also http://developer.qt.nokia.com/wiki/QSplashScreen_replacement_for_semitransparent_images
100 splash.show()
101 return splash
102
103
104 #app.setStyleSheet("background-color:white")
105 #palette = app.palette()
106 #palette.setColor(QPalette.Active, QPalette.Window, QColor('white'))
107 #palette.setColor(QPalette.Inactive, QPalette.Window, QColor('white'))