Community
    • 登入

    Hide (or Toggle) Find Results panel with keyboard command

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    5 貼文 3 Posters 4.7k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • Alan KilbornA
      Alan Kilborn
      最後由 編輯

      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?

      Claudia FrankC 1 條回覆 最後回覆 回覆 引用 0
      • Claudia FrankC
        Claudia Frank @Alan Kilborn
        最後由 Claudia Frank 編輯

        @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

        Alan KilbornA 1 條回覆 最後回覆 回覆 引用 2
        • Alan KilbornA
          Alan Kilborn @Claudia Frank
          最後由 編輯

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

          Claudia FrankC Scott SumnerS 2 條回覆 最後回覆 回覆 引用 0
          • Claudia FrankC
            Claudia Frank @Alan Kilborn
            最後由 編輯

            @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

            1 條回覆 最後回覆 回覆 引用 0
            • Scott SumnerS
              Scott Sumner @Alan Kilborn
              最後由 Scott Sumner 編輯

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

              1 條回覆 最後回覆 回覆 引用 0
              • Alan KilbornA Alan Kilborn referenced this topic on
              • 第一個貼文
                最後的貼文
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors