]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/RichTextCtrl.py
Don't use hidden items for size calc (patch 1698314)
[wxWidgets.git] / wxPython / demo / RichTextCtrl.py
index c19c0c7207118e92ad8ab3e732ec0596cfbcf774..5cf36b7f4d5782c7129925e0e99130c1a6c8e500 100644 (file)
@@ -17,7 +17,7 @@ class RichTextFrame(wx.Frame):
         self.rtc = rt.RichTextCtrl(self, style=wx.VSCROLL|wx.HSCROLL|wx.NO_BORDER);
         wx.CallAfter(self.rtc.SetFocus)
 
-
+        self.rtc.Freeze()
         self.rtc.BeginSuppressUndo()
 
         self.rtc.BeginParagraphSpacing(0, 20)
@@ -86,12 +86,12 @@ class RichTextFrame(wx.Frame):
         self.rtc.BeginLeftIndent(100, -40)
         self.rtc.Newline()
 
-        self.rtc.WriteText("It was in January, the most down-trodden month of an Edinburgh winteself.rtc. An attractive woman came into the cafe, which is nothing remarkable.")
+        self.rtc.WriteText("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable.")
         self.rtc.EndLeftIndent()
 
         self.rtc.Newline()
 
-        self.rtc.WriteText("Numbered bullets are possible, again using subindents:")
+        self.rtc.WriteText("Numbered bullets are possible, again using sub-indents:")
 
         self.rtc.BeginNumberedBullet(1, 100, 60)
         self.rtc.Newline()
@@ -172,7 +172,8 @@ class RichTextFrame(wx.Frame):
         self.rtc.EndParagraphSpacing()
 
         self.rtc.EndSuppressUndo()
-
+        self.rtc.Thaw()
+        
 
     def OnFileOpen(self, evt):
         # TODO: Use RichTextBuffer.GetExtWildcard to get the wildcard string
@@ -197,12 +198,13 @@ class RichTextFrame(wx.Frame):
         # TODO: Use RichTextBuffer.GetExtWildcard to get the wildcard string
         dlg = wx.FileDialog(self, "Choose a filename",
                             wildcard="All files (*.*)|*.*",
-                            style=wx.OPEN)
+                            style=wx.SAVE)
         if dlg.ShowModal() == wx.ID_OK:
             path = dlg.GetPath()
             if path:
                 self.rtc.SaveFile(path)
-
+        dlg.Destroy()
+        
                 
     def OnFileViewHTML(self, evt): pass
 
@@ -335,6 +337,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 +354,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 +524,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()