omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    [Example] editor.annotate_line (py3 beta)

    Pythonista
    editor annotate
    2
    3
    2866
    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.
    • Phuket2
      Phuket2 last edited by

      A silly example for editor.annotate_line. It's does a search on the current file and setting an annotation. This case is just the occurrence. Editor has a built in search, but just an example.

      import editor, clipboard, console, io
      
      def get_file_text():
      	file_name = editor.get_path()
      	with io.open(file_name, encoding = 'utf-8') as file:
      		return file.read()
      	
      def find_lines(text, search_text):
      	lst = []
      	for ln_no, ln in enumerate(text.splitlines()):
      		if search_text in ln:
      			lst.append(ln_no + 1)
      	return lst	
      
      def mark_lines(lns, s_text):
      	for i, ln in enumerate(lns):
      		editor.annotate_line(ln, text = str(i + 1), style = 'success', expanded= False)
      	
      if __name__ == '__main__':
      	
      	s_text = console.input_alert('Enter text to search for')
      	if not s_text:
      		exit()
      		
      	file_text = get_file_text()
      	
      	ln_list = find_lines(file_text, s_text)
      	mark_lines(ln_list, s_text)
      	
      
      1 Reply Last reply Reply Quote 0
      • Phuket2
        Phuket2 last edited by

        Ok, somewhere along the line I missed you can tap the file name to navigate the annotations. But its a great implementation I think

        1 Reply Last reply Reply Quote 0
        • cook
          cook last edited by

          @phuket2 this is really nice. You had mentioned that to me before but I wasn't sure what you meant. It's cool. I'm more and more looking forward to the next version of pythonista!

          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          Powered by NodeBB Forums | Contributors