On Oct 28, 2:49 pm, Terry Brown <[email protected]> wrote:
> On Fri, 28 Oct 2011 16:11:57 -0500
>
> I see your code calls g.doHook("after-create-leo-frame",c=cmdr), rather
> than g.registerHandler('after-create-leo-frame',onCreate), which
> suggests you're generating 'after-create-leo-frame' events rather than
> responding to them - the system should generate them when an outline is
> loaded, probably from near the end of g.openWithFileName()
>
Thanks for the correction. I should have called g.registerHandler()
not g.doHook().
> You show your code in a button - calls to g.openWithFileName()
> triggered when a user clicks on a button aren't reentrant, only calls
> run on load from a @script node would be reentrant, so (1) may not
> be relevant anyway.
I'm not sure what you mean. Do you mean that when
g.openWithFileName() is called by @script code, g.openWithFileName()
returns before the open is completed. But when g.openWithFileName() is
called by @button code, g.openWithFileName() finishes the open before
it returns?
This does seem to be the case, and I missed it when I wrote and
"tested" my code. That is, the only error symptom I see when
g.openWithFileName() is called by @button code is that the
c.frame.bringToFront() at the end does not work (The focus stays on
the tab for the last file opened.). This symptom also occurs when my
queuedOpenWithFileName() is used. So my "improvment" did not
demonstrate any improvement. Note that the c.frame.bringToFront()
does work in the @script node (even though the @script causes the log
pane tag confusions you note).
I wonder why c.frame.bringToFront() works in @script but does not work
in @button. By the way, and possibly relevant: A command line that
opens several outlines (e.g., leo a.leo b.leo c.leo) leaves the focus
on the tab for the first outline (e.g., a.leo).
My queuedOpenWithFileName() contained too many bugs to be worth
listing. But after I fixed many bugs including replacing the calls to
g.doHook() with calls to g.registerHandler(), it does seem to
eliminate all the bad behavior of an @script node that opens many
outlines.
Here is queuedOpenWithFileName() with my test. This includes many
print statements used for debugging.
+ @@script load tabs - Test queuedOpenWithFileName()
# Test queuedOpenWithFileName()
@others
queuedOpenWithFileName('/home/bob/.leo/workbook.leo', c)
queuedOpenWithFileName('/home/bob/tmp/c.leo', c)
queuedOpenWithFileName('/media/sda1/BobH/1/Leo/bzrNotes.leo', c)
queuedOpenWithFileName('/media/sda1/BobH/1/Leo/gtd.leo', c)
queuedOpenWithFileName('/media/sda1/BobH/1/Leo/Lisp.leo', c)
- owfnHookFunction()
def owfnHookFunction(tag, keywords):
"""
Hook Function used by queuedOpenWithFileName()
to drop the next entry from the queue of open requests
and to dispatch the next open (if any). This function
is executed on an after-create-leo-frame event.
@param tag: 'after-create-leo-frame'
@param keywords: Dictionary mapping 'c' to the commander
passed on the g.doHook() call that caused this call back.
"""
cmdr = keywords.get('c')
owfnFifo = getattr(g, '_owfnFifo', None)
if owfnFifo:
g.pr('FIFO exists, cmdr={0}'.format(cmdr))
else:
g.pr('No FIFO, cmdr={0}'.format(cmdr))
return
filename, cmdr = owfnFifo.pop(0)
if owfnFifo:
filename, cmdr = owfnFifo[0]
OK, cNew = g.openWithFileName(filename, cmdr)
if OK:
g.registerHandler("after-create-leo-frame",
owfnHookFunction)
else:
del g._owfnFifo
return
else:
# All tabs have been opened.
del g._owfnFifo
# owfnHookFunction() should be unregistered. How do I do
this?
g.pr('Bring to front {0}'.format(cmdr))
cmdr.frame.bringToFront() # Return focus to the tab from
which the open process began
- queuedOpenWithFileName()
def queuedOpenWithFileName(filename, cmdr):
"""
This function avoids re-entering g.openWithFileName() before
g.openWithFileName() completes certain non-reentrant parts
by queuing open requests and dispatching the next request
only when the next after-create-leo-frame event occurs.
"""
owfnFifo = getattr(g, '_owfnFifo', None)
if owfnFifo:
g.pr('Append {0}'.format(filename))
owfnFifo.append((filename, cmdr))
g.registerHandler("after-create-leo-frame", owfnHookFunction)
return True, cmdr
else:
setattr(g, '_owfnFifo', [(filename, cmdr)])
OK, cNew = g.openWithFileName(filename, cmdr)
if OK:
g.registerHandler("after-create-leo-frame",
owfnHookFunction)
else:
del g._owfnFifo
return OK, cNew
--
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.