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 76 77 78 79 80 81 82 83
| class Static_Variables(object):
flag = False
flag2 = False
pos = 0
display = 1
staticVariables = Static_Variables()
# La classe derive de la class Output, reimplante fonction write()
# ici on peut changer la couleur de print
class GuiOutput(Output):
"""Cette classe permet d'afficher le message sur la fenetre du logiciel"""
def __init__(self, gui_out):
self.gui_out = gui_out
def write(self, text):
if staticVariables.display == 0: #desactive l'affichage
pass
elif staticVariables.display == 1: # affichage normal
self.gui_out.SetDefaultStyle(wx.TextAttr(VarGlobal.myColor))
self.gui_out.AppendText(text)
self.gui_out.SetDefaultStyle(wx.TextAttr("black"))
elif staticVariables.display == 2: #affichage corrigé
self.gui_out.SetDefaultStyle(wx.TextAttr(VarGlobal.myColor))
flag = False
text=text.splitlines(1)
for elem in text:
if elem.find("\b") != -1:
for i in range(elem.count("\b")):
if elem.startswith("\b"):
elem = elem[1:]
remove2 +=1
else:
pos = elem.find("\b")
if pos >0:
if pos < len(elem) and elem[pos+1] != "\b":
if remove == 0:
elem = elem[0:pos-1]+elem[pos+1:len(elem)]
else:
if (pos-remove-1) < 0:
elem = elem[pos+1:len(elem)]+elem[pos-(remove-len(elem[pos+1:len(elem)])+1):pos]
else:
elem = elem[0:pos-remove-1]+elem[pos+1:len(elem)]+elem[pos-(remove-len(elem[pos+1:len(elem)])+1):pos]
remove = 0
else:
remove += 1
elem = elem[:pos] + elem[pos+1:]
if staticVariables.flag:
if staticVariables.flag2:
self.gui_out.Replace(staticVariables.pos,staticVariables.pos+len(elem.replace("\r","").replace("\n","")),elem.replace("\r","").replace("\n",""))
staticVariables.pos = self.gui_out.GetInsertionPoint()
self.gui_out.SetInsertionPointEnd()
if elem.endswith("\r\n") or elem.endswith("\n"):
self.gui_out.AppendText("\n")
staticVariables.flag = False
staticVariables.flag2 = False
if elem.endswith("\r"):
staticVariables.flag = False
staticVariables.flag2 = False
else:
pos = self.gui_out.GetInsertionPoint()
x,y = self.gui_out.PositionToXY(pos)
pos2= self.gui_out.XYToPosition(0, y)
self.gui_out.Replace(pos2,pos2+len(elem.replace("\r","").replace("\n","")),elem.replace("\r","").replace("\n",""))
staticVariables.pos = self.gui_out.GetInsertionPoint()
self.gui_out.SetInsertionPointEnd()
if elem.endswith("\r\n") or elem.endswith("\n"):
self.gui_out.AppendText("\n")
staticVariables.flag = False
staticVariables.flag2 = True
else:
self.gui_out.AppendText(elem.replace("\r",""))
if elem.endswith("\r"):
staticVariables.flag = True
self.gui_out.SetDefaultStyle(wx.TextAttr("black")) |
Partager