• Login
Community
  • Login

Hide (or Toggle) Find Results panel with keyboard command

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 3 Posters 4.5k 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.
  • A
    Alan Kilborn
    last edited by Jul 12, 2017, 1:19 PM

    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?

    C 1 Reply Last reply Jul 12, 2017, 10:05 PM Reply Quote 0
    • C
      Claudia Frank @Alan Kilborn
      last edited by Claudia Frank Jul 12, 2017, 10:07 PM Jul 12, 2017, 10:05 PM

      @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

      A 1 Reply Last reply Jul 13, 2017, 12:25 PM Reply Quote 2
      • A
        Alan Kilborn @Claudia Frank
        last edited by Jul 13, 2017, 12:25 PM

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

        C S 2 Replies Last reply Jul 13, 2017, 1:19 PM Reply Quote 0
        • C
          Claudia Frank @Alan Kilborn
          last edited by Jul 13, 2017, 1:19 PM

          @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 Reply Last reply Reply Quote 0
          • S
            Scott Sumner @Alan Kilborn
            last edited by Scott Sumner Jul 13, 2017, 1:55 PM Jul 13, 2017, 1:55 PM

            @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 Reply Last reply Reply Quote 0
            • A Alan Kilborn referenced this topic on Mar 15, 2024, 11:23 AM
            1 out of 5
            • First post
              1/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors