Community
    • Login

    Python gotoLine() Not going to line after Open()

    Scheduled Pinned Locked Moved General Discussion
    9 Posts 4 Posters 422 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.
    • Anthony BlincoA
      Anthony Blinco
      last edited by

      I have a file that has a list of files and linenumbers. I want to click on a line and hit an Fkey which will load the file and goto the line.
      My code looks like this;

      print("Opening "+os.path.normpath(c)+"...")
      notepad.open(c)
      print("Going to line "+parms[2]+"...")
      editor.gotoLine(int(parms[2]))
      

      My Console output looks like this;

      Opening excpmon.cbp...
      Going to line 136...
      

      It loads the file fine but it doesn’t goto the line. What have i done wrong?
      Thanks in advance for any help

      EkopalypseE Alan KilbornA 2 Replies Last reply Reply Quote 0
      • EkopalypseE
        Ekopalypse @Anthony Blinco
        last edited by

        @Anthony-Blinco

        Could it be that there are notifications or threads involved
        which result in executing gotoLine before the document has been loaded?

        870050d9-6451-40aa-b38d-89a4abd0828c-image.png

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

          @Anthony-Blinco said in Python gotoLine() Not going to line after Open():

          It loads the file fine but it doesn’t goto the line

          I changed your code a bit, to:

          p = r'd:\blah.txt'
          print("Opening "+ p + "...")
          notepad.open(p)
          line = 12
          print("Going to line " + str(line) + "...")
          editor.gotoLine(line)
          

          and, running it, it didn’t have a problem opening the file and moving to the correct line.

          1 Reply Last reply Reply Quote 1
          • Anthony BlincoA
            Anthony Blinco
            last edited by Anthony Blinco

            @Alan-Kilborn I’m not sure what the difference (between my code and yours) is there
            It is very weird. If I turn word wrap off it works, if word wrap is on it doesn’t work (For my primary file, not the loaded file).
            I do have pre-processor python code that runs when a file is loaded.
            Is there anyway to wait until there is no other processing and then goto the line?

            Alan KilbornA dailD 3 Replies Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @Anthony Blinco
              last edited by

              @Anthony-Blinco said in Python gotoLine() Not going to line after Open():

              If I turn word wrap off it works, if word wrap is on it doesn’t work (For my primary file, not the loaded file).

              I’m not sure what to think about that…

              I do have pre-processor python code that runs when a file is loaded.

              I’m not sure what “pre-processor python code” exactly means…

              Is there anyway to wait until there is no other processing and then goto the line?

              You could certainly do some kind of “sleep”.
              You might start with time.sleep() for experimentation purposes.
              A threading timer is a bit more elegant if the basic sleep works.
              I’m not convinced you should need it, but only you have your exact situation.

              1 Reply Last reply Reply Quote 0
              • dailD
                dail @Anthony Blinco
                last edited by

                @Anthony-Blinco said in Python gotoLine() Not going to line after Open():

                It is very weird. If I turn word wrap off it works, if word wrap is on it doesn’t work (For my primary file, not the loaded file).

                A quote from the Scintilla documentation

                Wrapping is not performed immediately there is a change but is delayed until the display is redrawn. This delay improves performance by allowing a set of changes to be performed and then wrapped and displayed once. Because of this, some operations may not occur as expected. If a file is read and the scroll position moved to a particular line in the text, such as occurs when a container tries to restore a previous editing session, then the scroll position will have been determined before wrapping so an unexpected range of text will be displayed. To scroll to the position correctly, delay the scroll until the wrapping has been performed by waiting for an initial SCN_PAINTED notification.

                1 Reply Last reply Reply Quote 3
                • Alan KilbornA
                  Alan Kilborn @Anthony Blinco
                  last edited by Alan Kilborn

                  @Anthony-Blinco said in Python gotoLine() Not going to line after Open():

                  if word wrap is on it doesn’t work (For my primary file, not the loaded file).

                  So what didn’t register with me is that “word wrap” is a global setting, it affects all files. So if you have one “wrapped” you have them all “wrapped”. So saying something like “word wrap is on…for my primary file not the loaded file” isn’t really a valid statement.

                  So yes, I think in light of that plus @dail 's input, a lot more is starting to make sense now as to what is happening for you. :-)

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

                    Hm, wrapping has an impact on scripts, learned something new today.

                    1 Reply Last reply Reply Quote 0
                    • Anthony BlincoA
                      Anthony Blinco
                      last edited by

                      Awesome advice as usual. A 10ms delay did it.
                      I will investigate the SCN_PAINTED notification to implement it properly
                      Thanks and very much appreciated

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