• Login
Community
  • Login

Finding available shortcut keys (originally "Where's the 'New Window' command?")

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
53 Posts 7 Posters 5.8k 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.
  • E
    Ekopalypse @TBugReporter
    last edited by Jan 12, 2023, 10:11 AM

    @TBugReporter

    something like this

    while True:
        result = notepad.messageBox('','', MESSAGEBOXFLAGS.ABORTRETRYIGNORE)
        if result != MESSAGEBOXFLAGS.RESULTRETRY:
            break
    
    A 1 Reply Last reply Jan 12, 2023, 1:51 PM Reply Quote 1
    • A
      Alan Kilborn @Ekopalypse
      last edited by Jan 12, 2023, 1:51 PM

      It boggles the mind that someone would ever think to use the Stop Script menu item, in code, to “bail out”. Just write code that nicely returns, like @Ekopalypse 's main example from earlier. Stop Script should only be run from the menus as a last resort, a “kill my script” kind of thing. And I don’t think I’ve ever had a need to use it.

      T 1 Reply Last reply Jan 12, 2023, 11:42 PM Reply Quote 1
      • T
        TBugReporter @Alan Kilborn
        last edited by Jan 12, 2023, 11:42 PM

        @Ekopalypse said in Finding available shortcut keys (originally “Where’s the ‘New Window’ command?”):

        while True:
            result = notepad.messageBox('','', MESSAGEBOXFLAGS.ABORTRETRYIGNORE)
            if result != MESSAGEBOXFLAGS.RESULTRETRY:
                break
        

        Okay, but where do I put the code that I want it to retry, and where do I put the code that tests whether to show the MessageBox? (without having to duplicate either of those?)

        @Alan-Kilborn said in Finding available shortcut keys (originally “Where’s the ‘New Window’ command?”):

        It boggles the mind

        Yeah, but isn’t it nice to know that your mind can still be boggled? 😁

        Stop Script should only be run from the menus as a last resort

        This was a stopgap measure for me - a placeholder until I could understand my difficulties with scope for variables. I think I got that under control; I just need to test it out and then I’ll do like you said.

        P 1 Reply Last reply Jan 12, 2023, 11:54 PM Reply Quote 0
        • P
          PeterJones @TBugReporter
          last edited by PeterJones Jan 12, 2023, 11:55 PM Jan 12, 2023, 11:54 PM

          @TBugReporter said in Finding available shortcut keys (originally “Where’s the ‘New Window’ command?”):

          Okay, but where do I put the code that I want it to retry

          while True:
              result = notepad.messageBox('','', MESSAGEBOXFLAGS.ABORTRETRYIGNORE)
              if result != MESSAGEBOXFLAGS.RESULTRETRY:
                  break
              # code to redo goes here
          

          or alternately, if it makes more sense to you,

          while True:
              result = notepad.messageBox('','', MESSAGEBOXFLAGS.ABORTRETRYIGNORE)
              if result == MESSAGEBOXFLAGS.RESULTRETRY:
                  # code to redo goes here
              else:
                  break
              # code to redo goes here
          
          T 1 Reply Last reply Jan 13, 2023, 12:48 AM Reply Quote 0
          • T
            TBugReporter @PeterJones
            last edited by Jan 13, 2023, 12:48 AM

            @PeterJones

            It seems to me that that structure won’t do the “code to redo” a first time without first putting up the A/R/I box…?

            P 1 Reply Last reply Jan 13, 2023, 1:15 AM Reply Quote 0
            • P
              PeterJones @TBugReporter
              last edited by Jan 13, 2023, 1:15 AM

              @TBugReporter ,

              It seems to me that that structure won’t do the “code to redo” a first time without first putting up the A/R/I box…?

              Then put the code in whatever order you think is logical for your needs.

              while True:
                 # code to do every loop goes here 
                 result = notepad.messageBox('','', MESSAGEBOXFLAGS.ABORTRETRYIGNORE)
                 if result != MESSAGEBOXFLAGS.RESULTRETRY:
                      break
              
              T 1 Reply Last reply Jan 13, 2023, 7:53 AM Reply Quote 0
              • T
                TBugReporter @PeterJones
                last edited by Jan 13, 2023, 7:53 AM

                @PeterJones
                I’ve now tried this …

                def bailout(msg):
                    print(msg)
                    user_response = notepad.messageBox(msg, "Error", MB_CANCELTRYCONTINUE | MB_ICONWARNING)
                    if user_response == MB_RESULTCANCEL:
                        notepad.runPluginCommand('Python Script', 'Stop Script')
                    else:
                        return user_response
                
                def main():
                    # ...
                    while True:
                        sk_mapper_hwnd = user32.FindWindowW(None, u"Shortcut mapper")
                        if not sk_mapper_hwnd:
                            action_to_take = bailout("Mapper window not found!")
                        if action_to_take != MB_RESULTTRYAGAIN:
                            break
                    # ...
                

                … but that gives me …

                UnboundLocalError: local variable 'action_to_take' referenced before assignment
                

                Where did I go wrong?

                E 1 Reply Last reply Jan 13, 2023, 12:08 PM Reply Quote 0
                • E
                  Ekopalypse @TBugReporter
                  last edited by Jan 13, 2023, 12:08 PM

                  @TBugReporter

                  Scope problem. An if-block introduces a new scope and the variables defined there are only valid within this scope. Either the comparison with MB_RESULTTRYAGAIN is indented to have it in the same scope, or action_to_take must be defined at the same scoping level as the comparison.

                  1 Reply Last reply Reply Quote 1
                  • A
                    Alan Kilborn
                    last edited by Jan 13, 2023, 12:15 PM

                    I don’t know that I like the trend of this thread. It seems we’re teaching Python??

                    1 Reply Last reply Reply Quote 1
                    • M
                      Mendella Replacement @Alan Kilborn
                      last edited by Jan 13, 2023, 4:26 PM

                      @Alan-Kilborn please can i get your attention? I need help pls

                      M 1 Reply Last reply Jan 13, 2023, 4:33 PM Reply Quote 0
                      • M
                        Mendella Replacement @Mendella Replacement
                        last edited by Jan 13, 2023, 4:33 PM

                        @Mendella-Replacement said in Finding available shortcut keys (originally “Where’s the ‘New Window’ command?”):

                        @Alan-Kilborn please can i get your attention? I need help pls

                        P 1 Reply Last reply Jan 13, 2023, 6:03 PM Reply Quote 0
                        • P
                          PeterJones @Mendella Replacement
                          last edited by Jan 13, 2023, 6:03 PM

                          This discussion has stopped being about “new window” or about “shortcut keys”, and really ceased even being about Notepad++. And now it’s even attracting random posts as well.

                          This topic is being locked. If anyone has Noteapd++ related discussion, a new topic can be started quite easily; if you need to, provide a link back to this discussion for reference.

                          1 Reply Last reply Reply Quote 3
                          • P PeterJones locked this topic on Jan 13, 2023, 6:03 PM
                          • A Alan Kilborn referenced this topic on Jan 21, 2023, 11:18 AM
                          51 out of 53
                          • First post
                            51/53
                            Last post
                          The Community of users of the Notepad++ text editor.
                          Powered by NodeBB | Contributors