Community
    • Login

    Change Autocomplete background color

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    14 Posts 6 Posters 2.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Michael VincentM
      Michael Vincent
      last edited by

      I do not see a nice SCI_AUTOC* message to change the autocomplete window background color from the standard white (with black text):

      b1cfb704-a83e-4bf8-90c0-19dd15deffdb-image.png

      I thought it may be using one of the Scintilla STYLES but I can’t find which one (if so). The simple answer may be “no, it can’t be done”, but I’ve seen some magic on this form with ctypes and Win32 API and PythonScript and thought maybe there is a way to change it.

      Any ideas?

      Cheers.

      1 Reply Last reply Reply Quote 0
      • prahladmifourP
        prahladmifour
        last edited by

        Hello,@Michael-Vincent
        Please follow this information, To Change Autocomplete background color

        Thus we need to send the SCI_CALLTIPUSESTYLE message and (continue reading on the website) we can configure foreground and background color with SCI_CALLTIPSETBACK and SCI_CALLTIPSETFORE.

        So to set the color of the call tip by sending messages to the Scintilla editor component using NppExec, you need do this:

        install NppExec with the PluginManager or from PluginCentral. The NppExec zip file contains the dll and some subdirectories. When installing/upgrading into Notepad++ plugin directory, take care that the subdirectories NppExec is created under the plugins directory. The NppExec directory contains the file Scintilla.h which has all the definitions for the possible messages.

        store these lines as a NppExec script (Plugins -> NppExec -> Execute… , enter the following lines and select save, e.g. as SetCallTipStlye):

        // use CALLTIPSTYLE instead DEFAULT
        SCI_SENDMSG SCI_CALLTIPUSESTYLE 0
        // background to black ( 0 )
        SCI_SENDMSG SCI_CALLTIPSETBACK 0
        // foreground to white ( 0xffffff )
        SCI_SENDMSG SCI_CALLTIPSETFORE 0xffffff
        

        execute the script with OK

        Now your calltip Window should be white on black, you might want to adopt the colors by changing the arguments.

        If everything works as you expect, then Plugins -> NppExec -> Advanced Options offers the option Execute this script when Notepad++ starts on the upper right area of the config dialog. Select the script name under which you saved the line

        I hope this information will be useful to you.
        Thank you.

        Michael VincentM 1 Reply Last reply Reply Quote 0
        • Michael VincentM
          Michael Vincent @prahladmifour
          last edited by

          @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.

          EkopalypseE 1 Reply Last reply Reply Quote 1
          • EkopalypseE
            Ekopalypse @Michael Vincent
            last edited by Ekopalypse

            @Michael-Vincent

            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 this

            4c670ed3-6670-4132-8be8-79516d62a39e-image.png

            and 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.

            Michael VincentM 1 Reply Last reply Reply Quote 2
            • Michael VincentM
              Michael Vincent @Ekopalypse
              last edited by

              @Ekopalypse

              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:

              7a768056-810b-4a32-995a-0d23c804ca93-image.png

              Cheers.

              EkopalypseE 2 Replies Last reply Reply Quote 0
              • EkopalypseE
                Ekopalypse @Michael Vincent
                last edited by

                @Michael-Vincent

                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.

                1 Reply Last reply Reply Quote 1
                • EkopalypseE
                  Ekopalypse @Michael Vincent
                  last edited by

                  @Michael-Vincent

                  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.

                  Michael VincentM 1 Reply Last reply Reply Quote 3
                  • Michael VincentM
                    Michael Vincent @Ekopalypse
                    last edited by

                    @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.

                    EkopalypseE 1 Reply Last reply Reply Quote 1
                    • EkopalypseE
                      Ekopalypse @Michael Vincent
                      last edited by

                      @Michael-Vincent

                      I tend to believe that there is a solution for every problem.
                      Unfortunately I have not yet come up with one. :-D

                      1 Reply Last reply Reply Quote 2
                      • nusvarN
                        nusvar
                        last edited by

                        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?
                        20230419_204351_Capture.png

                        PeterJonesP 1 Reply Last reply Reply Quote 0
                        • PeterJonesP
                          PeterJones @nusvar
                          last edited by PeterJones

                          @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.)

                          Michael VincentM nusvarN 2 Replies Last reply Reply Quote 0
                          • Michael VincentM
                            Michael Vincent @PeterJones
                            last edited by

                            @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.

                            1 Reply Last reply Reply Quote 1
                            • nusvarN
                              nusvar @PeterJones
                              last edited by

                              @PeterJones
                              Thanks for the great details.
                              Its so hard for programmers to make everybody happy. :)

                              1 Reply Last reply Reply Quote 0
                              • Mark OlsonM
                                Mark Olson
                                last edited by

                                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.
                                  5d506c34-392c-4ad8-93d9-89975828cb87-image.png
                                • running it an even number of times resets the style for the selected autocompletion line restores it to the defaults for the theme.
                                  4f6af084-acca-46c7-a012-3ae2dbe33f1d-image.png
                                1 Reply Last reply Reply Quote 3
                                • Mark OlsonM Mark Olson referenced this topic on
                                • First post
                                  Last post
                                The Community of users of the Notepad++ text editor.
                                Powered by NodeBB | Contributors