is there a command to turn off visual display of changes and then turn them back on?

29 views
Skip to first unread message

djc

unread,
Dec 7, 2016, 10:40:21 AM12/7/16
to leo-e...@googlegroups.com
Newbie question.

When I use the c.k.simulateCommand() method, it does an immediate redraw of the outline.  I would like to suppress the redraw until after I am done making changes.  I am looking at using position methods to do the same thing so that I control the redraw, but haven't had time to suss it out yet.  

Also, I have been doing some stress testing on large, programatically created outlines to see if there are scale limits in Leo.  I have found that Leo will crash if I use c.k.simulateCommand() on a large number of nodes in one function.

I don't want to report this formally until I have a chance to dig into it more, so this is just a heads up.

The specific code that I am working on is intended to build a journal with weekly text files.  This might be better served using a database, but I have some specific requirements that make Leo and interesting potential solution.....and it provides a great opportunity to learn the ins and outs of the tool.

A code snip follows that illustrates what I am doing.  This code does cause Leo to hang, but not at consistent places in the operation, so I assuming that it is a memory problem; perhaps stack space, or garbage collector overflow, or some such.


monthNames = {"01-January","02-February","03-March","04-April","05-May",
            "06-June","07-July","08-August","09-September","10-October","11-November","12-December"}
    
yr = 1960
for np in c.all_positions():

    if (c.p.h[:5] == 'Year:'):
        yr = int(c.p.h[-4:])
        g.es(str(yr)) 
          
    c.k.simulateCommand('goto-next-visible') 
    if (c.p.h[:5] == 'Year:'):
        c.k.simulateCommand('move-outline-right')
                 
    if (c.p.h in monthNames):
        c.k.simulateCommand('move-outline-right')
        c.k.simulateCommand('move-outline-right')
        
    elif (c.p.h[:1] == 'w'):
        c.k.simulateCommand('move-outline-right')
        c.k.simulateCommand('move-outline-right')
        c.k.simulateCommand('move-outline-right')

Thanks,

djc

Edward K. Ream

unread,
Dec 7, 2016, 10:54:45 AM12/7/16
to leo-editor
On Wed, Dec 7, 2016 at 9:40 AM, djc <darr...@gmail.com> wrote:

Is there something like and echo_on and echo_off when using c.k.simulateCommand()?

​Not sure what you mean by "changes".

Edward

djc

unread,
Dec 8, 2016, 12:28:31 PM12/8/16
to leo-editor
Sorry....not very well formatted question.

Terry Brown

unread,
Dec 8, 2016, 1:17:46 PM12/8/16
to leo-e...@googlegroups.com
My guess is using position methods is the way to go(*).  I think there's something about the way people come to Leo scripting that leads them down the c.k.simulateCommand path, but I'm not really sure that's intentionally.  My feeling is that c.k.simulateCommand is best for occasional limited use, not for the kind of thing you're doing. Complexity wise, the position methods are no harder to use than c.k.simulateCommand, when your script gets to the level yours has.

With the position methods there's typically no issue about unwanted display updates, you just need to remember to call c.redraw() when you're done.

(*) one caveat for programmatically generated trees - for large trees it's significantly faster to use vnodes instead of positions.  There's very little difference code wise, instead of

myNode = p.insertAfter()
<< build big tree under myNode >>

it's basically

myNode = p.insertAfter().v
<< build big tree under myNode >>

because most of the tree building methods positions have are available on vnodes too (.h, .b, .insertAfter(), etc.)

Cheers -Terry




From: djc <darr...@gmail.com>
To: leo-editor <leo-e...@googlegroups.com>
Sent: Thursday, December 8, 2016 11:28 AM
Subject: Re: is there a command to turn off visual display of changes and then turn them back on?

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+...@googlegroups.com.
To post to this group, send email to leo-e...@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


Edward K. Ream

unread,
Dec 11, 2016, 5:10:48 AM12/11/16
to leo-editor
On Thu, Dec 8, 2016 at 11:28 AM, djc <darr...@gmail.com> wrote:
Sorry....not very well formatted question.

When I use the c.k.simulateCommand() method, it does an immediate redraw of the outline.  I would like to suppress the redraw until after I am done making changes.  I am looking at using position methods to do the same thing so that I control the redraw, but haven't had time to suss it out yet.  

​As Terry says, using position methods will work, but these are low-level methods.  Using Commander (c) methods will be more convenient, provided you can make them do what you want them to do.

As Terry notes, there is one (and I think only one) performance issue to be aware of: p.setDirty. p.v.setDirty is much faster.  Use p.v.setDirty unless your @<file> nodes aren't being set dirty properly.

One more note: It's really important to understand that c.redraw() only requests a redraw, to be done when the command completes. c.k.simulateCommand does actually complete the command, which is why it's not great to string several such calls together--you'll get multiple full redraws.  If your script does need an immediate redraw, you can call c.redraw_now().

HTH.

Edward

Reply all
Reply to author
Forward
0 new messages