[wxPython-users] first time using styled text ctrl...

Jeff Peery jeffpeery at yahoo.com
Sun Jul 2 22:58:34 PDT 2006


Ok thanks for the help, I found great docs at 
  
  http://www.yellowbrain.com/stc/styling.html !
  
  so here is what i am doing now:
  
      # slider scroll event
      def OnSliderScroll(self, event):     
  # get slider value
  start = self.Slider.GetValue()
  # get user input length of data
  end = start + 5
  
                         self.styledTextCtrl1.StartStyling(start,wx.stc.STC_INDIC0_MASK)             
  self.styledTextCtrl1.SetStyling(end-start,wx.stc.STC_INDIC0_MASK)
  self.styledTextCtrl1.IndicatorSetStyle(0,wx.stc.STC_INDIC_BOX)             self.styledTextCtrl1.IndicatorSetForeground(0, wx.RED)
  
  
  
  this works well. when I move the slide bar the indicator shows and  moves through my text.  the only problems is that I need to delete  the old indicator so a length of 5 indicator moves. right now if you  slide through all the text in the styledtextctrl there is indicator  everywhere. I fixed this by just clearing the text with a ClearAll(),  then setting the text again before moving the indicator again. this  works but I think this is a bit sloppy? is there a cleaner way to clear  the old indicator so that I don't have to keep clearing and setting all  the text? maybe clearing all the indicator bits in each character? I  tried a StyleClearAll() but this didn't seem to do what I wanted. 
  
  thanks for the help!
  
  Jeff
Josiah Carlson <jcarlson at uci.edu> wrote:  
Jeff Peery  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



 		
---------------------------------
How low will we go? Check out Yahoo! Messenger’s low  PC-to-Phone call rates.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20060702/f614cd29/attachment.htm


More information about the wxpython-users mailing list