def make_at_clean_outline(self, fn, root, s, rev):
     '''
     Create a hidden temp outline from lines without sentinels.
     root is the @<file> node for fn.
     s is the contents of the (public) file, without sentinels.
     '''
     # A specialized version of at.readOneAtCleanNode.
     hidden_c = leoCommands.Commands(fn, gui=g.app.nullGui)
     at = hidden_c.atFileCommands
     x = hidden_c.shadowController
     hidden_c.frame.createFirstTreeNode()
     hidden_root = hidden_c.rootPosition()
     # copy root to hidden root, including gnxs.
     root.copyTreeFromSelfTo(hidden_root, copyGnxs=True)
     hidden_root.h = fn + ':' + rev if rev else fn
     # Set at.encoding first.
     at.initReadIvars(hidden_root, fn)
         # Must be called before at.scanAllDirectives.
     at.scanAllDirectives(hidden_root)
         # Sets at.startSentinelComment/endSentinelComment.
     new_public_lines = g.splitLines(s)
     old_private_lines = at.write_at_clean_sentinels(hidden_root)
     marker = x.markerFromFileLines(old_private_lines, fn)
     old_public_lines, junk = x.separate_sentinels(old_private_lines, marker)
     assert old_public_lines
     new_private_lines = x.propagate_changed_lines(
         new_public_lines, old_private_lines, marker, p=hidden_root)
     at.fast_read_into_root(
         c = hidden_c,
         contents = ''.join(new_private_lines),
         gnx2vnode = {},
         path = fn,
         root = hidden_root,
     )
     return hidden_c
 def createHiddenCommander(self, fn):
     '''Read the file into a hidden commander (Similar to g.openWithFileName).'''
     import leo.core.leoCommands as leoCommands
     lm = g.app.loadManager
     c2 = leoCommands.Commands(fn, gui=g.app.nullGui)
     theFile = lm.openLeoOrZipFile(fn)
     if theFile:
         c2.fileCommands.openLeoFile(theFile, fn, readAtFileNodesFlag=True, silent=True)
         return c2
     else:
         return None
 def make_leo_outline(self, fn, path, s, rev):
     """Create a hidden temp outline for the .leo file in s."""
     hidden_c = leoCommands.Commands(fn, gui=g.app.nullGui)
     hidden_c.frame.createFirstTreeNode()
     root = hidden_c.rootPosition()
     root.h = fn + ':' + rev if rev else fn
     hidden_c.fileCommands.getLeoFile(
         theFile=io.StringIO(initial_value=s),
         fileName=path,
         readAtFileNodesFlag=False,
         silent=False,
         checkOpenFiles=False,
     )
     return hidden_c
 def make_at_clean_outline(self, fn, root, s, rev):
     '''
     Create a hidden temp outline from lines without sentinels.
     root is the @<file> node for fn.
     s is the contents of the (public) file, without sentinels.
     '''
     # A specialized version of at.readOneAtCleanNode.
     trace = False and not g.unitTesting
     hidden_c = leoCommands.Commands(fn, gui=g.app.nullGui)
     at = hidden_c.atFileCommands
     x = hidden_c.shadowController
     hidden_c.frame.createFirstTreeNode()
     hidden_root = hidden_c.rootPosition()
     # copy root to hidden root, including gnxs.
     root.copyTreeFromSelfTo(hidden_root, copyGnxs=True)
     hidden_root.h = fn + ':' + rev if rev else fn
     # Set at.encoding first.
     at.initReadIvars(hidden_root, fn)
     # Must be called before at.scanAllDirectives.
     at.scanAllDirectives(hidden_root)
     # Sets at.startSentinelComment/endSentinelComment.
     new_public_lines = g.splitLines(s)
     old_private_lines = at.write_at_clean_sentinels(hidden_root)
     marker = x.markerFromFileLines(old_private_lines, fn)
     old_public_lines, junk = x.separate_sentinels(old_private_lines,
                                                   marker)
     assert old_public_lines
     new_private_lines = x.propagate_changed_lines(new_public_lines,
                                                   old_private_lines,
                                                   marker,
                                                   p=hidden_root)
     # Init the input stream used by read-open file.
     at.read_lines = new_private_lines
     at.read_ptr = 0
     # Read the file using the @file read logic.
     at.readOpenFile(hidden_root, fn, deleteNodes=True)
     # Complete the read.
     for p in hidden_root.self_and_subtree():
         p.b = ''.join(getattr(p.v, 'tempBodyList', []))
     if at.errors: g.trace(at.errors, 'errors!')
     if trace: g.trace(len(s), rev, fn, hidden_c)
     return None if at.errors else hidden_c
 def make_at_file_outline(self, fn, s, rev):
     """Create a hidden temp outline from lines."""
     # A specialized version of atFileCommands.read.
     hidden_c = leoCommands.Commands(fn, gui=g.app.nullGui)
     at = hidden_c.atFileCommands
     hidden_c.frame.createFirstTreeNode()
     root = hidden_c.rootPosition()
     root.h = fn + ':' + rev if rev else fn
     at.initReadIvars(root, fn, importFileName=None, atShadow=None)
     if at.errors > 0:
         g.trace('***** errors')
         return None
     at.fast_read_into_root(
         c=hidden_c,
         contents=s,
         gnx2vnode={},
         path=fn,
         root=root,
     )
     return hidden_c
Beispiel #6
0
 def setUp(self):
     """
     Create a commander using a **null** gui, regardless of g.app.gui.
     Create the nodes in the commander.
     """
     # Do the import here to avoid circular dependencies.
     from leo.core import leoCommands
     from leo.core.leoGui import NullGui
     # Set g.unitTesting *early*, for guards.
     g.unitTesting = True
     # Create a new commander for each test.
     # This is fast, because setUpClass has done all the imports.
     self.c = c = leoCommands.Commands(fileName=None, gui=NullGui())
     # Init the 'root' and '@settings' nodes.
     self.root_p = c.rootPosition()
     self.root_p.h = 'root'
     self.settings_p = self.root_p.insertAfter()
     self.settings_p.h = '@settings'
     # Select the 'root' node.
     c.selectPosition(self.root_p)
Beispiel #7
0
def create_app():
    """
    Create the Leo application, g.app, the Gui, g.app.gui, and a commander.
    
    This method is expensive (about 1 sec) only the first time it is called.
    
    Thereafter, recreating g.app, g.app.gui, and new commands is fast.
    """
    # t1 = time.process_time()
    from leo.core import leoGlobals as g
    from leo.core import leoApp
    g.app = leoApp.LeoApp()  # Do this first, to avoid circular dependencies.
    from leo.core import leoConfig
    from leo.core import leoNodes
    from leo.core import leoCommands
    from leo.core import leoGui
    # t2 = time.process_time()
    g.app.recentFilesManager = leoApp.RecentFilesManager()
    g.app.loadManager = leoApp.LoadManager()
    g.app.loadManager.computeStandardDirectories()
    if not g.app.setLeoID(useDialog=False, verbose=True):
        raise ValueError("unable to set LeoID.")
    g.app.nodeIndices = leoNodes.NodeIndices(g.app.leoID)
    g.app.config = leoConfig.GlobalConfigManager()
    g.app.db = g.TracingNullObject('g.app.db')
    g.app.pluginsController = g.NullObject('g.app.pluginsController')
    g.app.commander_cacher = g.NullObject('g.app.commander_cacher')
    g.app.gui = leoGui.NullGui()
    # t3 = time.process_time()
    #
    # Create a dummy commander, to do the imports in c.initObjects.
    c = leoCommands.Commands(fileName=None, gui=g.app.gui)
    # t4 = time.process_time()
    # if t4 - t3 > 0.1:
    # print('create_app\n'
    # f"  imports: {(t2-t1):.3f}\n"
    # f"      gui: {(t3-t2):.3f}\n"
    # f"commander: {(t4-t2):.3f}\n"
    # f"    total: {(t4-t1):.3f}\n")
    return c
 def make_at_file_outline(self, fn, s, rev):
     '''Create a hidden temp outline from lines.'''
     # A specialized version of atFileCommands.read.
     hidden_c = leoCommands.Commands(fn, gui=g.app.nullGui)
     at = hidden_c.atFileCommands
     hidden_c.frame.createFirstTreeNode()
     root = hidden_c.rootPosition()
     root.h = fn + ':' + rev if rev else fn
     at.initReadIvars(root, fn, importFileName=None, atShadow=None)
     at.fromString = s
     if at.errors > 0:
         g.trace('***** errors')
         return None
     at.inputFile = g.FileLikeObject(fromString=at.fromString)
     at.initReadLine(at.fromString)
     at.readOpenFile(root, fn, deleteNodes=True)
     at.inputFile.close()
     # Complete the read.
     for p in root.self_and_subtree():
         p.b = ''.join(getattr(p.v, 'tempBodyList', []))
     at.scanAllDirectives(root, importing=False, reading=True)
     return hidden_c
