Hide (or Toggle) Find Results panel with keyboard command



  • So I have my Find Results panel (and Pythonscript console “grouped” with it) at the bottom of my Notepad++ main window (probably pretty typical?). I can press the X with the mouse on this grouping of panels to close it when I want more screen real estate, and it appears back again automagically when I do my next Find-All or Find-in-Files. Life is good.

    However, it would be faster for me to do this closing/hiding (and maybe reopening too) with a keyboard shortcut. Is there one for this functionality, and if not, is it possible to assign one, or otherwise do this?



  • @Alan-Kilborn

    do you really wanna do this?
    Because in order to achieve this you need to send grandpa to bed. ;-)

    ################################################################################# 
    ## close find result and/or python script window
    import ctypes
    from ctypes.wintypes import BOOL, HWND, LPARAM
    
    WNDENUMPROC = ctypes.WINFUNCTYPE(BOOL, HWND,LPARAM)
    
    FindWindow = ctypes.windll.user32.FindWindowW
    GetWindowText = ctypes.windll.user32.GetWindowTextW
    GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
    SendMessage = ctypes.windll.user32.SendMessageW
    EnumChildWindows = ctypes.windll.user32.EnumChildWindows
    GetClassName = ctypes.windll.user32.GetClassNameW
    GetParent = ctypes.windll.user32.GetParent
    
    nppHandle = FindWindow(u'Notepad++', None)
    curr_class = ctypes.create_unicode_buffer(256)
    WM_CLOSE = 0x010
    
    def foreach_window(hwnd, lParam):
        if curr_class[:GetClassName(hwnd, curr_class, 256)] == u'#32770':
            length = GetWindowTextLength(hwnd)
            if length > 0:
                buff = ctypes.create_unicode_buffer(length + 1)
                GetWindowText(hwnd, buff, length + 1)    
                if buff.value in [u'Python Script', u'Find result']:
                    SendMessage(GetParent(GetParent(hwnd)), WM_CLOSE, 0, 0)
                    return False
        return True
        
    EnumChildWindows(nppHandle, WNDENUMPROC(foreach_window), 0)
    

    F7 for find result window and a shortcut mapped to show python script console
    will wake him up again.

    One word of (serious) warning, when calling ctypes function make sure you
    don’t overwrite it accidentally

    Cheers
    Claudia



  • @Claudia-Frank

    I get the joke about grandpa (GetParent() + GetParent()). :-D

    But I don’t understand the “serious warning” – can you elaborate?

    Looks like another winner of a script, Claudia, as it is working fine! Thank you yet again.

    So I notice that the PS console window will get shown again upon a script error (thanks to the functionality from here: https://notepad-plus-plus.org/community/topic/13277/pythonscript-show-console-on-error/). This is nice behavior! :-)

    This got me to wondering how to make hitting a simple “print” statement in a script also re-show a currently hidden PS console window…hmmmm…I find that interesting…



  • @Alan-Kilborn

    Hi Alan,

    warning is a bit extreme, maybe I should have said “info”.
    As you already use some scripts which uses ctypes you need to take care
    that you function definitions like, let’s say

    GetWindowText = ctypes.windll.user32.GetWindowTextW
    

    is used consistently because if a script, which you might run after this one, has something like

    GetWindowText = ctypes.windll.user32.GetWindowTextA
    

    than it will break this script. So I would recommend that you create a, let’s say, winapi.py file,
    put all of this ctypes stuff in it and import it accordingly.

    This got me to wondering how to make hitting a simple “print” statement in a script also re-show a currently hidden PS console window…hmmmm…I find that interesting…

    Redefining a statement doesn’t work but redirecting the stdout output might be a possible way.
    Or maybe try establishing a console.editor callback like charadded. I didn’t try both of them,
    just some thoughts.

    Cheers
    Claudia



  • @Alan-Kilborn said:

    how to make hitting a simple “print” statement in a script also re-show a currently hidden PS console window

    If you don’t mind changing your print statements into print() function calls, you should be able to adapt the technique shown here: https://stackoverflow.com/questions/550470/overload-print-python

    into something like this (put it in startup.py):

    from __future__ import print_function
    import __builtin__
    
    def print(*args, **kwargs):
        notepad.runPluginCommand('Python Script', 'Show Console') 
        return __builtin__.print(*args, **kwargs)
    

    …could be a bit redundant, running the show-console command, even when already shown…


Log in to reply