On Oct 18, 8:49 pm, Terry Brown <[email protected]> wrote:
> On Tue, 18 Oct 2011 20:24:01 -0700 (PDT)
>
> The only actually reported issue with the save tabs script was the
> spreading out of log messages between various log panes, which may or
> may not be avoided by adding a c.setLog() call to the end of the script.
Terry, maybe you are right. Maybe this use of g.openWithFileName()
causes no real harm. Maybe the log panes can be cleaned up by calling
c.setLog()---but I doubt both conjectures. Edward was vehement in his
warnings.
The following code eliminates all the bad symptoms that I have
complained about, by using a after-create-leo-frame hook as Edward
suggested. I have tested my code only lightly and there is lot I
don't know about Leo-Editor. When I use this code, I see no error
messages on the console and all the Log Pane output is correct. This
code may well be ten times worse than the restore_session() function.
I will welcome corrections and improvements. I would particularly
like to know how to put the focus back on the tab that started the
opens. See the comments in my code for what I tried which does not
work.
+ @button safe open tabs
"""
To use this button commmand, the body of the currently selected
node, must contain one UNL per line.
Close all file tabs except the file tab with the current focus.
Then for each UNL in the body of the currently selected node,
open the file in a tab and select the specified position.
This button commad 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.
"""
@others
closeList = g.app.windowList[:]
for frame in closeList:
if c == frame.c: continue
g.app.closeLeoWindow(frame)
for unl in p.b.split('\n'):
fn, np = unl.split('#')
if fn == c.fileName(): continue
OK, frameNew = queuedOpenWithFileName(fn, c)
if OK:
cNew = frameNew.c
for pos in cNew.all_positions():
if pos.get_UNL() == unl:
cNew.setCurrentPosition(pos)
cNew.redraw()
break
- 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')
cmdr.hookFunction = None
ownfnFifo = g._ownfnFifo
filename, cmdr = ownfnFifo.pop(0)
if ownfnFifo:
filename, cmdr = ownfnFifo[0]
OK, cNew = g.openWithFileName(filename, cmdr)
if OK:
cmdr.hookFunction = owfnHookFunction
g.doHook("after-create-leo-frame",c=cmdr)
else:
del g._ownfnFifo
return OK, cNew
else:
# All tabs have been opened.
del g._ownfnFifo
###### The following 2 lines appear to have no effect.
###### How can I return focus to the tab from which the open
process began?
#cmdr.frame.bringToFront() # Return focus to the tab from
which the open process began
#cmdr.redraw()
- 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:
ownfnFifo.apend((filename, cmdr))
g.doHook("after-create-leo-frame",c=cmdr)
else:
g._ownfnFifo = [(filename, cmdr)]
OK, cNew = g.openWithFileName(filename, cmdr)
if OK:
cmdr.hookFunction = owfnHookFunction
g.doHook("after-create-leo-frame",c=cmdr)
else:
del g._ownfnFifo
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.