Community
    • Login

    Using the PythonScript plugin to automate N++

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    pythonscriptautomation
    53 Posts 6 Posters 5.2k 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.
    • TBugReporterT
      TBugReporter
      last edited by

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

      This discussion has stopped being about “new window” or about “shortcut keys”

      Agreed, and I apologize for not starting a new topic sooner, but …

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

      and really ceased even being about Notepad++.

      … I’d have to disagree with this assessment, since Python (despite being a third-party plugin) seems to be the preferred/default scripting solution for N++.

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

      It seems we’re teaching Python??

      Also agreed, but my questions have been mostly about the interaction of Python with N++, and I don’t know of any better forum to pose such questions.

      I created this thread (with a more appropriate title) as a place for future automation questions to be addressed.

      @Alan-Kilborn said in macro to find/replace in current directory?:

      @rorso

      Cool that that technique can work for you. I had another idea which as “heavier” as it involved using a scripting plugin, so if that wouldn’t work out for you, I’d’ve gone down that road.

      So if and when you go down that road, maybe you can post about it here.

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

        @TBugReporter said in Using the PythonScript plugin to automate N++:

        I’d have to disagree with this assessment, since Python (despite being a third-party plugin) seems to be the preferred/default scripting solution for N++.
        …
        my questions have been mostly about the interaction of Python with N++

        You got the Notepad++ specific info earlier in the thread. If you want to compare and contrast the various methods for “how do I exit a routine or block early without exiting the script”, that it a question that is Notepad++/PythonScript agnostic, and could easily be explored in a Python or general programming forum. Your question might have spawned from an on-topic desire to automate Notepad++, but the specific question is not Notepad++-specific.

        The less an answer references the notepad or editor or console objects, the less it relates to NPP/PythonScript.

        1 Reply Last reply Reply Quote 2
        • TBugReporterT
          TBugReporter
          last edited by TBugReporter

          I’ve been working on my improved shortcut script, and I now have it mostly completed, but now I want to add a GUI dialog like @Ekopalypse suggested here. Unfortunately, running the Samples\Formatter script gives me this:
          Missing Library.png
          I’ve tried reinstalling the PythonScript plugin several times, both as admin and from my normal account, but nothing changes.

          Any clue where I should go from here?
          (“Away” will be a disappointing, but acceptable answer. 😒)

          EkopalypseE 1 Reply Last reply Reply Quote 0
          • EkopalypseE
            Ekopalypse @TBugReporter
            last edited by Ekopalypse

            @TBugReporter

            you need one of the *_TclTk_* from here. Download the proper version and unzip it over the installed one.

            Note: I assume that you are using PythonScript version installed via Plugin Admin.

            TBugReporterT 1 Reply Last reply Reply Quote 3
            • TBugReporterT
              TBugReporter @Ekopalypse
              last edited by

              @Ekopalypse

              Thank you, that fixed it. Apparently, there needs to be a " ‘Plugins to the Plugin’ Admin"! 🙃

              However, it looks like it’ll be quite a while before I understand everything that’s going on in that sample script. Maybe I should publish a version of my Shortcut script without the GUI bells and whistles?

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn @TBugReporter
                last edited by

                @TBugReporter said in Using the PythonScript plugin to automate N++:

                Apparently, there needs to be a " ‘Plugins to the Plugin’ Admin"!

                No. PythonScript plugin author has decided Plugins Admin is only to offer a certain PythonScript package. If you want the extras, you have to go get them manually. It’s not a big deal.

                TBugReporterT 1 Reply Last reply Reply Quote 0
                • TBugReporterT
                  TBugReporter @Alan Kilborn
                  last edited by TBugReporter

                  @Alan-Kilborn said in Using the PythonScript plugin to automate N++:

                  If you want the extras, you have to go get them manually. It’s not a big deal.

                  It is, when that “certain PythonScript package” includes sample scripts that won’t work without these extra parts - and when the documentation link built into the plugin gives no clue that these extra parts exist, nor how to get them.

                  Alan KilbornA EkopalypseE 2 Replies Last reply Reply Quote 0
                  • Alan KilbornA
                    Alan Kilborn @TBugReporter
                    last edited by Alan Kilborn

                    @TBugReporter said in Using the PythonScript plugin to automate N++:

                    that “certain PythonScript package” includes sample scripts that won’t work without these extra parts

                    Create an ISSUE that those sample scripts should be removed, or perhaps that instructions for getting the extra parts should be added as comments at the top of those scripts that need them?

                    the documentation link built into the plugin gives no clue that these extra parts exist, nor how to get them.

                    Documentation can always stand some improvement. Perhaps make that suggestion as well.


                    In general, be careful when considering those sample scripts. They are often added to the project without a lot of vetting.


                    I maintain that it is “not a big deal”. If you’re a “programmer” that wants everything handed to them, or always made “super obvious”, you’re probably not going to get very far. Google and some due diligence type research are your friends.

                    There was one guy a while ago that got all butt hurt that PythonScript 2 was different from PythonScript 3, and felt it was the PythonScript author’s job to better protect him from some of the effects of the differences. We all here kind of laughed at him; it was a “do your research before using, man” kind of thing.


                    Perhaps in the end you won’t like Tcl/Tk anyway; that’s been my feeling. Good luck.

                    1 Reply Last reply Reply Quote 2
                    • EkopalypseE
                      Ekopalypse @TBugReporter
                      last edited by

                      @TBugReporter said in Using the PythonScript plugin to automate N++:

                      It is, when that “certain PythonScript package” includes sample scripts

                      I agree, maybe it should be wrapped in a try block and if it can’t be found a MessageBox is called explaining this.

                      … nor how to get them

                      This is not as easy as it sounds, because there are several ways to set up a “PythonScript environment”. You can use one of the “environments” provided by the plugin, but you can also use the entire Python ecosystem by using a local Python installation along with the plugin. So at a certain point it’s hard to draw the line on what you can/should document.

                      TBugReporterT 2 Replies Last reply Reply Quote 4
                      • TBugReporterT
                        TBugReporter @Ekopalypse
                        last edited by

                        @Ekopalypse said in Using the PythonScript plugin to automate N++:

                        maybe it should be wrapped in a try block and if it can’t be found a MessageBox is called explaining this.

                        You mean like this one? 😉
                        Missing Library.png
                        While this provides useful info, I still think it’s not useful enough. I’ll be posting on @bruderstein’s GitHub, as soon as I decide exactly what to post.

                        Alan KilbornA EkopalypseE 2 Replies Last reply Reply Quote 0
                        • Alan KilbornA
                          Alan Kilborn @TBugReporter
                          last edited by

                          @TBugReporter said in Using the PythonScript plugin to automate N++:

                          While this provides useful info, I still think it’s not useful enough. I’ll be posting on @bruderstein’s GitHub, as soon as I decide exactly what to post.

                          Did you consider my story about the other guy that we laughed at? Do what you will, but think about NOT making yourself into another one of those guys.

                          Aren’t you the person that had the major tizzy because the right-click options on one of the controls in the ShortcutMapper had a couple of extra default options left on it?

                          We do seem to attract those that we call “interesting thinkers”, here…

                          TBugReporterT 1 Reply Last reply Reply Quote 1
                          • TBugReporterT
                            TBugReporter @Alan Kilborn
                            last edited by TBugReporter

                            @Alan-Kilborn said in Using the PythonScript plugin to automate N++:

                            Did you consider my story about the other guy that we laughed at?

                            Not really, because I’m only concerned about how the PythonScript plugin works, and in the process of learning about Python, my research - yes, I did some - revealed that there are some major differences between 2 and 3, but the question of whether the plugin conforms to whatever standards are (or were) established for the Python language - well, that question really didn’t matter to me.

                            Do what you will, but think about NOT making yourself into another one of those guys.

                            It’s hard to know what reaction a question or comment will generate before asking the question or making the comment.

                            Aren’t you the person that had the major tizzy because the right-click options on one of the controls in the ShortcutMapper had a couple of extra default options left on it?

                            I wouldn’t characterize it that way, but yes. Since that, because of that, my opinion of N++ has changed. I used to think of it as a well-polished alternative to the text editor supplied with Windows, but now I see it more as a collection of parts that don’t quite fit together - and that getting them to work together as well as they do is a major accomplishment in itself. That’s not to say that I won’t keep pushing to get it working better, but now I see the rough edges and understand why they’re so rough.

                            Alan KilbornA 1 Reply Last reply Reply Quote 1
                            • EkopalypseE
                              Ekopalypse @TBugReporter
                              last edited by Ekopalypse

                              @TBugReporter

                              You mean like this one?

                              Yes, but no - more in the direction pointing to the package that contains the Tkinter module.

                              1 Reply Last reply Reply Quote 1
                              • Alan KilbornA
                                Alan Kilborn @TBugReporter
                                last edited by Alan Kilborn

                                @TBugReporter said in Using the PythonScript plugin to automate N++:

                                I wouldn’t characterize it that way, but yes.

                                LOL.
                                And thanks for not having an emotional overreaction to my comments the way some people do.


                                because of that, my opinion of N++ has changed. I used to think of it as a well-polished alternative to the text editor supplied with Windows, but now I see it more as a collection of parts that don’t quite fit together - and that getting them to work together as well as they do is a major accomplishment in itself.

                                IMO, Notepad++ is “well polished” but maybe it has enough quirks to keep things interesting. :-)

                                And I don’t know that I’d agree that it is a “collection of parts that don’t quite fit together”. Probably if it were a sack of disjointed parts even the author would’ve given up on it long ago.


                                That’s not to say that I won’t keep pushing to get it working better, but now I see the rough edges and understand why they’re so rough.

                                I don’t know if your “rough” assessment is accurate, but I agree that all any of us (that are interested) can do, is some “pushing”.

                                TBugReporterT 1 Reply Last reply Reply Quote 0
                                • TBugReporterT
                                  TBugReporter @Alan Kilborn
                                  last edited by TBugReporter

                                  @Alan-Kilborn said in Using the PythonScript plugin to automate N++:

                                  thanks for not having an emotional overreaction to my comments the way some people do.

                                  I have experience with people who seem brusque when communicating over the Internet - heck, I am “those people” sometimes.

                                  IMO, Notepad++ is “well polished” but maybe it has enough quirks to keep things interesting. :-)

                                  Okay, I’ll go with “quirky”.


                                  @Ekopalypse:
                                  Two questions for you -

                                  1. I’m trying to import your taskdialog.py script into mine, but I’m getting this error:
                                    File "{...}\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\taskdialog.py", line 400, in show
                                      None if self.checked_verification is None else ctypes.byref(wintypes.INT(self.checked_verification))
                                  ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: expected LP_TASKDIALOGCONFIG instance instead of pointer to TASKDIALOGCONFIG
                                  

                                  Is this a bug in your script, or mine (or both)?

                                  1. I want my dialog to contain a group of checkboxes, but your script seems to only allow for one. What do I need to do to get this? Never mind. I found the Windows documentation for the TaskDialog routines and realized that this is just a slightly fancier version of “Abort, Retry, Ignore?” - IOW, it’s still not configurable enough for what I want, and everybody uses GUI IDEs to build these now, so there’s very little info out there on how to “roll your own”.
                                  EkopalypseE 2 Replies Last reply Reply Quote 0
                                  • EkopalypseE
                                    Ekopalypse @TBugReporter
                                    last edited by

                                    @TBugReporter

                                    Let me check - I will follow up later today.

                                    1 Reply Last reply Reply Quote 0
                                    • EkopalypseE
                                      Ekopalypse @TBugReporter
                                      last edited by

                                      @TBugReporter

                                      I was not able to replicate the error you mentioned, but unfortunately while testing I found a serious problem that could lead to a hanging or even crashing npp. This needs to be investigated further.

                                      1 Reply Last reply Reply Quote 1
                                      • TBugReporterT
                                        TBugReporter @Ekopalypse
                                        last edited by TBugReporter

                                        @Ekopalypse said in Using the PythonScript plugin to automate N++:

                                        maybe it should be wrapped in a try block and if it can’t be found a MessageBox is called explaining this.

                                        @TBugReporter said in Using the PythonScript plugin to automate N++:

                                        You mean like this one? 😉

                                        @Ekopalypse said in Using the PythonScript plugin to automate N++:

                                        Yes, but no - more in the direction pointing to the package that contains the Tkinter module.

                                        I’ve now added code to my script that comes close to doing this. An excerpt:

                                            tk_ok = False
                                            try:                                                        # see if we can do pretty dialogs
                                                import Tkinter as tk
                                                import ttk
                                                import qq                                               # DEBUG:  bogus name to force error triggering
                                                tk_ok = True
                                            except ImportError as e:                                    # if not, tell user
                                                console.show()
                                                user_response = notepad.messageBox(
                                                    (tk_err_msg + e.message
                                                    ), "Missing Library",
                                                    MESSAGEBOXFLAGS.OKCANCEL | MESSAGEBOXFLAGS.ICONWARNING | MB_HELP)
                                                if user_response == MESSAGEBOXFLAGS.RESULTCANCEL:
                                                    print("== RESULTCANCEL loading Tkinter")            # DEBUG
                                                    notepad.runPluginCommand('Python Script', 'Stop Script')
                                        

                                        This produces the following box:
                                        Missing Library.png
                                        Given that MB_HELP isn’t defined as part of PythonScript’s MESSAGEBOXFLAGS, it seems that no one anticipated anyone wanting to add a “Help” button to a MessageBox. Can someone here help me finish this feature for my script? Apparently, the “Help” button sends a message to the parent process, but do I have to add code to listen for and react to this message? Examples I’ve seen for other languages make it seem like I only need to define a URL to be accessed when the button is clicked, but again, I’m having a hard time translating those examples to PythonScript.

                                        (Also, I realize that with this question, I’m again straying away from N++ - for which I was soundly rebuked last time - but I’m thinking that interest in the larger goal of developing a more elegant way to inform PythonScript users of missing libraries might outweigh that concern.)

                                        Alan KilbornA 1 Reply Last reply Reply Quote 0
                                        • Alan KilbornA
                                          Alan Kilborn @TBugReporter
                                          last edited by Alan Kilborn

                                          @TBugReporter said in Using the PythonScript plugin to automate N++:

                                          notepad.runPluginCommand('Python Script', 'Stop Script')

                                          I thought we told you this was a “bad idea”; wasn’t there a discussion of how to “properly” end a script?

                                          I’m again straying away from N++ - for which I was soundly rebuked last time

                                          Nah, you go ahead if you want…

                                          but I’m thinking that interest in the larger goal of developing a more elegant way to inform PythonScript users of missing libraries might outweigh that concern.

                                          IMO, nobody’s concern is all that great, but if you think so then by all means proceed.

                                          Given that MB_HELP isn’t defined as part of PythonScript’s MESSAGEBOXFLAGS, it seems that no one anticipated anyone wanting to add a “Help” button to a MessageBox.

                                          A full-fledged polished programming environment/suite was never really what PS’s designers had in mind. A lot of times Python programs are referred to as “scripts” (which is really a poor thing to do for Python), but here we really are “scripting”, which is intended to be rather lightweight. It’s even in the name of the plugin.

                                          I use it for the power it can give me over the editor, not its UI capabilities, or its “full-fledgeness”.

                                          IMO you are heading down the wrong road, but let’s see where you end up…

                                          TBugReporterT 2 Replies Last reply Reply Quote 0
                                          • TBugReporterT
                                            TBugReporter @Alan Kilborn
                                            last edited by TBugReporter

                                            @Alan-Kilborn said in Using the PythonScript plugin to automate N++:

                                            wasn’t there a discussion of how to “properly” end a script?

                                            Yeah, I just never got around to changing that. (I’m retired, so I tend to do whatever I find entertaining at the moment.)

                                            @TBugReporter said in Using the PythonScript plugin to automate N++:

                                            I’m again straying away from N++ - for which I was soundly rebuked last time

                                            @Alan-Kilborn said in Using the PythonScript plugin to automate N++:

                                            Nah, you go ahead if you want…

                                            nobody’s concern is all that great, but if you think so then by all means proceed.

                                            Okay, perhaps my own enthusiasm for the project may have caused me to misread the temperature of the room - but as I said, I do as I like, and this project has intrigued me. It may end up as just another of my unfinished projects, but for now, I’ll keep banging on it.

                                            IMO you are heading down the wrong road, but let’s see where you end up…

                                            So what do you consider “the right road”? Maybe that road will intrigue me more. 🙂

                                            In software development, nothing is impossible, except making every user happy.
                                            — Notepad++ (@Notepad_plus)

                                            EkopalypseE 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors