wxBug/sciSmudge??: STC SetSyleSpec() whitespace Issue.

This(following line) works as expected. Ugly, hard to read, NonPEP8compliant Unpythonic Zen, because no space after commas.

self.StyleSetSpec(stc.STC_P_COMMENTLINE, ‘fore:#007F00,back:#EAFFE9,face:%(mono)s,size:%(size)d’ % faces)
The next line gets broken at the whitespace in the string.
self.StyleSetSpec(stc.STC_P_COMMENTLINE, ‘fore:#007F00, back:#FF0000,face:%(mono)s,size:%(size)d’ % faces)

Is this a scintilla “needs to parse string better” issue or a wx smudge/adaptation…?

Should I change/make my language theme styles as a OrderedDict such as…
OrderedDict= ([
(stc.STC_P_COMMENTLINE, [‘#007F00’, ‘#EAFFE9’, True, False, True, False, ‘face:%(mono)s’ %faces, ‘size:%(size)d’ %faces]),
etc…
])
Then go through and loop thru the SetStyleFore, SetStyleBack, SetStyleBold, SetStyleItalic, etc… funcs
These STC func()'s seem to work right first off. Seems to be more organized overall, but way more code(chars)/Func calls.

I notice the demo uses the SetStyleSpec() func and is non PEP8 and it breaks with whitespace. Confimed on wx2.9.4.0 msw. Probably also on other vers also…

Is this on a fixit list anywhere…?, or should it be reported to wxTickets or scintilla @sourceforge bugs/issues.

The more I read my own words makes me make a new coding guideline/madlib.

If when strictly trying to follow the zen, and something’s amiss, then “said” try is a bug, even if it is otherwise sometimes ugly working code:
Provide(anarchy)
Else:
it might be some alien language in some other case.
EndElse:
AndIf…

…Yea, it is a ummmverly common observance overall. wx2.8, wx2.9, wxPnx.
-MCow

Here is a CodeSnippet I whipped up.

This seems to work alright…

#!/usr/bin/env python

-- coding: utf-8 --

#-Imports-----------------------------------------------------------------------

#–Python Imports.
from collections import OrderedDict

#–wxPython Imports.
import wx.stc as stc

#–Local Imports.
from src.Constants import faces

gLanguageThemesStylesDict = OrderedDict([
(‘Default’, OrderedDict([
(stc.STC_LEX_PYTHON, OrderedDict([
# (stc.STC_STYLE, [‘Fore#HexSTR’, ‘Back#HexSTR’, BoldBOOL , ItalicBOOL, UnderlineBOOL, EOLBOOL , FacenameSTR, SizeINT, HotspotBOOL]),
(stc.STC_STYLE_DEFAULT, [‘#000000’, ‘#FFFFFF’, False, False, False, False, ‘%(mono)s’ %(faces), faces[‘size’], False]),
(stc.STC_STYLE_LINENUMBER, [‘#000000’, ‘#99AA99’, False, False, False, False, ‘%(mono)s’ %(faces), faces[‘size2’], False]),
(stc.STC_STYLE_BRACELIGHT, [‘#FF0000’, ‘#ACACFF’, True, False, False, False, ‘%(mono)s’ %(faces), faces[‘size’], False]),
(stc.STC_STYLE_BRACEBAD, [‘#000000’, ‘#FF0000’, True, False, False, False, ‘%(mono)s’ %(faces), faces[‘size’], False]),
## (stc.STC_STYLE_CONTROLCHAR, [‘#000000’, ‘#FFFFFF’, False, False, False, False, ‘%(mono)s’ %(faces), faces[‘size’], False]),
(stc.STC_STYLE_INDENTGUIDE, [‘#33FF33’, ‘#FF0000’, False, False, False, False, ‘%(mono)s’ %(faces), faces[‘size’], False]),
(stc.STC_STYLE_CALLTIP, [‘#000000’, ‘#EAFFE9’, False, False, False, False, ‘%(mono)s’ %(faces), faces[‘size’], False]),
##(stc.STC_STYLE_LASTPREDEFINED, [‘#000000’, ‘#FFFFFF’, False, False, False, False, ‘%(mono)s’ %(faces), faces[‘size’], False]),
##(stc.STC_STYLE_MAX, [‘#000000’, ‘#FFFFFF’, False, False, False, False, ‘%(mono)s’ %(faces), faces[‘size’], False]),

    (stc.STC_P_DEFAULT,      ['#000000', '#FFFFFF', False, False, False, False, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_COMMENTLINE,  ['#007F00', '#EAFFE9', False, False, False, False, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_NUMBER,       ['#FF0000', '#FFFFFF', False, False, False, False, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_STRING,       ['#FF8000', '#FFFFFF', False, False, False, False, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_CHARACTER,    ['#FF8000', '#FFFFFF', False, False, False, False, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_WORD,         ['#FF0000', '#FFFFFF', False, False, False, False, '%(mono)s' %(faces), faces['size'],  True]),
    (stc.STC_P_WORD2,        ['#6000FF', '#FFFFFF', False, False, False, False, '%(mono)s' %(faces), faces['size'],  True]),
    (stc.STC_P_TRIPLE,       ['#000000', '#FFF7EE', False, False, False, False, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_TRIPLEDOUBLE, ['#FF8000', '#FFF7EE', False, False, False, False, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_CLASSNAME,    ['#0000FF', '#FFFFFF',  True, False,  True, False, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_DEFNAME,      ['#007F7F', '#FFFFFF',  True, False, False, False, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_OPERATOR,     ['#000000', '#FFFFFF',  True, False, False, False, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_IDENTIFIER,   ['#000000', '#FFFFFF', False, False, False, False, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_COMMENTBLOCK, ['#7F7F7F', '#F8FFF8', False, False, False, False, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_STRINGEOL,    ['#000000', '#E0C0E0', False, False, False,  True, '%(mono)s' %(faces), faces['size'], False]),
    (stc.STC_P_DECORATOR,    ['#000000', '#FFFFFF', False, False, False, False, '%(mono)s' %(faces), faces['size'], False]),

    ])),

(‘OtherTODOTheme’, OrderedDict()),
])

…with this callback code… calling whatever theme style you want…

···

gLTSD = gLanguageThemesStylesDict[‘Default’][self.GetLexer()]
for key, item in six.iteritems(gLTSD):
## print(key, item)
if gLTSD[key][0]:
self.StyleSetForeground(key, gLTSD[key][0])
if gLTSD[key][1]:
self.StyleSetBackground(key, gLTSD[key][1])
self.StyleSetBold(key, gLTSD[key][2])
self.StyleSetItalic(key, gLTSD[key][3])
self.StyleSetUnderline(key, gLTSD[key][4])
self.StyleSetEOLFilled(key, gLTSD[key][5])
self.StyleSetFaceName(key, gLTSD[key][6])
self.StyleSetSize(key, gLTSD[key][7])
self.StyleSetHotSpot(key, gLTSD[key][8])

Metallicow wrote:

This(following line) works as expected. Ugly, hard to read,
NonPEP8compliant Unpythonic Zen, because no space after commas.

    self.StyleSetSpec(stc.STC_P_COMMENTLINE,
    'fore:#007F00,back:#EAFFE9,face:%(mono)s,size:%(size)d' % faces)

The next line gets broken at the whitespace in the string.

    self.StyleSetSpec(stc.STC_P_COMMENTLINE, 'fore:#007F00,
    back:#FF0000,face:%(mono)s,size:%(size)d' % faces)

Is this a scintilla "needs to parse string better" issue or a wx
smudge/adaptation...?

StyleSetSpec is simply a convenience function added in the wx layer and is intended to help you avoid calling up to 8 other APIs (listed below) for every style. This is the first complaint about it in 13 years so changing anything about it is going to be very low on the priority list. If you would rather use some other notation then feel free to implement your own helper/convenience method in a derived class.

             StyleSetBold
             StyleSetItalic
             StyleSetUnderline
             StyleSetEOLFilled
             StyleSetSize
             StyleSetFaceName
             StyleSetForeground
             StyleSetBackground

···

--
Robin Dunn
Software Craftsman

StyleSetSpec is simply a convenience function added in the wx layer and
is intended to help you avoid calling up to 8 other APIs (listed below)
for every style. This is the first complaint about it in 13 years so
changing anything about it is going to be very low on the priority list.
If you would rather use some other notation then feel free to
implement your own helper/convenience method in a derived class.

I think I will continue with my new implementation as a dictionary, and timeit against the new if there ever is a commited fix.

This fixer function below I wrote explains it.

def _StyleSetSpec(styleNum, spec):
“”"
Fix the whitespace breaking issue
before sending to convenience function.
specstring might have been PEP8’d with a whitespace after commas for zen: readability.
“”"
# The face:string might have whitespace and is the only place in the
# string that needs it.
match = re.search(r’face:(.+),‘, s, flags=0)
if match:
facename = match.group()[5:-1]
facenamestripped = facename.replace(’ ‘, ‘’)
else:
facename = ‘’
facenamestripped = ‘’
# Remove all whitespace
fixedSpec = spec.replace(’ ', ‘’).replace(facenamestripped, facename)
# Send Fixed SpecString to convenience function.
self.StyleSetSpec(styleNum, spec=fixedSpec)

Hope that is a simple fix, not sure tho. Is StyleSetSpec is C or python implementation…?

···

On Saturday, September 7, 2013 12:27:40 AM UTC-5, Robin Dunn wrote: