Community
    • Login

    Python 3 and Python scripts plugin

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    24 Posts 7 Posters 18.7k 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.
    • Bill WinderB
      Bill Winder
      last edited by Bill Winder

      Python 3, Python scrips plugin

      I would like to use python 3 in Npp, especially with the python Script plugin. I know how to run script in Py3, but I the plugin allows for transferring the contents of the editor to the script and output to the console.

      Is there a Npp py3 version? Or can I configure the plugin?

      Claudia FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank @Bill Winder
        last edited by

        @Bill-Winder

        No, but you can use NppExec plugin instead.
        Download and install and configure your run command like

        python3 -u "$(FULL_CURRENT_PATH)"
        

        $(FULL_CURRENT_PATH) gets automatically replaced with the correct path of the current
        active and saved document.

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 0
        • Bill WinderB
          Bill Winder
          last edited by

          Yes, thanks! Unfortunately, nppexec doesn’t seem to have access to npp items, such as the editor content. In order to manipulate editor content, one would have to save the tab, then modify the file, the reload. At least, that’s the only way to replicate editor.getText() function I have found.

          Scott SumnerS Claudia FrankC 2 Replies Last reply Reply Quote 0
          • Scott SumnerS
            Scott Sumner @Bill Winder
            last edited by

            @Bill-Winder

            Is it really that important to be able to execute unsaved Python code? What’s the point?

            1 Reply Last reply Reply Quote 0
            • Claudia FrankC
              Claudia Frank @Bill Winder
              last edited by Claudia Frank

              @Bill-Winder

              you can use NppExecs sci_sendmsg to execute scintilla messages
              but of course it isn’t that flexible as python script.

              Maybe you can explain the exact use case?

              Cheers
              Claudia

              1 Reply Last reply Reply Quote 0
              • Bill WinderB
                Bill Winder
                last edited by

                This could seem a bit … lazy, but I want to paste something from an Internet page into a tab and then transform it directly by clicking on a pythonscript button. I was trying to avoid the extra step of deciding on a name for the pasted text, saving it somewhere, then retrieving it with nppexec. But, yes, it’s a tweak.

                And then it became: What!??? pythonscript can only use 2.7? Why?

                Scott SumnerS dailD 2 Replies Last reply Reply Quote 0
                • Scott SumnerS
                  Scott Sumner @Bill Winder
                  last edited by

                  @Bill-Winder

                  Okay…so copy text from anywhere and put it in a “new” tab. Then run a Pythonscript (via button, menu, keycombo) that acts upon the text in the document tab using the editor object commands Pythonscript provides. You don’t have to save the tab to a file to operate upon its text. Why involve nppexec at all?

                  And then it became: What!??? pythonscript can only use 2.7? Why?

                  Yea…so I don’t get this… Is there some huge advantage that Python3 would give this purpose (scripting) over 2.7? I certainly don’t see what that would be but I am looking forward to being enlightened.

                  1 Reply Last reply Reply Quote 0
                  • Bill WinderB
                    Bill Winder
                    last edited by

                    I will be pasting French text, with accented characters. After struggling with encoding for some time in 2.7 (writing and reading to Windows in utf-8, reading sometimes from ansi, the locale setting), I finally threw in the towel and moved to 3. The encoding waters are much calmer.

                    I can write
                    with open(tempHtml,“w”, encoding=“utf8”) as f:
                    f.write(message)

                    I’m sure something equivalent can be done in 2.7, but 3 handles unicode in a much simpler way. That turns out to be important if you are constantly going from ansi to utf-8 (with or without BOM!).

                    In short, like any language, or software version, once you have set up shop there, you don’t want to have to switch, n’est-ce pas? (The looooong reason is here: https://docs.python.org/3/howto/unicode.html)

                    Now, no more (or less): ‘ascii’ codec can’t encode character ‘\ua000’ in
                    position 0: ordinal not in range(128)

                    1 Reply Last reply Reply Quote 0
                    • chcgC
                      chcg
                      last edited by

                      Latest version of https://sourceforge.net/projects/npppythonscript/files/ is from 2014-09-27 and python 3 was not so popular at that time.

                      Bill WinderB 1 Reply Last reply Reply Quote 0
                      • Bill WinderB
                        Bill Winder @chcg
                        last edited by

                        @chcg I wonder whether six would allow pyscript to transition to 3. …I have never used six, so I don’t know what I’m asking! (for the moment, npp is pretty restrictive: a 3 installation won’t allow pyscript to be installed…)

                        Scott SumnerS 1 Reply Last reply Reply Quote 0
                        • guy038G
                          guy038
                          last edited by guy038

                          Hi, @scott-sumner, and All,

                          Here are three links, on that eternal question : Python 2.x or Python 3.x !

                          The first one is a very interesting article ! See also the comments. As for the third one, it seems more code-oriented.

                          Probably, you are already aware of all that stuff, but who knows ?

                          http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html

                          https://wiki.python.org/moin/Python2orPython3

                          https://docs.python.org/3/whatsnew/3.0.html

                          I wish you good reading !

                          Cheers,

                          guy038

                          1 Reply Last reply Reply Quote 0
                          • Scott SumnerS
                            Scott Sumner @Bill Winder
                            last edited by

                            @Scott-Sumner said:

                            I am looking forward to being enlightened

                            And I am enlightened…to your need… Yes, this is one area where Python3 is advantageous over Python2. Fortunately, for myself, I don’t encounter the unicode need very often. Back to the why of Python2 for the Pythonscript plugin, I believe that there were some issues with Scintilla interaction which necessitated (at the time) using Python2 byte-strings versus Python3 unicode strings. I’m sure you can read about all the details of the design decisions on the old Pythonscript Soucreforge forums if you’d like…

                            1 Reply Last reply Reply Quote 1
                            • dailD
                              dail @Bill Winder
                              last edited by dail

                              @Bill-Winder said:

                              And then it became: What!??? pythonscript can only use 2.7? Why?

                              @Scott-Sumner said:

                              I’m sure you can read about all the details of the design decisions on the old Pythonscript Soucreforge forums if you’d like…

                              Discussion from a few years ago which discusses some of the hurdles switching from v2 to v3: https://sourceforge.net/p/npppythonscript/discussion/1188885/thread/cf066585/

                              Bill WinderB 1 Reply Last reply Reply Quote 2
                              • Bill WinderB
                                Bill Winder @dail
                                last edited by

                                @dail Wow! Hairy!

                                I do encounter just that problem in my normal use of npp. I can paste in è or ã and it generally works fine. But when I open or paste in certain texts (like phonetic transcription from espeak), I get o~ where I should get õ. Npp interprets some accent encoding as two characters, not one (works fine here):

                                la diskysjˈɔ̃ fˈy syspɑ̃dˈy pɑ̃dˈɑ̃ lə ʁˈɔbʁ
                                mɛ bjɛ̃tˈoˈandʁuː styˈaʁ la ʁəpʁənˈɛ

                                I have found no way to fix it by shifting the encoding. (Jedit does the same thing…, but notepad does not.)

                                Claudia FrankC 1 Reply Last reply Reply Quote 0
                                • Claudia FrankC
                                  Claudia Frank @Bill Winder
                                  last edited by

                                  @Bill-Winder said:

                                  la diskysjˈɔ̃ fˈy syspɑ̃dˈy pɑ̃dˈɑ̃ lə ʁˈɔbʁ
                                  mɛ bjɛ̃tˈoˈandʁuː styˈaʁ la ʁəpʁənˈɛ

                                  make sure that the font you use is capable of displaying needed symbols

                                  Cheers
                                  Claudia

                                  Bill WinderB 1 Reply Last reply Reply Quote 3
                                  • Bill WinderB
                                    Bill Winder @Claudia Frank
                                    last edited by

                                    @Claudia-Frank Thanks Claudia! – that fixed it, the moment I checked “enable global font”.

                                    Thanks! (It’s been bugging me…for a long time…)

                                    1 Reply Last reply Reply Quote 1
                                    • Vitaliy DovganV
                                      Vitaliy Dovgan
                                      last edited by

                                      Here is one of possible ways to get the text from an unsaved file tab in NppExec to allow further processing of the text:

                                      // temporary file name
                                      set local tmpfile = $(SYS.TEMP)\text.txt
                                      // current selection
                                      sci_sendmsg SCI_GETSELECTIONSTART
                                      set local selStart = $(MSG_RESULT)
                                      sci_sendmsg SCI_GETSELECTIONEND
                                      set local selEnd = $(MSG_RESULT)
                                      // select all the text and save it
                                      sci_sendmsg SCI_SELECTALL
                                      sel_saveto "$(tmpfile)"
                                      // restore the selection
                                      sci_sendmsg SCI_SETSELECTIONSTART $(selStart)
                                      sci_sendmsg SCI_SETSELECTIONEND $(selEnd)
                                      // now it's time to process the tmpfile...
                                      
                                      1 Reply Last reply Reply Quote 1
                                      • Vitaliy DovganV
                                        Vitaliy Dovgan
                                        last edited by

                                        Here is more “advanced” version that avoids visible selection change:

                                        // temporary file name
                                        set local tmpfile = $(SYS.TEMP)\text.txt
                                        // disable redrawing
                                        sci_sendmsg 0x000B 0 // WM_SETREDRAW FALSE
                                        // current selection
                                        sci_sendmsg SCI_GETSELECTIONSTART
                                        set local selStart = $(MSG_RESULT)
                                        sci_sendmsg SCI_GETSELECTIONEND
                                        set local selEnd = $(MSG_RESULT)
                                        // select all the text and save it
                                        sci_sendmsg SCI_SELECTALL
                                        sel_saveto "$(tmpfile)"
                                        // restore the selection
                                        sci_sendmsg SCI_SETSELECTIONSTART $(selStart)
                                        sci_sendmsg SCI_SETSELECTIONEND $(selEnd)
                                        // enable redrawing
                                        sci_sendmsg 0x000B 1 // WM_SETREDRAW TRUE
                                        // now it's time to process the tmpfile...
                                        
                                        1 Reply Last reply Reply Quote 1
                                        • Vitaliy DovganV
                                          Vitaliy Dovgan
                                          last edited by

                                          NppExec v0.6 beta 1 will introduce new command TEXT_SAVETO and TEXT_LOADFROM that will work with the whole current text. Apart from that, these commands will be similar to SEL_SAVETO and SEL_LOADFROM.

                                          Bill WinderB 1 Reply Last reply Reply Quote 1
                                          • guy038G
                                            guy038
                                            last edited by guy038

                                            Hello, @bill-winder, and All,

                                            I’m quite late, but I had have to update my list of fonts and to do some tests, in Notepad++, first ;-))

                                            So, Bill, here is below, a list of Unicode fonts which can, correctly, display your text example :

                                            la diskysjˈɔ̃ fˈy syspɑ̃dˈy pɑ̃dˈɑ̃ lə ʁˈɔbʁ
                                            mɛ bjɛ̃tˈoˈandʁuː styˈaʁ la ʁəpʁənˈɛ

                                            • The first table concerns Monospaced fonts, where all characters have the same width

                                            • The second table concerns Proportional fonts, with variable width


                                            Notes :

                                            • The Unicode number of code-points, handled by the font, is located in the Glyphs column

                                            • The different fonts are sorted out by increasing number of their glyphs

                                            • The default regular weight, only, of each font, is listed. The other weights ( Bold, Italic… ) are absent of the tables, below

                                            • The Lucida Sans Unicode is certainly already installed on your configuation ( v5.00 or higher )

                                            • The Segoe UI family font is probably installed, too ( v5.28 or higher )

                                            • For the Ioveska and Ioveska Slab fonts, read very carefully the README.md part, scrolling downwards, because these fonts are highly configurable ! Refer to :

                                            https://github.com/be5invis/Iosevka

                                            • You may also consult this valuable article, Large, multi-script Unicode fonts for Windows computers, at :

                                            http://www.alanwood.net/unicode/fonts.html


                                            •------------------------•------------•--------•-----------------------------------------------------------------------------------•
                                            |  MONOSPACED Font Name  |   Version  | Glyphs |                                Web Site Link                                      |
                                            •------------------------•------------•--------•-----------------------------------------------------------------------------------•
                                            | Linux Libertine Mono   |   v5.17    |  1,021 | http://www.linuxlibertine.org                                                     |
                                            | SourceCodePro          |   v2.030   |  1,585 | https://github.com/adobe-fonts/source-code-pro/releases/tag/2.030R-ro%2F1.050R-it |
                                            | DejaVu Sans Mono       |   v2.37    |  3,377 | https://dejavu-fonts.github.io/Download.html                                      |
                                            |                        |            |        |                                                                                   |
                                            | Iosevka                |   v1.14.0  |  3,654 | https://github.com/be5invis/Iosevka/releases                                      |
                                            | Iosevka Slab           |   v1.14.0  |  3,654 | https://github.com/be5invis/Iosevka/releases                                      |
                                            |                        |            |        |                                                                                   |
                                            | FreeMono               | v0412.2268 |  4,177 | http://ftp.gnu.org/gnu/freefont/freefont-ttf-20120503.zip                         |
                                            •------------------------•------------•--------•-----------------------------------------------------------------------------------•
                                            
                                            •------------------------•------------•--------•-----------------------------------------------------------------------------------•
                                            | PROPORTIONAL Font Name |   Version  | Glyphs |                                Web Site Link                                      |
                                            •------------------------•------------•--------•-----------------------------------------------------------------------------------•
                                            | Lucida Sans Unicode    |   v2.00    |  1,776 | https://fr.ffonts.net/Lucida-Sans-Unicode.font.zip                                |
                                            | Lucida Sans Unicode    |   v5.00    |  1,779 | Usually installed in Windows 8 and higher                                         |
                                            |                        |            |        |                                                                                   |
                                            | Linux Biolinum         |   v1.1.8   |  2,403 | http://www.linuxlibertine.org                                                     |
                                            | Linux Libertine        |   v5.3.0   |  2,676 | http://www.linuxlibertine.org                                                     |
                                            |                        |            |        |                                                                                   |
                                            | SegoeUI                |   v5.05    |  2,901 | https://github.com/KingRider/frontcom/tree/master/css/fonts                       |
                                            | SegoeUI                |   v5.28    |  4,516 | Usually installed in Windows 8 and higher                                         |
                                            |                        |            |        |                                                                                   |
                                            | Junicode               |   v0.78    |  3,286 | http://sourceforge.net/projects/junicode                                          |
                                            |                        |            |        |                                                                                   |
                                            | DejaVuSerif            |   v2.37    |  3,528 | https://dejavu-fonts.github.io/Download.html                                      |
                                            | DejaVuSans             |   v2.37    |  6,253 | https://dejavu-fonts.github.io/Download.html                                      |
                                            |                        |            |        |                                                                                   |
                                            | FreeIdgSerif           |   v1.52    |  6,256 | https://en.m.fontke.com/font/10352047/download/                                   |
                                            |                        |            |        |                                                                                   |
                                            | FreeSans               | v0412.2268 |  6,272 | http://ftp.gnu.org/gnu/freefont/freefont-ttf-20120503.zip                         |
                                            | FreeSerif              | v0412.2263 | 10,538 | http://ftp.gnu.org/gnu/freefont/freefont-ttf-20120503.zip                         |
                                            |                        |            |        |                                                                                   |
                                            | Quivira                |   v4.1     | 10,486 | http://www.quivira-font.com                                                       |
                                            |                        |            |        |                                                                                   |
                                            | Arial Unicode MS       |   v1.01    | 50,377 | https://www.wfonts.com/font/arial-unicode-ms                                      |
                                            |                        |            |        |                                                                                   |
                                            | Code 2000              |   v1.171   | 63,546 | http://www.fontspace.com/james-kass/code2000                                      |
                                            •------------------------•------------•--------•-----------------------------------------------------------------------------------•
                                            

                                            Best Regards,

                                            guy038

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