| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
import time |
| 22 |
t0 = time.time() |
| •23 |
import sys, os, itertools, traceback, subprocess |
| 24 |
from os.path import dirname, realpath, normpath |
| 25 |
|
| 26 |
e |
| 27 |
EMPLACEMENT = dirname(dirname(realpath(sys._getframe().f_code.co_filename))) |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
os.environ["QT_API"] = "pyqt5" |
| 32 |
|
| 33 |
if getattr(sys, '_launch_geophar', False): |
| 34 |
from .arguments import lire_arguments, traiter_arguments |
| 35 |
|
| 36 |
arguments = lire_arguments() |
| 37 |
|
| 38 |
|
| 39 |
le. |
| 40 |
ent |
| 41 |
|
| 42 |
if not (arguments.script or arguments.lister_modules): |
| 43 |
try: |
| 44 |
from .GUI.app import app, splash |
| 45 |
|
| 46 |
splash_screen = splash(normpath(EMPLACEMENT + '/wxgeometrie/images/logo6-1.png')) |
| 47 |
e. |
| 48 |
|
| 49 |
splash_screen.showMessage('Chargement en cours...') |
| 50 |
print("Démarrage GUI...") |
| 51 |
except ImportError: |
| 52 |
é |
| 53 |
. |
| 54 |
splash_screen = None |
| 55 |
|
| 56 |
parametres_additionnels, arguments, options = traiter_arguments(arguments) |
| 57 |
|
| 58 |
from . import param |
| 59 |
ms |
| 60 |
: |
| 61 |
, |
| 62 |
. |
| 63 |
, |
| 64 |
|
| 65 |
|
| 66 |
from .param import dependances, NOMPROG, NOMPROG2, LOGO, plateforme, GUIlib |
| 67 |
from .pylib.fonctions import path2 |
| 68 |
|
| 69 |
m) |
| 70 |
param.dpi_ecran = (app.desktop().physicalDpiX() + app.desktop().physicalDpiY())/2 |
| 71 |
|
| 72 |
n |
| 73 |
|
| 74 |
|
| 75 |
Qt |
| 76 |
. |
| 77 |
|
| 78 |
|
| 79 |
param.EMPLACEMENT = EMPLACEMENT |
| 80 |
. |
| 81 |
ces |
| 82 |
|
| 83 |
: |
| 84 |
|
| 85 |
h |
| 86 |
|
| 87 |
é. |
| 88 |
param.ID = ID = repr(t0).replace('.','-') |
| 89 |
|
| 90 |
if not options.script: |
| 91 |
app.nom(NOMPROG) |
| 92 |
if param.style_Qt: |
| 93 |
app.setStyle(param.style_Qt) |
| 94 |
app.icone("%/wxgeometrie/images/icone.ico") |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
class SortieTemporaire(list): |
| 112 |
def write(self, chaine): |
| 113 |
self.append(chaine) |
| 114 |
|
| 115 |
|
| 116 |
class SortiesMultiples(object): |
| 117 |
softspace = 0 |
| 118 |
def __init__(self, obligatoires = (), facultatives = ()): |
| 119 |
self.obligatoires = list(obligatoires) |
| 120 |
self.facultatives = list(facultatives) |
| 121 |
self.total = 0 |
| 122 |
|
| 123 |
def write(self, chaine): |
| 124 |
sys.__stdout__.write(chaine) |
| 125 |
|
| 126 |
self.total += len(chaine) |
| 127 |
if self.total - len(chaine) < param.taille_max_log <= self.total: |
| 128 |
chaine = "Sortie saturée !" |
| 129 |
for sortie in self.obligatoires: |
| 130 |
sortie.write(chaine) |
| 131 |
if param.debug: |
| 132 |
for sortie in self.facultatives: |
| 133 |
sortie.write(chaine) |
| 134 |
|
| 135 |
def flush(self): |
| 136 |
for sortie in itertools.chain(self.obligatoires, self.facultatives): |
| 137 |
if hasattr(sortie, 'flush'): |
| 138 |
sortie.flush() |
| 139 |
|
| 140 |
def __del__(self): |
| 141 |
self.close() |
| 142 |
|
| 143 |
def close(self): |
| 144 |
for sortie in self.obligatoires: |
| 145 |
if hasattr(sortie, 'close'): |
| 146 |
sortie.close() |
| 147 |
for sortie in self.facultatives: |
| 148 |
if hasattr(sortie, 'close'): |
| 149 |
sortie.close() |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
for emplacement in param.emplacements.values(): |
| 154 |
emplacement = path2(emplacement) |
| 155 |
try: |
| 156 |
if not os.path.isdir(emplacement): |
| 157 |
os.makedirs(emplacement) |
| 158 |
print('Création du répertoire : ' + emplacement) |
| 159 |
except IOError: |
| 160 |
print("Impossible de créer le répertoire %s !" %emplacement) |
| 161 |
print('%s: %s' % sys.exc_info()[:2]) |
| 162 |
except Exception: |
| 163 |
print('Erreur inattendue lors de la création du répertoire %s.' %emplacement) |
| 164 |
print('%s: %s' % sys.exc_info()[:2]) |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
!) |
| 169 |
. |
| 170 |
|
| 171 |
try: |
| 172 |
sorties = sys.stdout = sys.stderr = SortiesMultiples() |
| 173 |
!) |
| 174 |
sorties.write('') |
| 175 |
except: |
| 176 |
sys.stdout = sys.__stdout__ |
| 177 |
sys.stderr = sys.__stderr__ |
| 178 |
raise |
| 179 |
|
| 180 |
log_filename = path2(param.emplacements['log'] + "/messages.log") |
| 181 |
if param.enregistrer_messages and isinstance(sys.stdout, SortiesMultiples): |
| 182 |
try: |
| 183 |
sys.stdout.facultatives.append(SortieTemporaire()) |
| 184 |
fichier_log = open(log_filename, 'w') |
| 185 |
fichier_log.write(NOMPROG + " version " + param.version + '\n') |
| 186 |
fichier_log.write(time.strftime("%d/%m/%Y - %H:%M:%S") + '\n') |
| 187 |
sys.stdout.obligatoires.append(fichier_log) |
| 188 |
except IOError: |
| 189 |
fichier_log = None |
| 190 |
param.enregistrer_messages = param.historique_log = False |
| 191 |
print(traceback.format_exc()) |
| 192 |
print('Warning: This exception was not raised.') |
| 193 |
else: |
| 194 |
fichier_log = None |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
. |
| 200 |
ée |
| 201 |
eur |
| 202 |
) |
| 203 |
try: |
| 204 |
I |
| 205 |
if param.verbose: |
| 206 |
print('Arguments de la ligne de commande :', parametres_additionnels, arguments) |
| 207 |
if options.script: |
| 208 |
print("--- Mode script activé. ---") |
| 209 |
|
| 210 |
if param.frozen: |
| 211 |
print(sys.path) |
| 212 |
sys.path.extend(('library.zip\\matplotlib', 'library.zip\\' + GUIlib)) |
| 213 |
|
| 214 |
|
| 215 |
def initialiser(): |
| 216 |
from .API.parametres import actualiser_module |
| 217 |
from .pylib import print_error |
| 218 |
from .geolib import contexte |
| 219 |
uel |
| 220 |
path_lock = path2(param.emplacements['session'] + "/lock") |
| 221 |
crash = os.path.isfile(path_lock) |
| 222 |
|
| 223 |
try: |
| 224 |
open(path_lock, 'w').close() |
| 225 |
param.ecriture_possible = True |
| 226 |
except IOError: |
| 227 |
print("Warning: impossible de créer le fichier '%s'." %path_lock) |
| 228 |
param.ecriture_possible = False |
| 229 |
|
| 230 |
t. |
| 231 |
copie = param.__dict__.copy() |
| 232 |
copie.pop("__builtins__", {}) |
| 233 |
setattr(param, "_parametres_par_defaut", copie) |
| 234 |
|
| 235 |
eur. |
| 236 |
s) |
| 237 |
path = path2(param.emplacements['preferences'] + "/parametres.xml") |
| 238 |
try: |
| 239 |
if os.path.exists(path) and param.charger_preferences: |
| 240 |
if param.verbose: |
| 241 |
print("Chargement des préférences...") |
| 242 |
l. |
| 243 |
a_verifier = dict((dicname, getattr(param, dicname)) for dicname in param.a_mettre_a_jour) |
| 244 |
actualiser_module(param, path) |
| 245 |
ur |
| 246 |
|
| 247 |
. |
| 248 |
for dicname in param.a_mettre_a_jour: |
| 249 |
for key, val in a_verifier[dicname].items(): |
| 250 |
getattr(param, dicname).setdefault(key, val) |
| 251 |
: |
| 252 |
for parametre in ('decimales', 'unite_angle', 'tolerance'): |
| 253 |
contexte[parametre] = getattr(param, parametre) |
| 254 |
except: |
| 255 |
sys.excepthook(*sys.exc_info()) |
| 256 |
|
| 257 |
param.__dict__.update(parametres_additionnels) |
| 258 |
|
| 259 |
if options.script: |
| 260 |
from .GUI.mode_script import mode_script |
| 261 |
msg = mode_script(options.input, options.output) |
| 262 |
if msg: |
| 263 |
print(msg) |
| 264 |
|
| 265 |
else: |
| 266 |
ée. |
| 267 |
param._restart = False |
| 268 |
|
| 269 |
from .GUI.fenetre_principale import FenetrePrincipale |
| 270 |
if param.debug: |
| 271 |
print("Temps d'initialisation: %f s" % (time.time() - t0)) |
| 272 |
frame = FenetrePrincipale(app, fichier_log = fichier_log) |
| 273 |
if not param._restart: |
| 274 |
). |
| 275 |
splash_screen.finish(frame) |
| 276 |
if isinstance(sys.stdout, SortiesMultiples): |
| 277 |
if param.debug: |
| 278 |
for msg in sys.stdout.facultatives[0]: |
| 279 |
frame.fenetre_sortie.write(msg) |
| 280 |
sys.stdout.facultatives[0] = frame.fenetre_sortie |
| 281 |
if arguments: |
| 282 |
try: |
| 283 |
for arg in arguments: |
| 284 |
frame.onglets.ouvrir(arg) re |
| 285 |
except: |
| 286 |
print_error() if |
| 287 |
print(arg) |
| 288 |
elif options.restaurer or ((param.auto_restaurer_session or crash) |
| 289 |
and not options.nouveau): |
| 290 |
e. |
| 291 |
n) |
| 292 |
try: |
| 293 |
if crash: |
| 294 |
print(NOMPROG + " n'a pas été fermé correctement.\n" |
| 295 |
"Tentative de restauration de la session en cours...") |
| 296 |
es |
| 297 |
és. |
| 298 |
frame.gestion.charger_session(activer_modules=crash) |
| 299 |
except: |
| 300 |
print("Warning: La session n'a pas pu être restaurée.") |
| 301 |
print_error() |
| 302 |
frame.show() |
| 303 |
if param.debug: |
| 304 |
print('Temps de démarrage: %f s' % (time.time() - t0)) |
| 305 |
app.boucle() |
| 306 |
else: |
| 307 |
|
| 308 |
ues. |
| 309 |
r |
| 310 |
r). |
| 311 |
frame.gestion.fermer() |
| 312 |
sys.stdout = sys.__stdout__ |
| 313 |
sys.stderr = sys.__stderr__ |
| 314 |
sorties.close() |
| 315 |
try: |
| 316 |
os.remove(path_lock) |
| 317 |
except OSError: |
| 318 |
print("Warning: impossible de supprimer %s." % repr(path_lock)) |
| 319 |
if param._restart: |
| 320 |
args = [sys.executable, sys.argv[0], '--restaurer'] |
| 321 |
ée |
| 322 |
ts. |
| 323 |
print("\n=======================") |
| 324 |
print("Redémarrage en cours...") |
| 325 |
print(' '.join(args)) |
| 326 |
print("=======================\n") |
| 327 |
os.execv(sys.executable, args) |
| 328 |
|
| 329 |
except Exception: |
| 330 |
|
| 331 |
" |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
e |
| 337 |
|
| 338 |
me |
| 339 |
|
| 340 |
sys.excepthook(*sys.exc_info()) |
| 341 |
sys.stdout = sys.__stdout__ |
| 342 |
sys.stderr = sys.__stderr__ |
| 343 |
sorties.close() |
| 344 |
sys.exit("Erreur fatale lors de l'initialisation.") |