Community
    • Login

    PythonScript, editor.markerAdd has stopped working

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    18 Posts 3 Posters 1.4k 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.
    • PeterJonesP
      PeterJones @Michael Brock
      last edited by

      @michael-brock said in PythonScript, editor.markerAdd has stopped working:

      The upgrade to 8.3.3 overwrote that script.

      I find that difficult to believe.

      I think what happened is that you were using the machine startup.py (c:\Program Files\Notepad++\Plugins\PythonScript\Scripts is the normal machine-script folder) instead of the user startup.py (%AppData%\Notepad++\Plugins\Config\PythonScript\Scripts for a normal installation or <portable-npp-folder...>\Plugins\Config\PythonScript\Scripts for a portable) … Thus, when you installed PythonScript 2.0.0, it overwrite the machine startup.py; the plugin expects that it can overwrite that file, because users are expected to use the user startup.py for their own customization (though the docs don’t emphasize that enough, IMO; we in the forum do actively encourage PythonScript users to customize in the user startup, not the machine startup).

      Michael BrockM 1 Reply Last reply Reply Quote 1
      • Michael BrockM
        Michael Brock @PeterJones
        last edited by

        More specifically then: I upgraded Notepad++, that uninstalled Pyton Script. I reinstalled Python Script and in the process the startup.py script I was using was overwritten.

        This is the snippet of code:

        # sets margins and markers for bookmarks
        editor.setMarginWidthN(4, 10)
        editor.setMarginTypeN(4, MARGINTYPE.TEXT)
        
        for x in range(1,9):
            marginMask = 1 << x
            editor.setMarginMaskN(4, 510 )
            editor.markerDefine(x, 10048 + x) # use a colored symbol (possible symbols are CIRCLE, ROUNDRECT, ARROW, SMALLRECT, SHORTARROW, .
            editor.markerSetFore(x, (0,0,0)) # contour of symbol 
            editor.markerSetBack(x, (255,255,0)) # filling
        
        Alan KilbornA 1 Reply Last reply Reply Quote 1
        • Alan KilbornA
          Alan Kilborn @Michael Brock
          last edited by

          @michael-brock said in PythonScript, editor.markerAdd has stopped working:

          editor.markerDefine(x, 10048 + x)

          When I try something like this, with e.g. x = 2, I only get a half-width bookmark, looking like this:

          d6999263-acf1-4f97-b670-cd72c0e8046d-image.png

          Unless… I zoom way up in which case it looks better:

          e9f7a795-5f31-420a-9e5e-c1c0cd3e6151-image.png

          But that isn’t a realistic working environment for me. :-)

          If I try other types of boomarks (as well as the default blue/purple ball symbol), they all look fine at my preferred zoom level, here’s the “bookmark” one:

          666e736f-f687-4dd3-b40e-3bf6114db68d-image.png

          Michael BrockM 1 Reply Last reply Reply Quote 0
          • Michael BrockM
            Michael Brock @Alan Kilborn
            last edited by

            I had not noticed previously that zooming would affect the bookmarks. My default zoom is large enough for me not to have noticed.

            SharedScreenshot.jpg

            Interestingly, Window’s Ink Workspace screen shot removes the color from the left margin and really makes the font unreadable.

            Michael BrockM 1 Reply Last reply Reply Quote 0
            • Michael BrockM
              Michael Brock @Michael Brock
              last edited by

              Better screenshot:

              SharedScreenshot.jpg

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

                @Alan-Kilborn ,

                from Npp import *
                
                # sets margins and markers for bookmarks
                editor.setMarginWidthN(4, 10)
                editor.setMarginTypeN(4, MARGINTYPE.TEXT)
                
                # this will make margin#4 allow markers 1-10
                editor.setMarginMaskN(4, 0x03FF )
                for x in range(1,9+1):
                    editor.markerDefine(x, 10048 + x) # use a colored symbol (possible symbols are CIRCLE, ROUNDRECT, ARROW, SMALLRECT, SHORTARROW, .
                    editor.markerSetFore(x, (0,0,0)) # contour of symbol
                    editor.markerSetBack(x, (255,255,0)) # filling
                
                for i in range(1,9+1):
                    editor.markerAdd(5+i,i)
                
                editor.setMarginMaskN(1, editor.getMarginMaskN(1) | 0x3FF ) # set those bits
                
                from time import sleep
                sleep(10) # five seconds later
                editor.setMarginMaskN(1, editor.getMarginMaskN(1) & ~0x3FF ) # clear those bits
                

                3d440d16-5131-4c46-85aa-9ec66ec6d605-image.png

                It appears that if you are putting the character style in margin 1, where the bookmark round icon goes, the characters are strangely placed. I think it might have to do with the editor.setMarginTypeN(1, ...) that is implicit in Notepad++ default condition. Because the margin=1 column cuts off the characters, but margin=4 column does not.

                I added

                for i in range(0,4+1):
                    t = editor.getMarginTypeN(i)
                    console.write("margin type #{} = {} {}\n".format(i, t, MARGINTYPE.values[t]))
                

                to see the types for each of the 5 margins:

                margin type #0 = 1 NUMBER
                margin type #1 = 6 COLOUR
                margin type #2 = 0 SYMBOL
                margin type #3 = 0 SYMBOL
                margin type #4 = 4 TEXT
                

                but even if I add editor.setMarginTypeN(1,4) near the beginning, the margin=1 column still cuts off half of the character.

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

                  So there are some nuances here that I haven’t thought about before, or at least not in a long time, so I will expend some more time thinking about it…

                  But aside from the visual implications of seeing a different number symbol for the bookmarks, is there other value in doing this – what the OP has done? I don’t think so, unless there are other commands created which use the numbers to do something.

                  Michael BrockM 1 Reply Last reply Reply Quote 0
                  • Michael BrockM
                    Michael Brock @Alan Kilborn
                    last edited by

                    @alan-kilborn said in PythonScript, editor.markerAdd has stopped working:

                    So there are some nuances here that I haven’t thought about before, or at least not in a long time, so I will expend some more time thinking about it…

                    But aside from the visual implications of seeing a different number symbol for the bookmarks, is there other value in doing this – what the OP has done? I don’t think so, unless there are other commands created which use the numbers to do something.

                    This is part of a bookmarking “scheme”. I can set a marker/bookmark w/ the number marker in the column with alt-1,alt-2, etc. The snippet of code above sets the bookmark. What isn’t shown is the portion that saves the marker handle (as a string) to a file named after the bookmark # and the file name (so a separate file for each bookmark for each file).

                    I have a separate set of scripts which are keyed to ctrl-1, ctrl-2, etc. These look for a file named as above and reads the marker from the file and uses

                    gotoLine=editor.markerLineFromHandle(int(gotoMarker))
                    editor.gotoLine(int(gotoLine))
                    

                    to jump to the line.

                    It works very well. So I have a set of 9 bookmarks that I can set and jump between. In my programming I will set particular code blocks to always have the same bookmark and it makes jumping between them very easy.

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

                      @michael-brock said in PythonScript, editor.markerAdd has stopped working:

                      It works very well.

                      Ah, okay. It’s always nice to have the “rest of the story” on something that starts out as a tech support question and then takes on a life of its own through discussions. :-)

                      1 Reply Last reply Reply Quote 1
                      • Alan KilbornA Alan Kilborn referenced this topic on
                      • Alan KilbornA
                        Alan Kilborn
                        last edited by

                        The marker ID used for bookmarks changed in Notepad++ 8.4.6 (and later). It is now 20, instead of 24. So, all references to 24 in this thread and/or its script(s), should be changed to 20.

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