• Login
Community
  • Login

Python 3 and Python scripts plugin

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
24 Posts 7 Posters 18.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.
  • C
    Claudia Frank @Bill Winder
    last edited by Claudia Frank Feb 11, 2018, 8:33 PM Feb 11, 2018, 8:32 PM

    @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
    • B
      Bill Winder
      last edited by Feb 12, 2018, 4:57 AM

      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?

      S D 2 Replies Last reply Feb 12, 2018, 12:37 PM Reply Quote 0
      • S
        Scott Sumner @Bill Winder
        last edited by Feb 12, 2018, 12:37 PM

        @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
        • B
          Bill Winder
          last edited by Feb 12, 2018, 5:38 PM

          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
          • C
            chcg
            last edited by Feb 12, 2018, 5:47 PM

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

            B 1 Reply Last reply Feb 12, 2018, 6:47 PM Reply Quote 0
            • B
              Bill Winder @chcg
              last edited by Feb 12, 2018, 6:47 PM

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

              S 1 Reply Last reply Feb 13, 2018, 1:12 AM Reply Quote 0
              • G
                guy038
                last edited by guy038 Feb 12, 2018, 11:52 PM Feb 12, 2018, 11:52 PM

                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
                • S
                  Scott Sumner @Bill Winder
                  last edited by Feb 13, 2018, 1:12 AM

                  @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
                  • D
                    dail @Bill Winder
                    last edited by dail Feb 13, 2018, 5:05 AM Feb 13, 2018, 5:04 AM

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

                    B 1 Reply Last reply Feb 13, 2018, 6:55 PM Reply Quote 2
                    • B
                      Bill Winder @dail
                      last edited by Feb 13, 2018, 6:55 PM

                      @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.)

                      C 1 Reply Last reply Feb 13, 2018, 7:07 PM Reply Quote 0
                      • C
                        Claudia Frank @Bill Winder
                        last edited by Feb 13, 2018, 7:07 PM

                        @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

                        B 1 Reply Last reply Feb 14, 2018, 12:31 AM Reply Quote 3
                        • B
                          Bill Winder @Claudia Frank
                          last edited by Feb 14, 2018, 12:31 AM

                          @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
                          • V
                            Vitaliy Dovgan
                            last edited by Feb 17, 2018, 9:48 AM

                            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
                            • V
                              Vitaliy Dovgan
                              last edited by Feb 17, 2018, 10:04 AM

                              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
                              • V
                                Vitaliy Dovgan
                                last edited by Feb 17, 2018, 4:28 PM

                                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.

                                B 1 Reply Last reply Feb 19, 2018, 8:52 PM Reply Quote 1
                                • G
                                  guy038
                                  last edited by guy038 Feb 19, 2018, 7:21 PM Feb 18, 2018, 10:08 PM

                                  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

                                  B 1 Reply Last reply Feb 19, 2018, 9:36 PM Reply Quote 0
                                  • B
                                    Bill Winder @Vitaliy Dovgan
                                    last edited by Feb 19, 2018, 8:52 PM

                                    @Vitaliy-Dovgan Thanks! Good work around. There must be somewhere direct access to an unsaved tab, because I can close npp with an unsaved tab and when I reopen, it is there. So the unsaved tab is actually saved somewhere. Curious!

                                    S 1 Reply Last reply Feb 19, 2018, 9:01 PM Reply Quote 0
                                    • S
                                      Scott Sumner @Bill Winder
                                      last edited by Feb 19, 2018, 9:01 PM

                                      @Bill-Winder said:

                                      So the unsaved tab is actually saved somewhere.

                                      Yes, saved under a “Backup” folder by default. I just made 5 “new files” and they were created in this folder with the following names:

                                      new 1@2018-02-19_155611
                                      new 2@2018-02-19_155613
                                      new 3@2018-02-19_155613
                                      new 4@2018-02-19_155615
                                      new 5@2018-02-19_155618
                                      
                                      B 1 Reply Last reply Feb 20, 2018, 10:11 PM Reply Quote 0
                                      • B
                                        Bill Winder @guy038
                                        last edited by Feb 19, 2018, 9:36 PM

                                        @guy038 Very cool! I just chose fonts at random until things looked right. Useful description, which will serve elsewhere also – same issue in Jedit. (Though I use Jedit less and less - npp has everything I need and is very fast.)

                                        1 Reply Last reply Reply Quote 0
                                        • B
                                          Bill Winder @Scott Sumner
                                          last edited by Feb 20, 2018, 10:11 PM

                                          @Scott-Sumner and they are numbered! Perfect. Which essentially solves my problem.

                                          I hope! There is one further step. I will have to capture the name of the active tab and give it to NPPEXec.

                                          But that should be possible through the sci_sendmessage function (will look into that), since this is possible:

                                          sci_sendmsg SCI_GETSELECTIONSTART
                                          set local selStart = $(MSG_RESULT)

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