for i, token in enumerate(self.__tokens):
if isinstance(token, self.MetadataToken):
if start < i:
text = self.get_text(start, i)
dc.TextBackground = background_color
dc.DrawText(text, loc, self.padding)
loc += dc.GetTextExtent(text)[0]
dc.TextBackground = metadata_color
dc.DrawText(token.value, loc, self.padding)
loc += dc.GetTextExtent(token.value)[0]
start = i+1
if start < len(self.__tokens):
text = self.get_text(start)
dc.TextBackground = background_color
dc.DrawText(text, loc, self.padding)
After Change
self.__tokens.insert(index, token)
self.on_token_change()
def OnPaint(self, event):
dc = wx.GCDC(wx.BufferedPaintDC(self))
dc.GraphicsContext.PushState()
try:
dc.BackgroundMode = wx.SOLID
background_color = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)
metadata_color = get_primary_outline_color()
dc.Background = wx.Brush(background_color)
dc.Font = self.Font
dc.Clear()
if self.native_border:
renderer = wx.RendererNative.Get()
style = 0
if self.FindFocus() == self:
style |= wx.CONTROL_FOCUSED | wx.CONTROL_CURRENT
if not self.Enabled:
style |= wx.CONTROL_DISABLED
renderer.DrawTextCtrl(self, dc, (0, 0,
self.ClientSize[0],
self.ClientSize[1]),
style)
dc.SetClippingRect((self.padding, self.padding,
self.ClientSize[0] - 2*self.padding,
self.ClientSize[1] - 2*self.padding))
loc = self.xoffset
for i, token in enumerate(self.__tokens):
if isinstance(token, self.MetadataToken):
dc.TextBackground = metadata_color
text = token.value
else:
text = self.get_text(i, i+1)
dc.TextBackground = background_color
dc.DrawText(text, loc, self.padding)
loc += self.GetTextExtent(text)[0]
finally: