Ejemplo n.º 1
0
 def openLeoFile(self, fileName):
     """Open a .leo file, or create a new Leo frame if no fileName is given."""
     g = self.g
     g.app.silentMode = self.silentMode
     useLog = False
     if not self.isOpen():
         return None
     if self.useCaches:
         self.reopen_cachers()
     else:
         g.app.db = g.NullObject()
     fileName = self.completeFileName(fileName)
     c = g.openWithFileName(fileName)  # #2489.
     # Leo 6.3: support leoInteg.
     g.app.windowList.append(c.frame)
     if not self.useCaches:
         c.db = g.NullObject()
     # New in Leo 5.1. An alternate fix for bug #130.
     # When using a bridge Leo might open a file, modify it,
     # close it, reopen it and change it all within one second.
     # In that case, this code must properly compute the next
     # available gnx by scanning the entire outline.
     g.app.nodeIndices.compute_last_index(c)
     if useLog:
         g.app.gui.log = log = c.frame.log
         log.isNull = False
         log.enabled = True
     return c
Ejemplo n.º 2
0
 def finishCreate(self, c):
     '''Create the entire Leo main window in the shim itself.'''
     import leo.plugins.qt_frame as qt_frame
     import leo.plugins.qt_text as qt_text
     ###
     # import leo.plugins.qt_tree as qt_tree
     # import leo.plugins.qt_menu as qt_menu
     # import leo.core.leoFrame as leoFrame
     self.c = c
     g.pr('\n----- OutlineEditorShim.finishCreate: g.app.log: %r\n' %
          g.app.log)
     # Called by c.finishCreate.
     f = c.frame
     # A LeoFrame, *not* a QWidget.
     c.frame.c = c
     assert isinstance(c.frame, qt_frame.LeoQtFrame), repr(c.frame)
     self.setStyleSheet('background: red')
     # No longer seen, which is good.
     #
     # From SDIFrameFactory.createFrame
     dw = qt_frame.DynamicWindow(c, parent=self)
     dw.construct()
     # This just creates frames for components.
     dw.show()
     f.top = dw
     assert isinstance(dw.treeWidget,
                       qt_frame.LeoQTreeWidget), repr(dw.treeWidget)
     #
     # From LeoQtFrame.finishCreate.
     f.createIconBar()  # A base class method.
     f.createSplitterComponents()
     ### f.createStatusLine() # A base class method.
     f.createFirstTreeNode()  # Call the base-class method.
     # Does some basic inits.
     if 1:
         lm = g.app.loadManager
         fn = c.fileName()
         theFile = lm.openLeoOrZipFile(fn)
         # Enable the log.
         g.app.unlockLog()
         c.frame.log.enable(True)
         # Phase 2: Create the outline.
         ### g.doHook("open1", old_c=None, c=c, new_c=c, fileName=fn)
         if theFile:
             ### readAtFileNodesFlag = bool(previousSettings)
             readAtFileNodesFlag = True
             # The log is not set properly here.
             assert c.p
             ok = lm.readOpenedLeoFile(c, fn, readAtFileNodesFlag, theFile)
             # Call c.fileCommands.openLeoFile to read the .leo file.
             if not ok:
                 g.trace('lm.readOpenedLeoFile FAILED', fn)
     ### f.menu = qt_menu.LeoQtMenu(c, f, label='top-level-menu')
     f.menu = g.NullObject(tag='c.frame.menu')
     g.app.windowList.append(f)
     f.miniBufferWidget = qt_text.QMinibufferWrapper(c)
     c.setLog()
     c.redraw()
     c.bodyWantsFocus()
Ejemplo n.º 3
0
 def __getattr__(self, name):
     aList = self.d.get(name, [])
     callers = g.callers(4)
     if callers not in aList:
         aList.append(callers)
         self.d[name] = aList
         g.trace('%30s' % ('TemplateMenu.' + name), callers)
     return g.NullObject()
Ejemplo n.º 4
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
Ejemplo n.º 5
0
 def __init__(self, guiName='nullGui'):
     '''ctor for the NullGui class.'''
     LeoGui.__init__(self, guiName)
     # init the base class.
     self.clipboardContents = ''
     self.theDict = {}
     self.focusWidget = None
     self.frameFactory = g.NullObject()
     self.iconimages = {}
     self.script = None
     self.lastFrame = None
     self.isNullGui = True
     self.bodyTextWidget = leoFrame.StringTextWidget
     self.plainTextWidget = leoFrame.StringTextWidget
Ejemplo n.º 6
0
 def runMainLoop(self, fileName=None):
     '''The main loop for the browser gui.'''
     # pylint: disable=arguments-differ
     if fileName:
         print('LeoWapp running: %s...' % g.shortFileName(fileName))
     else:
         print('LeoWapp running...')
     if 0:  # Run all unit tests.
         path = g.os_path_finalize_join(g.app.loadDir, '..', 'test',
                                        'unittest.leo')
         c = g.openWithFileName(path, gui=self)
         c.findCommands.ftm = g.NullObject()
         # A hack. Maybe the NullGui should do this.
         c.debugCommands.runAllUnitTestsLocally()
     print('calling sys.exit(0)')
     sys.exit(0)
Ejemplo n.º 7
0
 def __init__ (self,c):
     '''Ctor for backlinkController class.'''
     self.c = c
     self.c.backlinkController = self
     self.initIvars()
     self.name_levels = c.config.getInt('backlink_name_levels') or 0
     self.fixIDs(c)
     if Tk:
         self.ui = backlinkTkUI(self)
     elif Qt:
         self.ui = backlinkQtUI(self)
     else:
         # Fix part of #509. Ignore missing attributes.
         self.ui = g.NullObject()
     g.registerHandler('select3', self.updateTab)
     g.registerHandler('open2', self.loadLinks)
     # already missed initial 'open2' because of after-create-leo-frame, so
     self.loadLinksInt()
     self.updateTabInt()
Ejemplo n.º 8
0
    def initLeo(self):
        """
        Init the Leo app to which this class gives access.
        This code is based on leo.run().
        """
        if not self.isValidPython():
            return
        #@+<< initLeo imports >>
        #@+node:ekr.20070227093629.1: *4* << initLeo imports >> initLeo (leoBridge)
        try:
            # #1472: Simplify import of g
            from leo.core import leoGlobals as g
            self.g = g
        except ImportError:
            print("Error importing leoGlobals.py")
        #
        # Create the application object.
        try:
            # Tell leoApp.createDefaultGui not to create a gui.
            # This module will create the gui later.
            g.in_bridge = self.vs_code_flag  # #2098.
            g.in_vs_code = True  # 2098.
            from leo.core import leoApp
            g.app = leoApp.LeoApp()
        except ImportError:
            print("Error importing leoApp.py")
        g.app.leoID = None
        if self.tracePlugins:
            g.app.debug.append('plugins')
        g.app.silentMode = self.silentMode
        #
        # Create the g.app.pluginsController here.
        from leo.core import leoPlugins
        leoPlugins.init()  # Necessary. Sets g.app.pluginsController.
        try:
            from leo.core import leoNodes
        except ImportError:
            print("Error importing leoNodes.py")
            traceback.print_exc()
        try:
            from leo.core import leoConfig
        except ImportError:
            print("Error importing leoConfig.py")
            traceback.print_exc()
        #@-<< initLeo imports >>
        g.app.recentFilesManager = leoApp.RecentFilesManager()
        g.app.loadManager = lm = leoApp.LoadManager()
        lm.computeStandardDirectories()
        # #2519: Call sys.exit if leoID does not exist.
        g.app.setLeoID(useDialog=False, verbose=True)
        # Can be done early. Uses only g.app.loadDir & g.app.homeDir.
        lm.createAllImporterData()  # #1965.
        g.app.inBridge = True  # Support for g.getScript.
        g.app.nodeIndices = leoNodes.NodeIndices(g.app.leoID)
        g.app.config = leoConfig.GlobalConfigManager()
        if self.useCaches:
            g.app.setGlobalDb()  # #556.
        else:
            g.app.db = g.NullObject()
            g.app.commander_cacher = g.NullObject()
            g.app.global_cacher = g.NullObject()
        if self.readSettings:
            # reads only standard settings files, using a null gui.
            # uses lm.files[0] to compute the local directory
            # that might contain myLeoSettings.leo.
            lm.readGlobalSettingsFiles()
        else:
            # Bug fix: 2012/11/26: create default global settings dicts.
            settings_d, bindings_d = lm.createDefaultSettingsDicts()
            lm.globalSettingsDict = settings_d
            lm.globalBindingsDict = bindings_d
        self.createGui()  # Create the gui *before* loading plugins.
        if self.verbose:
            self.reportDirectories()
        self.adjustSysPath()
        # Kill all event handling if plugins not loaded.
        if not self.loadPlugins:

            def dummyDoHook(tag, *args, **keys):
                pass

            g.doHook = dummyDoHook
        g.doHook("start1")  # Load plugins.
        g.app.computeSignon()
        g.app.initing = False
        g.doHook("start2", c=None, p=None, v=None, fileName=None)
Ejemplo n.º 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