wxpython richtextctrl con stikethrough
-
23-12-2019 - |
Domanda
Voglio impostare il testo con Strike-through in RichTextCtrl
di wxPython
.Ma non è stato possibile trovare alcun metodo come BeginStrikethrough
o SetStrikethrough
.
È possibile applicare Strike-through in RichTextCtrl
?Come?
Modifica 1:
Font
con bandiera Strike-through utilizzata con BeginFont
e EndFont
non dando effetto Strike-through
import wx
import wx.richtext as rt
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, 1, 'Testing strike-through')
rtc = rt.RichTextCtrl(self, -1)
rtc.WriteText("normal text")
rtc.Newline()
font = wx.FFont(12, wx.FONTFAMILY_DEFAULT, face='Tahoma', flags=wx.FONTFLAG_STRIKETHROUGH)
rtc.BeginFont(font)
rtc.WriteText("This is strike-through")
rtc.EndFont()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()
.
Uscita:
Soluzione
- .
-
È possibile utilizzare
font.SetStrikethrough(True)
conwxpython2.9.4 or higher
, fare riferimento a Questo link -
altrimenti: utilizzare
font.SetNativeFontInfoFromString(str)
per impostare il flag con la descrizione delle informazioni native.
Si prega di controllare la seguente stringa per vedere la differenza, testato solo in Windows:
Desc senza uno stikethrough: 0; -16; 0; 0; 0; 400; 0; 0; 0
; 1; 0; 0; 2; 32; Tahoma
Desc con Strikethrough: 0; -16; 0; 0; 0; 400; 0; 0; 1
; 1; 0; 0; 2; 32; Tahoma
Codice:
import wx
import wx.richtext as rt
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, 1, 'Testing strike-through')
rtc = rt.RichTextCtrl(self, -1)
rtc.WriteText("normal text")
rtc.Newline()
font = wx.FFont(12, wx.FONTFAMILY_DEFAULT, face='Tahoma', flags=wx.FONTFLAG_STRIKETHROUGH)
info = font.GetNativeFontInfoDesc()
info = self.setFontInfoStrikethrough(info)
font.SetNativeFontInfoFromString(info)
rtc.BeginFont(font)
rtc.WriteText("This is strike-through")
rtc.EndFont()
def setFontInfoStrikethrough(self, info):
print "orig:", info
info = info.split(";")
info[8] = r'1'
info = ";".join(info)
print "new :",info
return info
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()
.Altri suggerimenti
È possibile utilizzare un effetto testo, funziona anche con wxpython 2.8.12:
style = rt.TextAttrEx()
style.SetFlags(rt.TEXT_ATTR_EFFECTS)
style.SetTextEffects(rt.TEXT_ATTR_EFFECT_STRIKETHROUGH)
style.SetTextEffectFlags(rt.TEXT_ATTR_EFFECT_STRIKETHROUGH)
rtc.BeginStyle(style)
rtc.WriteText("This is strike-through")
rtc.EndStyle()
.
(testato su Linux)