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
|
import wx.richtext, wx
app = wx.App(0)
frame = wx.Frame(None)
text = 'truc à dire, titre blabla description: blabla'
couleurSpecial = 'red'
motSpeciaux = ('description', 'titre')
listRangeMot = []
#on récupère la position de tous mots spéciaux
for mot in motSpeciaux:
indexMot = text.find(mot)
while indexMot != -1:#tant qu'il y des mots trouvés
listRangeMot.append((indexMot-1, indexMot+len(mot)))
indexMot = text.find(mot, indexMot+1)
richText = wx.richtext.RichTextCtrl(frame, size=(200, 200))
richText.SetEditable(False)#si tu veux que le RichTextCtrl ne soit pas éditable
#le style qui permet de changer de couleur
attr = wx.richtext.TextAttrEx()
attr.SetTextColour(couleurSpecial)
richText.WriteText(text)
for rangeMot in listRangeMot:
richText.SetStyle(rangeMot, attr)
frame.Show()
app.MainLoop() |
Partager