Setting Text Distances from a Script

Here is a simple script for setting the text distances for a text frame. In this particular version, we set all the distances the same, so only one value is needed for the value.Dialog.

More complex but more versatile
What if we didn't want all the distances to be the same? Look at this modification of the distance value.Dialog, and subsequent lines: We could use int(distance...), but using float allows for decimals - whatever you enter into the dialog will be a string until converted, and the setTextDistances command needs number values. In case you haven't used the built-in split function in Python, this breaks a series of values or words into a list, eliminating the white space (which can be of variable length). So here we create the list distance[] from the 4 values. I think this is more efficient than making a series of value.Dialogs.

I could save some lines by doing this: but this makes later review, editing, and understanding of the script more difficult.

Oh yes, there's some voodoo here too!
Look at these lines: I move the text frame, then I move it back! Doesn't make sense, does it? For whatever reason, if I didn't put these in there, Scribus wouldn't redraw the frame, and I don't know why. If you're thinking that it's because I forgot the redrawAll command, think again. I tried various combinations of setRedraw(True/False), and nothing worked.

What I found out was that if I moved the frame after the script ran, Scribus would redraw and place the text inside the distances, but then I'd have to move it back. So here the script does it, and voilà! It just works.