[wxPython-users] first time using styled text ctrl...
Josiah Carlson
jcarlson at uci.edu
Sat Jul 1 23:15:21 PDT 2006
Jeff Peery <jeffpeery at yahoo.com> wrote:
> hello, I'm for the first time using a styledtxtctrl and I'm not sure exactly how this works. I read the docs but they don't seem to start with 'newbie' basics... nevertheless I managed to get some of the functionality I want. I have a slider bar that I want to slide and as I slide it a length of 5 characters is highlighted in the styled text ctrl.... here is basically what I do now:
>
> def OnDataSliderScroll(self, event):
> # set start of highlighted section, use the slider value
> start = self.DataSlider.GetValue()
> end = start + 5
> # select the region in the styled text ctrl
> self.styledTextCtrl1.SetSelection(start,end)
> self.styledTextCtrl1.SetSelBackground(True, wx.RED)
> self.styledTextCtrl1.SetSelForeground(True, wx.WHITE)
>
> so this is basically what I want to do, but this won't work for me because I have two of these sliders and I want to highlight/select two different regions. I don't think I can select two different regions with two different background colors. so I just need to change the style of a group of text as the user slides the slide bar. I tried something like this but didn't get anywhere:
>
> def OnDataSliderScroll(self, event):
> # create a style that I want to use to highlight a region specified by the slider
> self.styledTextCtrl1.StyleSetSpec(0,'fore:[wx.WHITE],back:[wx.RED]')
> # goto the start of the text that I want to style. the start value depends of the slider value
> start = self.DataSlider.GetValue()
> self.styledTextCtrl1.GotoPos(start)
> # set the style of the 5 characters after the start position, use style '0' that I specified above
> self.styledTextCtrl1.SetStyling(5, 0)
For the future, don't reply to a post and change the subject when
posting about a completely different topic. People who weren't
interested in the parent thread may not reply to your later post.
If you didn't know already, the StyledTextCtrl is a wrapping of the
Scintilla editor control, whose full documentation is available via
scintilla.org, and that provide a sample editor application as SciTE.
Generally speaking, if you want to set styles and have them stick, you
need to use the STC_LEX_CONTAINER lexer, as that will allow you to
manually style everything. If you use /any/ of the other lexers, the
moment your content changes, it is reparsed and you lose your styling.
You can, however, use different indicators regardless of your lexer.
See: http://scintilla.sourceforge.net/ScintillaDoc.html#Indicators
You could use the INDIC_BOX or INDIC_ROUNDBOX, then set the foregrounds
of the two boxes to be different colors. These indicators are usable
regardless of the lexer.
- Josiah
More information about the wxpython-users
mailing list