On Wed, 24 Aug 2011 07:16:36 -0700 (PDT)
Truong Nghiem <[email protected]> wrote:
> Hi,
>
> I am new to Leo editor and find it very interesting. I have been
> using it for writing my slides (presentations) in Beamer/LaTeX. Its
> structure editing is very useful.
>
> I would like to create a few buttons to insert template LaTeX code,
> for example code for a new frame (i.e. slide), code for columns, etc.
> However, I don't know how to insert text at the current cursor
> position in the body pane?
Below is some code for closing XML tags in the body pane - if you can
read around the XML stuff it manipulates the body text along the lines
you're asking. I recently suggested this part of the API be cleaned
up, as it can add significant power from a text editor / macroish point
of view.
Actually my example might not completely cover what you're after, but
you can introspect the opjects it's using for other methods.
> Also, will the function g.app.gui.runAskOkCancelStringDialog() returns
> None if the user clicked Cancel? Or will it return an empty string?
> How about runAskOkCancelNumberDialog()?
Sometime's it easiest just to read the code, by opening
the .../leo/core/LeoPyRef.leo file
Cheers -Terry
from xml import sax
class Stacky(sax.handler.ContentHandler):
def __init__(self): self.stack = []
def startElement(self, name, attrs):
self.stack.append(name)
def endElement(self, name):
self.stack.pop()
stacky = Stacky()
txt = p.bodyString()
w = c.frame.body.bodyCtrl
pnt = w.getInsertPoint()
xml = txt[:pnt]
try:
sax.parseString(str(xml), stacky)
except sax.SAXParseException, descrip:
if 'no element found' not in str(descrip):
g.es("Error in context '%s'" % '->'.join(stacky.stack))
raise
if stacky.stack:
etag = '</%s>' % stacky.stack[-1]
c.setBodyString(p, xml + etag + txt[pnt:])
# insert point moves to end of buffer... so move it back
w.setInsertPoint(pnt+len(etag)) # unicode safe?
else:
raise
--
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.