Change Autocomplete background color
-
@prahladmifour said in Change Autocomplete background color:
SCI_CALLTIPUSESTYLE message and (continue reading on the website) we can configure foreground and background color with SCI_CALLTIPSETBACK and SCI_CALLTIPSETFORE
I’m familiar with these messages and already use PythonScript to change the background of calltips, but that is not what I’m asking. I’m asking about Autocomplete.
Cheers.
-
afaik, “no, it can’t be done” :-) at least not from within scintilla
A really dirty hack would be to change the colors system wide like thisand maybe using focusin and focusout event for setting and resetting it.
One other way might be to subclass scintillas window procedure
and react on wm_paint messages. Hmm, now I remember that
there is also a scintilla notification called painted.
Maybe this can be used as well.
Sorry, currently very busy with other stuff but maybe I can find some time
tomorrow and see if this can be achieved using ctypes and python. -
Yeah, hoping to not change the system colors, just do it within Scintilla. If it can’t be done - that’s a valid answer - no need to pursue any further. Your script above - that’s not Python … is it?
I did a bit of exploring, looks like the Notepad++ WindowClass for the autocomplete window is
ListBoxX
:Cheers.
-
Yes, UI Spy reports the same ListboxX. Maybe a custom window
scintilla created. Hmmm … that could mean that there is a wm_paint event.
No, it is not python.
I’m currently trying different new programming languages.
The above one is V.
Is nice - I see a lot of potential but is still in alpha stage at the moment. -
I have already tried - I don’t see how this can be realized in a reasonable way.
The ListBox is NOT a child window of Scintilla, so I am not able to see
when this control is created by subclassing scintilla.
And as a top level window I can only find it after it has been created.
When subclassed, it did not provide WM_PAINT messages.
I can’t think of anything else to try at the moment. -
@Ekopalypse said in Change Autocomplete background color:
I have already tried - I don’t see how this can be realized in a reasonable way.
No worries - thanks for trying. I know we can access some N++ windows like the splitter to move / rotate the Scintilla views so thought this might be similar, but I couldn’t get anywhere (which isn’t saying much). If experienced Python scripters like yourself can’t do it reasonably, I tend to think it can’t be done.
Again, thanks for trying - please don’t waste anymore time on it for me.
Cheers.
-
I tend to believe that there is a solution for every problem.
Unfortunately I have not yet come up with one. :-D -
I came here when I was searching for the opposite.
I edited the ‘Deep Black’ theme and managed the desired effect, which I did not want.
Now, I am unable to switch back to white background in tooltip.
Text compare with the original theme file does not give a clue.
Anybody wants to study or test my theme XML?
-
@nusvar ,
It’s nothing you did. It’s the version of Notepad++.
In 2020, when this conversation originally took place, the autocompletion (and similar) background didn’t follow your theme settings.
After adding Dark Mode in v8.0 in 2021, with more people using a dark theme who didn’t like any part of the UI having light background, v8.4 from 2022 included the new permanent feature to have that autocomplete chooser follow the colors of the active theme for its background. From v8.4 onward, the only way to get a light background in that chooser is to have a light background for your theme. (Or you can go back to using v8.3.3 or earlier, where it’s always a light background no matter what your theme or dark mode.)
-
@nusvar
@PeterJones said in Change Autocomplete background color:From v8.4 onward, the only way to get a light background in that chooser is to have a light background for your theme. (Or you can go back to using v8.3.3 or earlier, where it’s always a light background no matter what your theme or dark mode.)
… OR … use a scripting plugin (PythonScript) to change it (which I do).
Cheers.
-
@PeterJones
Thanks for the great details.
Its so hard for programmers to make everybody happy. :) -
This is kind of necroposting, but I just wanted to share a PythonScript script I made that hopefully makes it reasonably easy to improve the contrast of the autocompletion list selected line.
# https://community.notepad-plus-plus.org/topic/20320/change-autocomplete-background-color/13 from __future__ import print_function from Npp import * def caret_line_and_selection_back(): ''' WORDSTYLESUPDATED notifications don't give anything like style names when they fire so we identify each style by a tuple of (caret line back, selection back) which is hopefully unique to that style. ''' return (editor.getElementColour(ELEMENT.CARET_LINE_BACK), editor.getElementColour(ELEMENT.SELECTION_BACK)) class ALSMCT(object): def __init__(self): self.off = False self.style_list_defaults = {} def reset_autocomp_list_colors(self): caret_selback = caret_line_and_selection_back() list_defaults = self.style_list_defaults.get(caret_selback) if list_defaults and 'back' in list_defaults and 'fore' in list_defaults: list_default_fore = list_defaults['fore'] print('resettting autocompletion list fore to style default %s' % (list_default_fore,)) editor.setElementColour(ELEMENT.LIST_SELECTED, list_defaults['fore']) list_default_back = list_defaults['back'] print('resettting autocompletion list back to style default %s' % (list_default_back,)) editor.setElementColour(ELEMENT.LIST_SELECTED_BACK, list_defaults['back']) else: # couldn't find current style, so just use global defaults print('resetting autocompletion list colors to global defaults') editor.resetElementColour(ELEMENT.LIST_SELECTED) editor.resetElementColour(ELEMENT.LIST_SELECTED_BACK) def on_wordstyles_updated(self, notif): # map current (caret line back, selection back) (which this script doesn't change) # to LIST_SELECTED and LIST_SELECTED_BACK (which it does change) # that way we can later restore the defaults for the current lexer. # Note that editor.resetElementColour just resets to global defaults # NOT the default for the current style caret_selback = caret_line_and_selection_back() list_selected_defaults = { 'fore': editor.getElementColour(ELEMENT.LIST_SELECTED), 'back': editor.getElementColour(ELEMENT.LIST_SELECTED_BACK) } self.style_list_defaults.setdefault(caret_selback, list_selected_defaults) print('default autocompletion list style is %s when caret line back is %s and selection back is %s' % (*caret_selback, list_selected_defaults)) # now change the list styles to caret line styles (if not ALSMCT_OFF) self.on_bufferactivated(notif) def on_bufferactivated(self, notif): if self.off: return caret_line_back = editor.getElementColour(ELEMENT.CARET_LINE_BACK) list_fore = editor.getElementColour(ELEMENT.LIST) # match list fore color to caret line fore color as well to avoid low contrast # (since default LIST_SELECTED may be similar to CARET_LINE_BACK) print('setting autocompletion list back color to %s' % (caret_line_back,)) editor.setElementColour(ELEMENT.LIST_SELECTED_BACK, caret_line_back) print('setting autocompletion list fore color to %s' % (list_fore,)) editor.setElementColour(ELEMENT.LIST_SELECTED, list_fore) if __name__ == '__main__': try: alsmct.off = not alsmct.off # running script multiple times toggles it if alsmct.off: alsmct.reset_autocomp_list_colors() else: alsmct.on_bufferactivated({}) except NameError: alsmct = ALSMCT() alsmct.on_wordstyles_updated(1) notepad.callback(alsmct.on_bufferactivated, [NOTIFICATION.BUFFERACTIVATED]) notepad.callback(alsmct.on_wordstyles_updated, [NOTIFICATION.WORDSTYLESUPDATED])
Running the script changes the autocompletion list style as follows:
- running it an odd number of times (including once) causes the text color for the selected autocompletion line to match the text color for the other autocomp lines, and causes the back color of the selected autocomp line to match the back color of the caret line in the document.
- running it an even number of times resets the style for the selected autocompletion line restores it to the defaults for the theme.
- running it an odd number of times (including once) causes the text color for the selected autocompletion line to match the text color for the other autocomp lines, and causes the back color of the selected autocomp line to match the back color of the caret line in the document.
-