A small report about styling in the stc and other new issues

Hi Robin, Neil? and all.

I had some problems with the styling using wxPy 2.4.0.n. So
I prepared a demo code to show them. Now I migrated to
2.4.1.2, it seems that new issues have arrived. (due to the
introduction of AppendText() ? )

Being a SciTe user, I do not think the problems are due to
Scintilla, but mainly to the Scintilla control --> wxPython
conversion.

Instead of describing each error, I submit a test program
showing them.
Just comment and uncomment some lines to see the effects.
I tried to add some helpfull comment for every issue.
I also tried to serialize the problems (finding some
consistency) but I didn't succeed.

To be short, eol issues are new in 2.4.1.2.

All my tests win98, py 2.2.3, wxpy 2.3.0.2 and wxpy 2.4.1.2

Here the code to play with

···

#-----------------------------------------------------------
--------
# StcForRobin.py
#-----------------------------------------------------------
--------

import wx
from wx import stc
import os
import time
import string

#-----------------------------------------------------------
--------

STYLERED = 1

#ok for 256 colors
STYLEDEFAULTSPEC = "face:Courier
New,size:10,fore:#000000,back:#FFFFFF"
STYLEDEFAULTSPEC1 =
"face:Verdana,size:20,fore:#FF0000,back:#00FFFF"

STYLEREDSPEC = "face:Courier
New,size:10,fore:#FF0000,back:#00FF00"

#-----------------------------------------------------------
--------

#~ def PyStyl(mystc, startpos, endpos):
# see other sources

#-----------------------------------------------------------
--------

class MyStc(stc.StyledTextCtrl):
    def __init__(self, parent, id, pos , size):
        self.parent = parent
        si = self.parent.GetClientSize()
        stc.StyledTextCtrl.__init__(self, parent, id, pos,
si)

        #~ self.SetBackgroundColour(wx.RED)
        # Comment:
        # Does this has an effect? The method
SetBackgroundColour() is
        # a member of stc!. ( dir(self) )
        # Does this method interfere with the styling stuff?

        #some init
        self.SetViewWhiteSpace(True)
        self.SetTabWidth(4)
        self.SetUseTabs(False)
        self.SetCaretForeground("#FF0000")
        self.SetSelBackground(True, "#FFFF00")
        self.UsePopUp(False)
        self.SetViewEOL(True)
        #self.SetEOLMode(stc.STC_EOL_CRLF) #default on win
        #~ self.SetEOLMode(stc.STC_EOL_LF)
        #~ self.SetMarginLeft(5)
        #~ self.NormalMargin = 0
        #~ self.SetMarginType(self.NormalMargin,
stc.STC_MARGIN_SYMBOL)
        #~ self.SetMarginWidth(self.NormalMargin, 0)

        # Is there a way to get the version of the stc
included in
        # the wxPython package? According to the doc, it is
1.52.
        # If no, it would be nice to be able to get this
info
        # programmatically. I did not check it; the some
question
        # applies for wx.html and wx.grid.

        #~ s = 'abc'
        #~ self.AppendText(len(s), s)
        #~ s = 'def'
        #~ self.AppendText(10, s)
        # comment:
        # self.AppendText() was missing in wx pckg 2.4.0.n
        # Now it is included, but it requires 2 arguments:
length and
        # text. Why two arguments and not one like in
AddText() ?
        # What happens if the lenght argument is greater
than len(text)?
        # One, only one 'nul' char is inserted!
        # If length < len(text), the text is displayed with
strange char at the
        #end.

        #~ self.AddText('ab\r\nde')
        #~ print self.GetLength()
        #~ print self.GetEOLMode()
        # comment:
        # This is a new problem in 2.4.1.2
        # After adding this text, the stc displays
        # ab\r
        # ab\r
        # and the caret becomes invisible.
        # No \n after the 1st line and a \r at the end of
the text.
        # GetLength() returns 6
        # This example was working ok in the 2.4.0.n
versions.

        #~ s = 'a\r\nd'
        #~ self.AppendText(len(s), s)
        #~ print self.GetLength()
        # comment:
        # stc displays a\ra\r , yes, a twice

        #~ self.SetEOLMode(stc.STC_EOL_CRLF) #default on win
        #~ self.AddText('abc' + os.linesep)
        #~ print self.GetEOLMode()
        # comment:
        # forcing eol == \r\n
        # GetEOLMode() returns 0 (0 == \r\n)
        # stc display abc\r

        # about the default style (2.4.0.x and 2.4.1.2)
        #----------------------------------------------

        #~ self.AddText('abc\r\ndef')
        #~ print self.GetStyleAt(2)
        # comment:
        #~ # No styles are defined. On my win platform, I
get something like
        # font:MS Sans Serif, size: 10, ... That's ok.
        # GetStyle returns 0

        #~ self.StyleSetSpec(stc.STC_STYLE_DEFAULT,
STYLEDEFAULTSPEC1)
        #~ self.AddText('abc\r\ndef')
        #~ print self.GetStyleAt(2)
        # comment:
        # GetStyleAt() returns 0 and not 32. Why?
        # The STYLEDEFAULTSPEC params are not correctly
applied.
        # Font size: ok, fore colour: not ok, back colour:
the whole
        # stc has a cyan colour.

        #~ self.StyleSetSpec(0, STYLEDEFAULTSPEC1)
        #~ self.AddText('abc\r\ndef')
        #~ print self.GetStyleAt(2)
        # comment:
        # GetStyleAt() returns 0. ok!?
        # All the STYLEDEFAULTSPEC are supported.
        # Ctrl chars like cr, lf have a not size of 20.

        #~ self.StyleSetSpec(stc.STC_STYLE_DEFAULT,
STYLEDEFAULTSPEC1)
        #~ self.StyleClearAll()
        #~ self.AddText('abc\r\ndef')
        #~ print self.GetStyleAt(2)
        # comment:
        #font, size, ctrl char, fore colour: ok
        #back colour not ok

        #~ self.StyleSetSpec(stc.STC_STYLE_DEFAULT,
STYLEDEFAULTSPEC1)
        #~ self.StyleClearAll()
        #~ self.StyleSetSpec(0, STYLEDEFAULTSPEC1)
        #~ self.AddText('abc\r\ndef')
        #~ print self.GetStyleAt(2)
        # comment:
        # GetStyleAt() returns 0. ok.
        #font, size, ctrl char, fore colour: ok
        #back colour not ok, whole control has a cyan colour

        # At this point, I'm asking about the function of
stc.STC_STYLE_DEFAULT
        # stc.STC_STYLE_DEFAULT has (or should have) a value
of 32 decimal.
        # According to the scintilla doc, styles are defined
by the first five
        # bits of the style byte. 32 dec == 100000 bin, this
binary number has
        # 6 bits.

        #setting non default styles (2.4.0.x and 2.4.1.2)
        # (Without considering the new eol issue.
        #------------------------------------------------

        #~ self.StyleSetSpec(0, STYLEDEFAULTSPEC)
        #~ self.StyleSetSpec(1, STYLEREDSPEC)
        #~ self.AddText('abc\r\ndef')
        #~ self.StartStyling(0, 0xff)
        #~ self.SetStyling(3, STYLERED)
        # comment:
        # seems to works ok

        #~ self.StyleSetSpec(0, STYLEDEFAULTSPEC)
        #~ self.StyleSetSpec(stc.STC_STYLE_DEFAULT,
STYLEDEFAULTSPEC)
        #~ self.StyleClearAll()
        #~ self.StyleSetSpec(1, STYLEREDSPEC)
        #~ self.AddText('abc')
        #~ self.StartStyling(0, 0xff)
        #~ self.SetStyling(3, STYLERED)
        # comment:
        # seems to works ok

        #~ self.StyleSetSpec(0, STYLEDEFAULTSPEC)
        #~ self.StyleSetSpec(1, STYLEREDSPEC)
        #~ self.AddText('abc')
        #~ self.GotoPos(0)
        #~ self.StartStyling(0, 0xff)
        #~ self.SetStyling(3, STYLERED)
        #~ print self.GetStyleAt(2)
        #~ self.Refresh()
        # comment:
        # GetStyleAt(2) returns 1 !
        # does not work. Is the styling dependent from the
caret position?
        # interresting: if i press a key (charkey) after
this. Styling will be applied!
        # the same example
        # moving caret by hand or programatically has no
effect.
        # a self.Refresh() command has no effect!

        #~ self.StyleSetSpec(0, STYLEDEFAULTSPEC)
        #~ self.StyleSetSpec(1, STYLEREDSPEC)
        #~ self.AddText('abc')
        #~ self.GotoPos(0)
        #~ self.StartStyling(0, 0xff)
        #~ self.SetStyling(3, STYLERED)
        #~ print self.GetStyleAt(2)
        #~ self.InsertText(0, '')
        # comment:
        # like above. The self.InserText() acts forces a
refresh!
        # Note: this trick may remove/unselect a selected
text
        # Another way to force a refresh:
        #~ self.AddText(' ')
        #~ self.CmdKeyExecute(stc.STC_CMD_DELETEBACK )

        self.StyleSetSpec(0, STYLEDEFAULTSPEC)
        self.StyleSetSpec(1, STYLEREDSPEC)
        self.AddText('abc')
        self.StartStyling(0, 0xff)
        nchar = 3
        self.SetStyling(nchar, STYLERED)
        # comment:
        # the stc contains exactly 3 chars (no eol)
        # if nchar == 3: ok, expected behaviour
        # if nchar == 4: also working, but should not be
possible
        # if nchar == 5: also working, but should not be
possible
        # if nchar == 6: not working. I got the correct
assertion failure:
        # Assertion [lengthSyle == 0 || (lengthStyle > 0 &&
lengthStyle + position < length)]
        # failed at
contrib\stc\contrib\src\stc/scintilla/src/CellBuffer.cxx 755
        # Note on 2.4.1.2 I got the line number 756 instead
of 755 (2.4.0)

        #I stop here for the while

#-----------------------------------------------------------
--------
class MyFrame(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, "StcForRobin",
wx.Point(100,10), wx.Size(500, 400))
        stc = MyStc(self, -1, wx.DefaultPosition,
wx.DefaultSize)
        wx.EVT_CLOSE(self, self.OnCloseWindow)
    def OnCloseWindow(self, event):
        self.Destroy()
#-----------------------------------------------------------
--------
class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1)
        frame.Show(True)
        self.SetTopWindow(frame)
        return True
#-----------------------------------------------------------
--------
def main():
    print 'main is running...'
    app = MyApp(0)
    app.MainLoop()
#-----------------------------------------------------------
--------
if __name__ == "__main__" :
    main()
#eof--------------------------------------------------------
-----------

With the hope that helps a bit. Regards.
Jean-Michel Fauth, Switzerland

Jean-Michel Fauth wrote:

Hi Robin, Neil? and all.

I had some problems with the styling using wxPy 2.4.0.n. So
I prepared a demo code to show them. Now I migrated to
2.4.1.2, it seems that new issues have arrived. (due to the
introduction of AppendText() ? )

Being a SciTe user, I do not think the problems are due to
Scintilla, but mainly to the Scintilla control --> wxPython
conversion.

Instead of describing each error, I submit a test program
showing them.
Just comment and uncomment some lines to see the effects.
I tried to add some helpfull comment for every issue.
I also tried to serialize the problems (finding some
consistency) but I didn't succeed.

To be short, eol issues are new in 2.4.1.2.

All my tests win98, py 2.2.3, wxpy 2.3.0.2 and wxpy 2.4.1.2

Here the code to play with

Please resend your code as an attachment so the lines are not wrapped.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!