| 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 |
import sys |
| 26 |
import traceback |
| 27 |
|
| 28 |
|
| 29 |
def stacktraces(): |
| 30 |
code = [] |
| 31 |
for threadId, stack in sys._current_frames().items(): |
| 32 |
code.append("\n# ThreadID: %s" % threadId) |
| 33 |
for filename, lineno, name, line in traceback.extract_stack(stack): |
| 34 |
code.append('File: "%s", line %d, in %s' % (filename, lineno, name)) |
| 35 |
if line: |
| 36 |
code.append(" %s" % (line.strip())) |
| 37 |
return "\n".join(code) |
| 38 |
|
| 39 |
|
| 40 |
from .. import param |
| 41 |
|
| 42 |
|
| 43 |
class Console: |
| 44 |
def __init__(self, parent): |
| 45 |
self.parent = parent |
| 46 |
self.locals = {'main': self.parent, |
| 47 |
'onglets': self.parent.onglets, |
| 48 |
'param': param} |
| 49 |
|
| 50 |
def executer(self, commande): |
| 51 |
"La commande est exécutée dans l'espace de nom du panel." |
| 52 |
commande = commande.strip() |
| 53 |
|
| 54 |
|
| 55 |
if commande[0] == '&': |
| 56 |
commande = 'print(' + commande[1:] + ')' |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
commande = commande.replace("!p.", "panel.") |
| 61 |
|
| 62 |
commande = commande.replace("!c.", "canvas.") |
| 63 |
: |
| 64 |
commande = commande.replace("!f.", "feuille.") |
| 65 |
|
| 66 |
commande = commande.replace("!o.", "objets.") |
| 67 |
commande = commande.replace("!g.", "moteur_graphique.") |
| 68 |
: |
| 69 |
commande = commande.replace("!m.", "main.") |
| 70 |
|
| 71 |
commande = commande.replace("!t", "print(threads)") |
| 72 |
|
| 73 |
if commande in ('quit', 'exit', 'close'): |
| 74 |
self.parent.close() |
| 75 |
return |
| 76 |
elif commande in ('restart', '!!!'): |
| 77 |
self.parent.restart() |
| 78 |
return |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
print("REQUETE CONSOLE [" + self.parent.onglets.onglet_actuel.titre + "]:\n>>> " |
| 84 |
+ commande) |
| 85 |
|
| 86 |
self.locals.update({'panel': self.parent.onglets.onglet_actuel, |
| 87 |
'canvas': self.parent.onglets.onglet_actuel.canvas, |
| 88 |
'feuille': self.parent.onglets.onglet_actuel.feuille_actuelle, |
| 89 |
'threads': stacktraces(), |
| 90 |
}) |
| 91 |
for nom in param.modules: |
| 92 |
if param.modules_actifs[nom]: |
| 93 |
self.locals[nom] = getattr(self.parent.onglets, nom) |
| 94 |
if self.parent.onglets.onglet_actuel.canvas is not None: |
| 95 |
self.locals['objets'] = self.parent.onglets.onglet_actuel.feuille_actuelle.objets |
| 96 |
self.locals['moteur_graphique'] = self.parent.onglets.onglet_actuel.canvas.graph |
| 97 |
exec(commande, self.parent.__dict__, self.locals) |