Menu

How to use indicators?

Help
CFrank
2015-12-21
2015-12-26
  • CFrank

    CFrank - 2015-12-21

    Hello,
    I try to use indicators but it doesn't work as expected.
    When running the script for the first time it marks the first match only
    (although I do have multiple matches, confirmed by console.write).
    When running the script the second time everything gets cleared,
    nothing marked at all.
    When running the third time it acts like the first time and so on...

    My script looks like

    editor.indicSetStyle(8,INDICATORSTYLE.STRAIGHTBOX)
    editor.indicSetFore(8,(0,127,0))
    editor.indicSetAlpha(8,255)
    editor.indicSetOutlineAlpha(8,255)
    # editor.indicSetUnder(8,True)   
    editor.setIndicatorCurrent(8)
    editor.indicatorClearRange(0, text_end_position)
    
    matches = []
    editor.research(selected_text, lambda m: matches.append(m.span(0)))
    
    for match in matches:
        console.write('match {0} {1}\n'.format(match[0], match[1] - match[0]))
        # editor.setIndicatorValue(8)
        editor.indicatorFillRange(match[0], match[1] - match[0])
    

    Any ideas what I'm doing wrong?

    Npp 6.8.7
    Python Script 1.0.8
    Windows 7 x64

    Thank you
    Claudia

     

    Last edit: CFrank 2015-12-21
  • CFrank

    CFrank - 2015-12-22

    OK, solution seems to be setting indicator styles within for loop.
    Hmm, still not sure if this is how it should work.

    Claudia

     
    • Dave Brotherstone

      My guess would that n++ is jumping in between the actions and setting the
      indicators somehow. As all scripts run on a separate thread, it's entirely
      possible that something gets reset - possibly as a result of setting the
      indicator in the first place.

      It could be we need to create a function that does all these operations in
      one go. I've been thinking about trying to provide an interface where you
      could provide a function/lambda that you want to call atomically, on the
      main n++ thread. This would probably solve this, but admittedly not in an
      easy way.

      If you or anyone else with more python knowledge than me, would like to
      suggest an interface for doing something like that, I'd be keen to hear it!

      Cheers
      Dave

      On Tue, 22 Dec 2015 22:01 CFrank myxin2010@users.sf.net wrote:

      OK, solution seems to be setting indicator styles within for loop.
      Hmm, still not sure if this is how it should work.

      Claudia


      How to use indicators?


      Sent from sourceforge.net because you indicated interest in <
      https://sourceforge.net/p/npppythonscript/discussion/1188886/>

      To unsubscribe from further messages, please visit <
      https://sourceforge.net/auth/subscriptions/>

       
      • CFrank

        CFrank - 2015-12-26

        Hi Dave,
        sorry for late answer but I didn't get a notifcation sent that someone had replied.
        May I ask you what you mean by

        If you or anyone else with more python knowledge than me, would like to
        suggest an interface for doing something like that, I'd be keen to hear it!

        ?

        You don't speak about c++ interface do you? If so, sorry I cannot be helpful at all.
        If you talk about a python class which acts inbetween, than I might have some ideas
        if I could only understand what your request is asking for. Sorry you see I'm not really
        a programmer :-(

        What I think I understood is,

        python script plugin runs on a separated (from npp) thread which, of course, means
        that interacting with npps or scintillas interface could lead to the situation that script
        hasn't finished it work yet and npp (or any other plugin) jumps in to do something similar
        or somesthing which reversed what script has been done so far. Which, I guess, could always
        happen, even if that script runs in an atomic way.
        Now you think about an additional function, let's called run_atomic, which would get
        editor as the first parameter, and a function or lambda as the second paramter. Then you
        would like to run this function within the main thread of npp, to prevent, how can I say this,
        thread interruption (?) and report the result back to python script plugin.

        If I understood this correctly, can this even be guaranteed? What I read about atomic executions is that only the processor itself can be seen as the only trusted resource
        to ask for atomic execution.

        Thank you for your help
        Claudia

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.