← Back to team overview

zim-wiki team mailing list archive

Wrap command tool

 

Hi all,

I know just enough python to get strangled by it - but here goes...

I've been using a Autokey script under Linux for a while - decided I
would try my hand at porting it to a Zim Custom tool.

I like to use the verbatim format for some text references - just to
set it off from my personal text.  So in Autokey it's done by copying
the highlighted text into a string, performing the wrap on the string
(which may span multiple lines) and pasting the wrapped text back
using keyboard.send_key from the Autokey library (overwriting the
unwrapped text).  Works well.

I've managed to do the same thing in a wrap.py script that I can run
on the python command line, giving it a long string as an argument.
For instance the following wraps the string (whole words) at 20
characters or less (I use 100 in Zim text window):

import textwrap
import sys
text = sys.argv[1]
text_lines =text.splitlines()
for line in text_lines:
    wrap_line = textwrap.fill(line,20)
    print wrap_line+'\n'

And can run it as:

$python wrap.py "This is a very long line that I need to have over 100
characters in in order to see it wrap, I think we are coming close to
100 characters"
This is a very long
line that I need to
have over 100
characters in in
order to see it
wrap, I think we are
coming close to 100
characters

The question that I have is that I'm no sure what mods are necessary
to run this as a Zim custom tool: I'm guessing something line a Wrap
tool mapped to a command like "wrap.py %t" - but how do I (a) delete
the existing (unwrapped) text and (b) get the wrapped text back into
the Zim window?

Sorry to be such a newbie

- Kurt


Follow ups