From f4e8f51c54f237f8a19da5ee2269890d9016e86e Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 27 Jun 2003 18:39:54 +0000 Subject: [PATCH] Use wxSTC in the demo for displaying the soucre code of the samples. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@21447 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/CHANGES.txt | 9 ++++ wxPython/demo/Main.py | 64 ++++++++++++++++++++++++++--- wxPython/demo/wxStyledTextCtrl_2.py | 4 +- 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/wxPython/CHANGES.txt b/wxPython/CHANGES.txt index a7e6fff454..5d81424b18 100644 --- a/wxPython/CHANGES.txt +++ b/wxPython/CHANGES.txt @@ -2,6 +2,15 @@ CHANGES.txt for wxPython ---------------------------------------------------------------------- +2.4.1.x +------- + +Use wxSTC in the demo for displaying the soucre code of the samples. + + + + + 2.4.1.2 ------- diff --git a/wxPython/demo/Main.py b/wxPython/demo/Main.py index 336d7af3a0..48c8113423 100644 --- a/wxPython/demo/Main.py +++ b/wxPython/demo/Main.py @@ -231,6 +231,59 @@ class MyTP(wx.PyTipProvider): def GetTip(self): return "This is my tip" +#--------------------------------------------------------------------------- +# A class to be used to display source code in the demo. Try using the +# wxSTC in the wxStyledTextCtrl_2 sample first, fall back to wxTextCtrl +# if there is an error, such as the stc module not being present. + +try: + ##raise ImportError + from wx import stc + from wxStyledTextCtrl_2 import PythonSTC + class DemoCodeViewer(PythonSTC): + def __init__(self, parent, ID): + PythonSTC.__init__(self, parent, ID) + self.SetEdgeMode(stc.STC_EDGE_NONE) + self.SetSelBackground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT)) + self.SetSelForeground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)) + + # Some methods to make it compatible with how the wxTextCtrl is used + def SetValue(self, value): + self.SetReadOnly(False) + self.SetText(value) + self.SetReadOnly(True) + + def Clear(self): + self.ClearAll() + + def SetInsertionPoint(self, pos): + self.SetCurrentPos(pos) + + def ShowPosition(self, pos): + self.GotoPos(pos) + + def GetLastPosition(self): + return self.GetLength() + + def GetRange(self, start, end): + return self.GetTextRange(start, end) + + def GetSelection(self): + return self.GetAnchor(), self.GetCurrentPos() + + def SetSelection(self, start, end): + self.SetSelectionStart(start) + self.SetSelectionEnd(end) + + +except ImportError: + class DemoCodeViewer(wx.TextCtrl): + def __init__(self, parent, ID): + wx.TextCtrl.__init__(self, parent, ID, style = + wx.TE_MULTILINE | wx.TE_READONLY | + wx.HSCROLL | wx.TE_RICH2 | wx.TE_NOHIDESEL) + + #--------------------------------------------------------------------------- def opj(path): @@ -387,11 +440,10 @@ class wxPythonDemo(wx.Frame): self.SetOverview(self.overviewText, overview) - # Set up a TextCtrl on the Demo Code Notebook page - self.txt = wx.TextCtrl(self.nb, -1, - style = wx.TE_MULTILINE|wx.TE_READONLY| - wx.HSCROLL|wx.TE_RICH2|wx.TE_NOHIDESEL) + # Set up a notebook page for viewing the source code of each sample + self.txt = DemoCodeViewer(self.nb, -1) self.nb.AddPage(self.txt, "Demo Code") + self.GetDemoFile('Main.py') # Set up a log on the View Log Notebook page @@ -532,7 +584,7 @@ class wxPythonDemo(wx.Frame): try: self.txt.SetValue(open(filename).read()) except IOError: - self.txt.WriteText("Cannot open %s file." % filename) + self.txt.SetValue("Cannot open %s file." % filename) self.txt.SetInsertionPoint(0) self.txt.ShowPosition(0) @@ -588,8 +640,8 @@ class wxPythonDemo(wx.Frame): return else: self.finddlg.Destroy() - self.txt.SetSelection(loc, loc + len(findstring)) self.txt.ShowPosition(loc) + self.txt.SetSelection(loc, loc + len(findstring)) diff --git a/wxPython/demo/wxStyledTextCtrl_2.py b/wxPython/demo/wxStyledTextCtrl_2.py index 302942d0e7..4a5433e14a 100644 --- a/wxPython/demo/wxStyledTextCtrl_2.py +++ b/wxPython/demo/wxStyledTextCtrl_2.py @@ -110,9 +110,9 @@ class PythonSTC(wxStyledTextCtrl): # Number self.StyleSetSpec(wxSTC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces) # String - self.StyleSetSpec(wxSTC_P_STRING, "fore:#7F007F,italic,face:%(times)s,size:%(size)d" % faces) + self.StyleSetSpec(wxSTC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces) # Single quoted string - self.StyleSetSpec(wxSTC_P_CHARACTER, "fore:#7F007F,italic,face:%(times)s,size:%(size)d" % faces) + self.StyleSetSpec(wxSTC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces) # Keyword self.StyleSetSpec(wxSTC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces) # Triple quotes