Beispiel #9
0
def create_app(gui_name='null'):
    """
    Create the Leo application, g.app, the Gui, g.app.gui, and a commander.

    This method is expensive (0.5 sec) only the first time it is called.

    Thereafter, recreating g.app, g.app.gui, and new commands is fast.
    """
    trace = False
    t1 = time.process_time()
    #
    # Set g.unitTesting *early*, for guards, to suppress the splash screen, etc.
    g.unitTesting = True
    # Create g.app now, to avoid circular dependencies.
    g.app = leoApp.LeoApp()
    # Late imports.
    warnings.simplefilter("ignore")
    from leo.core import leoConfig
    from leo.core import leoNodes
    from leo.core import leoCommands
    from leo.core.leoGui import NullGui
    if gui_name == 'qt':
        from leo.plugins.qt_gui import LeoQtGui
    t2 = time.process_time()
    g.app.recentFilesManager = leoApp.RecentFilesManager()
    g.app.loadManager = lm = leoApp.LoadManager()
    lm.computeStandardDirectories()
    g.app.leoID = 'TestLeoId'  # 2022/03/06: Use a standard user id for all tests.
    g.app.nodeIndices = leoNodes.NodeIndices(g.app.leoID)
    g.app.config = leoConfig.GlobalConfigManager()
    g.app.db = g.NullObject('g.app.db')  # type:ignore
    g.app.pluginsController = g.NullObject(
        'g.app.pluginsController')  # type:ignore
    g.app.commander_cacher = g.NullObject(
        'g.app.commander_cacher')  # type:ignore
    if gui_name == 'null':
        g.app.gui = NullGui()
    elif gui_name == 'qt':
        g.app.gui = LeoQtGui()
    else:
        raise TypeError(f"create_gui: unknown gui_name: {gui_name!r}")
    t3 = time.process_time()
    # Create a dummy commander, to do the imports in c.initObjects.
    # Always use a null gui to avoid screen flash.
    # setUp will create another commander.
    c = leoCommands.Commands(fileName=None, gui=g.app.gui)
    # Create minimal config dictionaries.
    settings_d, bindings_d = lm.createDefaultSettingsDicts()
    lm.globalSettingsDict = settings_d
    lm.globalBindingsDict = bindings_d
    c.config.settingsDict = settings_d
    c.config.bindingsDict = bindings_d
    assert g.unitTesting is True  # Defensive.
    t4 = time.process_time()
    # Trace times. This trace happens only once:
    #     imports: 0.016
    #         gui: 0.000
    #   commander: 0.469
    #       total: 0.484
    if trace and t4 - t3 > 0.1:
        print('create_app:\n'
              f"  imports: {(t2-t1):.3f}\n"
              f"      gui: {(t3-t2):.3f}\n"
              f"commander: {(t4-t2):.3f}\n"
              f"    total: {(t4-t1):.3f}\n")
    return c