On Thu, 6 Oct 2011 07:44:29 -0700 (PDT)
Todd Mars <[email protected]> wrote:
> Another thing I probably want/need is to write my @file node
> (@auto .txt right now) according to the current state as viewed on the
> screen.
Got a bit carried away here, but the new version below asks what to do
re expanded nodes, and uses a template to define indentation / extra
lines between pieces.
Note that this just runs directly on the outline, @file / @auto etc. is
irrelevant.
Cheers -Terry
--- cut here ---
# template is everything between r""" and second """
# placeholders are H heading B body C children
# use \n in B and C lines for conditional blank lines
template = r"""H
B
* C"""
lines=[]
exp_only = g.app.gui.runAskYesNoCancelDialog(
c, 'Expanded nodes only?', 'Expanded nodes only?')
if exp_only == 'no':
exp_only = False
def export_text(p, indent=''):
spaces = ' '*(len(indent) - len(indent.lstrip(' ')))
for line in template.split('\n'):
if 'H' in line:
lines.append(indent + line.replace('H', p.h))
elif 'B' in line and p.b.strip():
prefix = line[:line.find('B')].replace('\\n', '\n')
for i in p.b.strip().split('\n'):
lines.append(spaces + prefix + i)
prefix = line[:line.find('B')].replace('\\n', '')
if line.endswith('\\n'):
lines.append('')
elif 'C' in line and (not exp_only or p.isExpanded()):
prefix = line[:line.find('C')].replace('\\n', '\n')
for child in p.children():
export_text(child, indent=spaces + prefix)
if line.endswith('\\n'):
lines.append('')
elif 'C' not in line and 'B' not in line:
lines.append(line)
if exp_only != 'cancel':
for i in c.getSelectedPositions():
export_text(i)
# filename = g.app.gui.runSaveFileDialog('Save to file')
filename = '/home/tbrown/Desktop/del.txt'
if filename is not None:
open(filename,'w').write('\n'.join(lines))
--- cut here ---
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en.