Added color setting tool to the RichTextCtrl sample
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40245 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -335,6 +335,7 @@ class RichTextFrame(wx.Frame):
|
||||
|
||||
r = self.rtc.GetSelectionRange()
|
||||
fontData = wx.FontData()
|
||||
fontData.EnableEffects(False)
|
||||
attr = rt.RichTextAttr()
|
||||
attr.SetFlags(rt.TEXT_ATTR_FONT)
|
||||
if self.rtc.GetStyle(self.rtc.GetInsertionPoint(), attr):
|
||||
@@ -351,6 +352,29 @@ class RichTextFrame(wx.Frame):
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
def OnColour(self, evt):
|
||||
colourData = wx.ColourData()
|
||||
attr = rt.RichTextAttr()
|
||||
attr.SetFlags(rt.TEXT_ATTR_TEXT_COLOUR)
|
||||
if self.rtc.GetStyle(self.rtc.GetInsertionPoint(), attr):
|
||||
colourData.SetColour(attr.GetTextColour())
|
||||
|
||||
dlg = wx.ColourDialog(self, colourData)
|
||||
if dlg.ShowModal() == wx.ID_OK:
|
||||
colourData = dlg.GetColourData()
|
||||
colour = colourData.GetColour()
|
||||
if colour:
|
||||
if not self.rtc.HasSelection():
|
||||
self.rtc.BeginTextColour(colour)
|
||||
else:
|
||||
r = self.rtc.GetSelectionRange()
|
||||
attr.SetFlags(rt.TEXT_ATTR_TEXT_COLOUR)
|
||||
attr.SetTextColour(colour)
|
||||
self.rtc.SetStyle(r, attr)
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
|
||||
def OnUpdateBold(self, evt):
|
||||
evt.Check(self.rtc.IsSelectionBold())
|
||||
|
||||
@@ -498,6 +522,8 @@ class RichTextFrame(wx.Frame):
|
||||
tbar.AddSeparator()
|
||||
doBind( tbar.AddTool(-1, images.get_rt_fontBitmap(),
|
||||
shortHelpString="Font"), self.OnFont)
|
||||
doBind( tbar.AddTool(-1, images.get_rt_colourBitmap(),
|
||||
shortHelpString="Font Colour"), self.OnColour)
|
||||
|
||||
tbar.Realize()
|
||||
|
||||
|
Reference in New Issue
Block a user