Hi Rob.
If you want to get some help on scripting you need to show the whole script 
or attach Leo document. The error you mentioned tells you about unknown 
variable self and yet in the piece of code you showed there is nothing 
about that variable. If you say that you just put debug print statements in 
the appropriate places there is no way we can deduce what those places are.

If you just copied a method from the ExternalFilesController class, and 
tried to use it as a function in your script, it will be missing `self` 
argument, or it will be misinterpreted as other argument. The distinction 
between methods and functions is that methods always receive as their first 
argument an instance of the class the method belongs to. That first 
argument is named *self*. It is written in the beginning of the method 
definition, but when method is used (called by some other code), this 
argument is skipped.

For example:
class A:
   def m_one(self, a, b, c):
       pass

# given 
inst =A()

# the following call to method m_one
inst.m_one(1, 2, 3)
# is roughly equivalent to
A.m_one(inst, 1, 2, 3)

The second way to call a method is longer, and Python does this conversion 
for us, so it is possible to use shorter and nicer syntax:
inst.m_one(a, b, c)

I don't know how you plan to solve this issue, but here are few hints. You 
most probably need to get the modification time of the external files after 
some synchronization with the cloud. Once you have those times you should 
call 

g.app.externalFilesController.set_time(filename, new_time)

That will ensure that Leo doesn't notice this change, and therefore Leo 
won't ask you about it.

If you know that synchronization with cloud takes at most 3s (for example), 
you can disable checking of external files for 3s every time 
synchronization happens. 

Here is a script that demonstrates this technique.

from leo.core.leoQt import QtCore

import time

FNAME = '/tmp/dummy.txt'


c.frame.log.clearTab('Log')

efc = g.app.externalFilesController


def change_later():

   def mkchange():

       with open(FNAME, 'wt', encoding='utf8') as out:

           out.write('This is not a dummy text')

       g.es('changed file')

   QtCore.QTimer.singleShot(3000, mkchange)


def toggle():

   txt = '\n'.join(['This is a dummy text', time.asctime()])

   c.find_h('@clean %s'%FNAME)[0].b = txt

   if g.os_path_exists(FNAME):

       g.os.unlink(FNAME)

   c.save()

   efc.checksum_d[FNAME] = efc.checksum(FNAME)

   efc.enabled_d[c] = not efc.enabled_d.get(c, True)

   efc.unchecked_commanders = []

   return efc.enabled_d[c]


g.es('checking ext files?', toggle())

change_later()


To test it you need to add a node with headline `@clean /tmp/dummy.txt` or 
if you use another file name then change the variable FNAME at the 
beginning of the script to match your filename.

Every time this script is executed, it turns checking external files 
on/off, and then it changes the outline a bit and ensures that the change 
is written to the file. After about 3s, it changes the content of the file 
writing directly to the file in the function mkchange. 

If you run this script several times (wait each time at least 3s), you will 
notice that Leo one time notices the file has been changed, and the next 
time it doesn't notice.

HTH
Vitalije

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to