Exemple #1
0
def init():
    ok = not g.app.unitTesting # Not safe for unit testing.  Changes core class.
    if ok:
        #@+<< override write methods >>
        #@+node:ekr.20040419105219.1: ** << override write methods >>
        oldOpenNodeSentinel = leoAtFile.atFile.putOpenNodeSentinel

        def putLineNumberDirective(self,v,inAtAll=False,inAtOthers=False,middle=False):

            oldOpenNodeSentinel(self,v,inAtAll,inAtOthers,middle)

            if self.language in ("perl","perlpod"):
                line = 'line 1 "node:%s (%s)"' % (self.nodeSentinelText(v),self.shortFileName)
                self.putSentinel(line)

        g.funcToMethod(putLineNumberDirective,	
            leoAtFile.atFile,"putOpenNodeSentinel")
        #@-<< override write methods >>
        #@+<< override read methods >>
        #@+node:ekr.20040419105219.2: ** << override read methods >>
        readNormalLine = leoAtFile.atFile.readNormalLine

        def skipLineNumberDirective(self, s, i):

            if linere.search(s): 
                return  # Skipt the line.
            else:		
                readNormalLine(self,s,i)

        g.funcToMethod(skipLineNumberDirective,
            leoAtFile.atFile,"readNormalLine")
        #@-<< override read methods >>
        g.plugin_signon(__name__)
    return ok
def init():
    '''Return True if the plugin has loaded successfully.'''
    ok = not g.unitTesting
        # Not for unit testing: overrides core methods.
    if ok:
        if 0:
            # Override the LeoFrame class.
            class myLeoFrame(leoFrame.LeoFrame):
                def __init__(self,title=None):
                    g.pr("myLeoFrame ctor",title)
                    leoFrame.LeoFrame.__init__(self,title)
            leoFrame.LeoFrame = myLeoFrame
            
        if 0:
            # Override methods of the LeoApp class.
            oldAppCloseLeoWindow = g.app.closeLeoWindow

            def myAppCloseLeoWindow(self,frame):
                global oldAppCloseLeoWindow
                oldAppCloseLeoWindow(frame)
                g.trace("after closeLeoWindow")
            
            g.funcToMethod(myAppCloseLeoWindow,leoApp.LeoApp,"closeLeoWindow")
            
        g.plugin_signon(__name__)
    return ok
def init():

    ok = not g.unitTesting
    # Not for unit testing: overrides core methods.
    if ok:
        if 0:
            # @+<< override the LeoFrame class >>
            # @+node:edream.110203113231.917: *3* << override the LeoFrame class >>
            class myLeoFrame(leoFrame.leoFrame):

                if 0:

                    def __init__(self, title=None):
                        g.pr("myLeoFrame ctor", title)
                        leoFrame.leoCoreFrame.__init__(self, title)

            leoFrame.LeoFrame = myLeoFrame
            # @-<< override the LeoFrame class >>
        if 0:
            # @+<< override methods of the LeoApp class >>
            # @+node:edream.110203113231.918: *3* << override methods of the LeoApp class >>
            oldAppCloseLeoWindow = g.app.closeLeoWindow

            def myAppCloseLeoWindow(self, frame):

                global oldAppCloseLeoWindow

                oldAppCloseLeoWindow(frame)
                g.trace("after closeLeoWindow")

            g.funcToMethod(myAppCloseLeoWindow, leoApp.LeoApp, "closeLeoWindow")
            # @-<< override methods of the LeoApp class >>
        g.plugin_signon(__name__)

    return ok
def init():
    """Return True if the plugin has loaded successfully."""
    ok = not g.unitTesting  # Not for unit testing: overrides core methods.
    if ok:
        if 0:
            # Override the LeoFrame class.

            class myLeoFrame(leoFrame.LeoFrame):

                def __init__(self, c, title=None):
                    g.pr("myLeoFrame ctor", title)
                    super().__init__(c, gui=None)

            leoFrame.LeoFrame = myLeoFrame
        if 0:
            # Override methods of the LeoApp class.
            oldAppCloseLeoWindow = g.app.closeLeoWindow

            def myAppCloseLeoWindow(self, frame):
                global oldAppCloseLeoWindow
                oldAppCloseLeoWindow(frame)
                g.trace("after closeLeoWindow")

            g.funcToMethod(myAppCloseLeoWindow, leoApp.LeoApp, "closeLeoWindow")
        g.plugin_signon(__name__)
    return ok
Exemple #5
0
def onmenu2(tag, keys):
    c = keys.get('c')
    if c:
        g.trace(c.k)
        g.funcToMethod(f=ekrCommand1, theClass=c, name=None)
        g.funcToMethod(f=ekrCommand2, theClass=c, name=None)
        c.k.registerCommand('ekr-command1', c.ekrCommand1)
        c.k.registerCommand('ekr-command2', c.ekrCommand2)
Exemple #6
0
def onmenu2 (tag,keys):
    c = keys.get('c')
    if c:
        g.trace(c.k)
        g.funcToMethod(f=ekrCommand1, theClass=c, name=None)
        g.funcToMethod(f=ekrCommand2, theClass=c, name=None)
        c.k.registerCommand('ekr-command1',shortcut=None,func=c.ekrCommand1,pane='all',verbose=False)
        c.k.registerCommand('ekr-command2',shortcut=None,func=c.ekrCommand2,pane='all',verbose=False)
Exemple #7
0
def onStart2(tag, keywords):
    """
    Replace tkfile open/save method with external calls to zenity.
    """
    trace and g.trace('zenity ok')

    g.funcToMethod(runOpenFileDialog, g.app.gui)
    g.funcToMethod(runSaveFileDialog, g.app.gui)
Exemple #8
0
def onmenu2(tag, keys):
    c = keys.get('c')
    if c:
        g.trace(c.k)
        g.funcToMethod(f=ekrCommand1, theClass=c, name=None)
        g.funcToMethod(f=ekrCommand2, theClass=c, name=None)
        c.k.registerCommand('ekr-command1', c.ekrCommand1)
        c.k.registerCommand('ekr-command2', c.ekrCommand2)
    def install_drawing_overrides (self):

        # g.pr("Cleo plugin: installing overrides for",self.c.shortFileName())

        tree = self.c.frame.tree # NOT tkGui.leoTkinterTree

        g.funcToMethod(self.setUnselectedHeadlineColors,tree)
        g.funcToMethod(self.setDisabledHeadlineColors,tree)
Exemple #10
0
def onStart (tag,keywords):
    
    log = c.frame.log

    # Replace frame.put with newPut.
    g.funcToMethod(newPut,log,"put")

    # Replace frame.putnl with newPutNl.
    g.funcToMethod(newPutNl,log,"putnl")
Exemple #11
0
def onStart (tag,keywords):
    '''redefine methods when Leo starts.'''
    c = keywords.get('c')
    if c:
        log = c.frame.log
        # Replace frame.put with newPut.
        g.funcToMethod(newPut,log,"put")
        # Replace frame.putnl with newPutNl.
        g.funcToMethod(newPutNl,log,"putnl")
def onStart2 (tag, keywords):

    """
    Replace tkfile open/save method with external calls to zenity.
    """
    trace and g.trace('zenity ok')

    g.funcToMethod(runOpenFileDialog,g.app.gui)
    g.funcToMethod(runSaveFileDialog,g.app.gui)
Exemple #13
0
def onStart(tag, keywords):
    '''redefine methods when Leo starts.'''
    c = keywords.get('c')
    if c:
        log = c.frame.log
        # Replace frame.put with newPut.
        g.funcToMethod(newPut, log, "put")
        # Replace frame.putnl with newPutNl.
        g.funcToMethod(newPutNl, log, "putnl")
Exemple #14
0
def init ():
    '''Return True if the plugin has loaded successfully.'''
    # Append to the module list, not to the g.copy.
    g.globalDirectiveList.append('multipath')
    g.globalDirectiveList.append('multiprefix')
    # Override all instances of leoAtFile.AtFile.
    at = leoAtFile.AtFile
    global originalOpenFileForWriting ; originalOpenFileForWriting = at.openFileForWriting
    g.funcToMethod(decoratedOpenFileForWriting,at,name='openFileForWriting')
    # g.registerHandler('save1',start)
    g.registerHandler('save2',stop)
    g.registerHandler(('new','menu2'),addMenu)
    g.plugin_signon(__name__)
    return True # Now gui-independent.
Exemple #15
0
def init ():
    '''Return True if the plugin has loaded successfully.'''
    # Append to the module list, not to the g.copy.
    g.globalDirectiveList.append('multipath')
    g.globalDirectiveList.append('multiprefix')
    # Override all instances of leoAtFile.AtFile.
    at = leoAtFile.AtFile
    global originalOpenFileForWriting ; originalOpenFileForWriting = at.openFileForWriting
    g.funcToMethod(decoratedOpenFileForWriting,at,name='openFileForWriting')
    # g.registerHandler('save1',start)
    g.registerHandler('save2',stop)
    g.registerHandler(('new','menu2'),addMenu)
    g.plugin_signon(__name__)
    return True # Now gui-independent.
Exemple #16
0
def installDrawMethod(tags, kw):
    global registered
    if registered:
        return

    g.funcToMethod(doFootprint, leoTkinterTree, "setUnselectedLabelState")

    registered = True

    updater = threading.Thread(target=updateNodes)
    updater.setDaemon(True)
    updater.start()

    global lock
    lock = threading.Lock()
def onCreate (tag, keys):

    c = keys.get('c')
    if c and c.frame.log:

        g.pr('overriding c.executeScript')

        # Inject ivars.
        log = c.frame.log
        c.script_io_to_body_oldexec  = c.executeScript
        c.script_io_to_body_oldput   = log.put
        c.script_io_to_body_oldputnl = log.putnl

        # Override c.executeScript.
        g.funcToMethod(newExecuteScript,c.__class__,'executeScript')
        c.k.overrideCommand('execute-script',c.executeScript)
def onCreate(tag, keys):

    c = keys.get('c')
    if c and c.frame.log:

        g.pr('overriding c.executeScript')

        # Inject ivars.
        log = c.frame.log
        c.script_io_to_body_oldexec = c.executeScript
        c.script_io_to_body_oldput = log.put
        c.script_io_to_body_oldputnl = log.putnl

        # Override c.executeScript.
        g.funcToMethod(newExecuteScript, c.__class__, 'executeScript')
        c.k.overrideCommand('execute-script', c.executeScript)
Exemple #19
0
def onmenu2(tag, keys):
    c = keys.get('c')
    if c:
        g.trace(c.k)
        g.funcToMethod(f=ekrCommand1, theClass=c, name=None)
        g.funcToMethod(f=ekrCommand2, theClass=c, name=None)
        c.k.registerCommand('ekr-command1',
                            shortcut=None,
                            func=c.ekrCommand1,
                            pane='all',
                            verbose=False)
        c.k.registerCommand('ekr-command2',
                            shortcut=None,
                            func=c.ekrCommand2,
                            pane='all',
                            verbose=False)
def installDrawMethod(tags, kw): 
    global registered 
    if registered: 
        return 

    g.funcToMethod(doFootprint, 
        leoTkinterTree, 
        "setUnselectedLabelState") 

    registered = True 

    updater = threading.Thread(target=updateNodes) 
    updater.setDaemon(True) 
    updater.start() 

    global lock 
    lock = threading.Lock() 
Exemple #21
0
def init():
    '''Return True if the plugin has loaded successfully.'''
    global original_precheck
    #
    # Append to the module list, not to the g.copy.
    g.globalDirectiveList.append('multipath')
    g.globalDirectiveList.append('multiprefix')
    #
    # Override all instances of at.precheck
    at = leoAtFile.AtFile
    original_precheck = at.precheck
    g.funcToMethod(decorated_precheck, at, name='precheck')
    #
    # g.registerHandler('save1',start)
    g.registerHandler('save2', stop)
    g.registerHandler(('new', 'menu2'), addMenu)
    g.plugin_signon(__name__)
    return True  # gui-independent.
Exemple #22
0
def init ():
    '''Return True if the plugin has loaded successfully.'''
    global original_precheck
    #
    # Append to the module list, not to the g.copy.
    g.globalDirectiveList.append('multipath')
    g.globalDirectiveList.append('multiprefix')
    #
    # Override all instances of at.precheck
    at = leoAtFile.AtFile
    original_precheck = at.precheck
    g.funcToMethod(decorated_precheck, at, name='precheck')
    #
    # g.registerHandler('save1',start)
    g.registerHandler('save2',stop)
    g.registerHandler(('new','menu2'),addMenu)
    g.plugin_signon(__name__)
    return True # gui-independent.
Exemple #23
0
    def monkey_patch_leo(self):

        global old_loadFile
        #
        # Use a Leonine pyzo.config.
        if 0:
            # Works, but uses light theme.
            pyzo.config = ConfigShim()
        #
        # Ignore .leo files.
        if 0:
            # Probably will never be needed: it's fine to load .leo files for now.
            from pyzo.core.editorTabs import EditorTabs
            old_loadFile = EditorTabs.loadFile
            g.funcToMethod(loadFile, EditorTabs)
        #
        # Patch pyzo.core.editor.createEditor function
        if 1:
            import pyzo.core.editor
            pyzo.core.editor.createEditor = createEditor
Exemple #24
0
def init():
    """Return True if the plugin has loaded successfully."""
    ok = not g.unitTesting  # Not safe for unit testing.  Changes core class.
    if ok:
        #@+<< override write methods >>
        #@+node:ekr.20040419105219.1: ** << override write methods >> (lineNumbers.py)
        oldOpenNodeSentinel = leoAtFile.AtFile.putOpenNodeSentinel

        def putLineNumberDirective(self, p, inAtAll=False):

            oldOpenNodeSentinel(self, p, inAtAll)

            if self.language in ("perl", "perlpod"):
                line = 'line 1 "node:%s (%s)"' % (self.nodeSentinelText(p),
                                                  self.shortFileName)
                self.putSentinel(line)

        g.funcToMethod(putLineNumberDirective, leoAtFile.AtFile,
                       "putOpenNodeSentinel")
        #@-<< override write methods >>
        g.plugin_signon(__name__)
    return ok
Exemple #25
0
def init():
    ok = not g.app.unitTesting  # Not safe for unit testing.  Changes core class.
    if ok:
        #@+<< override write methods >>
        #@+node:ekr.20040419105219.1: ** << override write methods >>
        oldOpenNodeSentinel = leoAtFile.AtFile.putOpenNodeSentinel

        def putLineNumberDirective(self,
                                   v,
                                   inAtAll=False,
                                   inAtOthers=False,
                                   middle=False):

            oldOpenNodeSentinel(self, v, inAtAll, inAtOthers, middle)

            if self.language in ("perl", "perlpod"):
                line = 'line 1 "node:%s (%s)"' % (self.nodeSentinelText(v),
                                                  self.shortFileName)
                self.putSentinel(line)

        g.funcToMethod(putLineNumberDirective, leoAtFile.AtFile,
                       "putOpenNodeSentinel")
        #@-<< override write methods >>
        #@+<< override read methods >>
        #@+node:ekr.20040419105219.2: ** << override read methods >>
        readNormalLine = leoAtFile.AtFile.readNormalLine

        def skipLineNumberDirective(self, s, i):

            if linere.search(s):
                return  # Skipt the line.
            else:
                readNormalLine(self, s, i)

        g.funcToMethod(skipLineNumberDirective, leoAtFile.AtFile,
                       "readNormalLine")
        #@-<< override read methods >>
        g.plugin_signon(__name__)
    return ok
Exemple #26
0
def init():
    '''Return True if the plugin has loaded successfully.'''
    ok = not g.app.unitTesting # Not safe for unit testing.  Changes core class.
    if ok:
        #@+<< override write methods >>
        #@+node:ekr.20040419105219.1: ** << override write methods >>
        oldOpenNodeSentinel = leoAtFile.AtFile.putOpenNodeSentinel

        def putLineNumberDirective(self,p,inAtAll=False):

            oldOpenNodeSentinel(self,p,inAtAll)

            if self.language in ("perl","perlpod"):
                line = 'line 1 "node:%s (%s)"' % (
                    self.nodeSentinelText(p),self.shortFileName)
                self.putSentinel(line)

        g.funcToMethod(putLineNumberDirective,
            leoAtFile.AtFile,"putOpenNodeSentinel")
        #@-<< override write methods >>
        #@+<< override read methods >>
        #@+node:ekr.20040419105219.2: ** << override read methods >>
        # readNormalLine = leoAtFile.AtFile.readNormalLine

        # def skipLineNumberDirective(self, s, i):

            # if linere.search(s):
                # return  # Skipt the line.
            # else:
                # readNormalLine(self,s,i)

        # g.funcToMethod(skipLineNumberDirective,
            # leoAtFile.AtFile,"readNormalLine")
        #@-<< override read methods >>
        g.plugin_signon(__name__)
    return ok
Exemple #27
0
def init():
    '''Return True if the plugin has loaded successfully.'''
    ok = not g.app.unitTesting # Not safe for unit testing.  Changes core class.
    if ok:
        #@+<< override write methods >>
        #@+node:ekr.20040419105219.1: ** << override write methods >>
        oldOpenNodeSentinel = leoAtFile.AtFile.putOpenNodeSentinel

        def putLineNumberDirective(self,p,inAtAll=False):

            oldOpenNodeSentinel(self,p,inAtAll)

            if self.language in ("perl","perlpod"):
                line = 'line 1 "node:%s (%s)"' % (
                    self.nodeSentinelText(p),self.shortFileName)
                self.putSentinel(line)

        g.funcToMethod(putLineNumberDirective,
            leoAtFile.AtFile,"putOpenNodeSentinel")
        #@-<< override write methods >>
        #@+<< override read methods >>
        #@+node:ekr.20040419105219.2: ** << override read methods >>
        # readNormalLine = leoAtFile.AtFile.readNormalLine

        # def skipLineNumberDirective(self, s, i):

            # if linere.search(s):
                # return  # Skipt the line.
            # else:
                # readNormalLine(self,s,i)

        # g.funcToMethod(skipLineNumberDirective,
            # leoAtFile.AtFile,"readNormalLine")
        #@-<< override read methods >>
        g.plugin_signon(__name__)
    return ok
Exemple #28
0
def init():

    ok = not g.unitTesting
    # Not for unit testing: overrides core methods.
    if ok:
        if 0:
            #@+<< override the LeoFrame class >>
            #@+node:edream.110203113231.917: *3* << override the LeoFrame class >>
            class myLeoFrame(leoFrame.leoFrame):

                if 0:

                    def __init__(self, title=None):
                        g.pr("myLeoFrame ctor", title)
                        leoFrame.leoCoreFrame.__init__(self, title)

            leoFrame.LeoFrame = myLeoFrame
            #@-<< override the LeoFrame class >>
        if 0:
            #@+<< override methods of the LeoApp class >>
            #@+node:edream.110203113231.918: *3* << override methods of the LeoApp class >>
            oldAppCloseLeoWindow = g.app.closeLeoWindow

            def myAppCloseLeoWindow(self, frame):

                global oldAppCloseLeoWindow

                oldAppCloseLeoWindow(frame)
                g.trace("after closeLeoWindow")

            g.funcToMethod(myAppCloseLeoWindow, leoApp.LeoApp,
                           "closeLeoWindow")
            #@-<< override methods of the LeoApp class >>
        g.plugin_signon(__name__)

    return ok
Exemple #29
0
def onStart(tag, keywords):

    # insert function insertUser as method of class Commands at runtime
    g.funcToMethod(insertUser, leoCommands.Commands)
    g.funcToMethod(insertOKcmd, leoCommands.Commands)
def undirect (c):

    log = c.frame.log.__class__

    g.funcToMethod(c.script_io_to_body_oldput,log,"put")
    g.funcToMethod(c.script_io_to_body_oldputnl,log,"putnl")
Exemple #31
0
def onStart(tag, keywords):

    from leo.core import leoNodes

    g.funcToMethod(newMoreHead, leoNodes.VNode, "moreHead")
Exemple #32
0
def onStart(tag, keywords):

    # g.trace("replacing openWithTempFilePath")

    g.funcToMethod(openWithTempFilePath, leoCommands.Commands,
                   "openWithTempFilePath")
def onStart (tag,keywords):

    # g.trace("replacing openWithTempFilePath")

    g.funcToMethod(openWithTempFilePath,leoCommands.Commands,"openWithTempFilePath")
Exemple #34
0
    # Pyflakes will complaint about * imports.
    #
    # pylint: disable=unused-wildcard-import,wildcard-import
    #
    # Set the isQt* constants only if all required imports succeed.
    try:
        if 0:  # Testing: Force Qt5.
            raise AttributeError
        from leo.core.leoQt6 import *  # type:ignore

        #
        # Restore the exec_method!
        def exec_(self, *args, **kwargs):
            return self.exec(*args, **kwargs)

        # pylint: disable=c-extension-no-member
        g.funcToMethod(exec_, QtWidgets.QWidget)
        isQt6 = True
        # print('\n===== Qt6 =====')
    except Exception:
        # g.es_exception()
        try:
            from leo.core.leoQt5 import *  # type:ignore
            isQt5 = True
            # print('\n===== Qt5 =====')
        except Exception:
            # print('===== No Qt =====')
            if g.app.gui.guiName() == 'qt':
                print('Can not load pyQt5 or pyQt6')
#@-leo
def redirect(c):

    log = c.frame.log.__class__

    g.funcToMethod(newPut, log, "put")
    g.funcToMethod(newPutNl, log, "putnl")
Exemple #36
0
def onStart(tag, keywords):

    import leo.core.leoNodes as leoNodes

    g.funcToMethod(newMoreHead, leoNodes.vnode, "moreHead")
Exemple #37
0
    def load_pyzo(self):
        '''
        Go through pyzo's *entire* startup logic with monkey-patches to
        integrate pyzo with Leo.
        
        Called by the the top-level init() function in pyzo_support.py.
        '''
        sys.argv = []
        # Avoid trying to load extra files.
        #
        # Part 1. Do *extra* early imports before calling pyzo.start.
        #         These are needed so we can monkey-patch main.MainWindow.
        g.pr('\nload_pyzo: EARLY imports...')
        #
        # For MainWindow.__init__.
        from pyzo.core import commandline, main, splash
        # This imports...
        # pyzo.core.main.py
        # pyzo.core.icons.py
        # pyzo.core.splash.py
        #
        # For MainWindow._populate.
        from pyzo.codeeditor.misc import callLater
        # This imports...
        # pyzo.codeeditor
        # pyzo.codeeditor.parsers
        # pyzo/codeeditor/base.py
        # pyzo.codeeditor.highlighter.py
        g.pr('load_pyzo: AFTER early imports')
        #
        # Part 2: Add aliases for MainWindow. __init__.
        loadAppIcons = main.loadAppIcons
        loadIcons = main.loadIcons
        loadFonts = main.loadFonts
        SplashWidget = splash.SplashWidget

        #
        # Part 3: Define the monkey-patched functions.
        #@+others
        #@+node:ekr.20190421025254.1: *4* patched: MainWindow.__init__
        def __init__(self, parent=None, locale=None):
            '''
            A monkey-patched version of MainWindow.__init__.py.
            
            Copyright (C) 2013-2018, the Pyzo development team.
            '''
            if g: g.pr('\nBEGIN PATCHED MainWindow.__init__')
            super().__init__(parent)
            # self.setObjectName('MainWindow') # EKR.

            self._closeflag = 0  # Used during closing/restarting

            # Init window title and application icon
            # Set title to something nice. On Ubuntu 12.10 this text is what
            # is being shown at the fancy title bar (since it's not properly
            # updated)
            self.setMainTitle()
            loadAppIcons()
            self.setWindowIcon(pyzo.icon)

            # Restore window geometry before drawing for the first time,
            # such that the window is in the right place
            self.resize(800, 600)  # default size
            self.restoreGeometry()

            # Show splash screen (we need to set our color too)
            w = SplashWidget(self, distro='no distro')
            self.setCentralWidget(w)
            self.setStyleSheet("QMainWindow { background-color: #268bd2;}")

            # Show empty window and disable updates for a while
            self.show()
            self.paintNow()
            self.setUpdatesEnabled(False)

            # Determine timeout for showing splash screen
            splash_timeout = time.time() + 1.0

            # Set locale of main widget, so that qt strings are translated
            # in the right way
            if locale:
                self.setLocale(locale)

            # Store myself
            pyzo.main = self

            # Init dockwidget settings
            self.setTabPosition(QtCore.Qt.AllDockWidgetAreas,
                                QtWidgets.QTabWidget.South)
            self.setDockOptions(QtWidgets.QMainWindow.AllowNestedDocks
                                | QtWidgets.QMainWindow.AllowTabbedDocks
                                #|  QtWidgets.QMainWindow.AnimatedDocks
                                )

            # Set window atrributes
            self.setAttribute(QtCore.Qt.WA_AlwaysShowToolTips, True)

            # Load icons and fonts
            loadIcons()
            loadFonts()

            # Set qt style and test success
            self.setQtStyle(None)  # None means init!

            # Hold the splash screen if needed
            while time.time() < splash_timeout:
                QtWidgets.qApp.flush()
                QtWidgets.qApp.processEvents()
                time.sleep(0.05)

            # Populate the window (imports more code)
            self._populate()

            # Revert to normal background, and enable updates
            self.setStyleSheet('')
            self.setUpdatesEnabled(True)

            # Restore window state, force updating, and restore again
            self.restoreState()
            self.paintNow()
            self.restoreState()

            # Present user with wizard if he/she is new.
            if False:  # pyzo.config.state.newUser:
                from pyzo.util.pyzowizard import PyzoWizard
                w = PyzoWizard(self)
                w.show(
                )  # Use show() instead of exec_() so the user can interact with pyzo

            # Create new shell config if there is None
            if not pyzo.config.shellConfigs2:
                from pyzo.core.kernelbroker import KernelInfo
                pyzo.config.shellConfigs2.append(KernelInfo())

            # EKR:patch Set background.
            if True:
                bg = getattr(pyzo.config.settings, 'dark_background',
                             '#657b83')
                # Default: solarized base00
                try:
                    self.setStyleSheet("background: %s" % bg)
                except Exception:
                    if g: g.pr('oops: PATCHED MainWindow.__init__')

            # Focus on editor
            e = pyzo.editors.getCurrentEditor()
            if e is not None:
                e.setFocus()

            # Handle any actions
            commandline.handle_cmd_args()

            if g: g.pr('END PATCHED MainWindow.__init__')

        # To force drawing ourselves
        #@+node:ekr.20190421034940.1: *4* patched: MainWindow._populate
        def _populate(self):
            '''
            A monkey-patched version of MainWindow._populate.
            
            Copyright (C) 2013-2018, the Pyzo development team
            '''
            if g: g.pr('\nBEGIN PATCHED MainWindow._populate')

            # Delayed imports
            from pyzo.core.editorTabs import EditorTabs
            from pyzo.core.shellStack import ShellStackWidget
            from pyzo.core import codeparser
            from pyzo.core.history import CommandHistory
            from pyzo.tools import ToolManager

            # Instantiate tool manager
            pyzo.toolManager = ToolManager()

            # Check to install conda now ...
            #from pyzo.util.bootstrapconda import check_for_conda_env
            #check_for_conda_env()

            # Instantiate and start source-code parser
            if pyzo.parser is None:
                pyzo.parser = codeparser.Parser()
                pyzo.parser.start()

            # Create editor stack and make the central widget
            pyzo.editors = EditorTabs(self)
            self.setCentralWidget(pyzo.editors)
            # EKR: QMainWindow.setCentralWidget

            # Create floater for shell
            self._shellDock = dock = QtWidgets.QDockWidget(self)
            if pyzo.config.settings.allowFloatingShell:
                dock.setFeatures(dock.DockWidgetMovable
                                 | dock.DockWidgetFloatable)
            else:
                dock.setFeatures(dock.DockWidgetMovable)
            dock.setObjectName('shells')
            dock.setWindowTitle('Shells')
            self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock)

            # Create shell stack
            pyzo.shells = ShellStackWidget(self)
            dock.setWidget(pyzo.shells)

            # Initialize command history
            pyzo.command_history = CommandHistory('command_history.py')

            # Create the default shell when returning to the event queue
            callLater(pyzo.shells.addShell)

            # Create statusbar
            if pyzo.config.view.showStatusbar:
                pyzo.status = self.statusBar()
            else:
                pyzo.status = None
                self.setStatusBar(None)

            # Create menu
            from pyzo.core import menu
            pyzo.keyMapper = menu.KeyMapper()
            menu.buildMenus(self.menuBar())

            # Add the context menu to the editor
            pyzo.editors.addContextMenu()
            pyzo.shells.addContextMenu()

            # Load tools
            if pyzo.config.state.newUser and not pyzo.config.state.loadedTools:
                pyzo.toolManager.loadTool('pyzosourcestructure')
                pyzo.toolManager.loadTool('pyzofilebrowser',
                                          'pyzosourcestructure')
            elif pyzo.config.state.loadedTools:
                for toolId in pyzo.config.state.loadedTools:
                    pyzo.toolManager.loadTool(toolId)

            if g: g.pr('END PATCHED MainWindow._populate\n')

        #@+node:ekr.20190418204559.1: *4* patched: MainWindow.closeEvent
        def closeEvent(self, event):
            '''
            A monkey-patched version of MainWindow.closeEvent.
            
            Copyright (C) 2013-2018, the Pyzo development team
            '''
            # pylint: disable=no-member, not-an-iterable
            # Pylint gets confused by monkey-patches.
            if g: g.pr('PATCHED MainWindow.closeEvent')

            # Are we restaring?
            # restarting = time.time() - self._closeflag < 1.0

            # Save settings
            pyzo.saveConfig()
            pyzo.command_history.save()

            # Stop command server
            commandline.stop_our_server()

            # Proceed with closing...
            result = pyzo.editors.closeAll()

            if 0:  # Force the close.
                if not result:
                    self._closeflag = False
                    event.ignore()
                    return
                self._closeflag = True

            # Proceed with closing shells
            pyzo.localKernelManager.terminateAll()

            for shell in pyzo.shells:
                shell._context.close()

            # Close tools
            for toolname in pyzo.toolManager.getLoadedTools():
                tool = pyzo.toolManager.getTool(toolname)
                tool.close()

            # Stop all threads (this should really only be daemon threads)
            import threading
            for thread in threading.enumerate():
                if hasattr(thread, 'stop'):
                    try:
                        thread.stop(0.1)
                    except Exception:
                        pass

            # Proceed as normal
            QtWidgets.QMainWindow.closeEvent(self, event)

            # Don't exit Leo!
            # if sys.version_info >= (3,3,0): # and not restarting:
            # if hasattr(os, '_exit'):
            # os._exit(0)

        #@-others
        #
        # Part 4: Early patches: *before* calling pyzo.start()
        g.funcToMethod(__init__, main.MainWindow)
        g.funcToMethod(_populate, main.MainWindow)
        #
        # Part 5: Do pyzo's official startup:
        #         - Does all pyzo imports
        #         - Instantiates all pyzo objects.
        pyzo.start()
        #
        # Part 6: Late patches: *after* calling pyzo.start()
        #         Late patches are safe because all pyzo imports have been done.
        g.funcToMethod(closeEvent, main.MainWindow)
        #
        # Part 7: Late inits.
        # Each PyzoController instance inits menus, etc.
        if 0:
            self.dump_pyzo_objects()
        if 0:
            self.reparent_dock()
def redirect (c):

    log = c.frame.log.__class__

    g.funcToMethod(newPut,log,"put")
    g.funcToMethod(newPutNl,log,"putnl")
Exemple #39
0
def onStart(tag, keywords):

    # insert function insertUser as method of class Commands at runtime
    g.funcToMethod(insertUser, leoCommands.Commands)
    g.funcToMethod(insertOKcmd, leoCommands.Commands)
def undirect(c):

    log = c.frame.log.__class__

    g.funcToMethod(c.script_io_to_body_oldput, log, "put")
    g.funcToMethod(c.script_io_to_body_oldputnl, log, "putnl")
Exemple #41
0
    def _populate(self):
        '''
        This method is based on pyzo code
        Copyright (C) 2013-2018 by Almar Klein.
        '''

        trace = False and g.pyzo_trace_imports

        # Delayed imports, exactly as in MainWindow._populate.
        if trace:
            g.pr('\n===== MainWindowShim._populate\n')
        from pyzo.core.editorTabs import EditorTabs
        from pyzo.core.shellStack import ShellStackWidget
        from pyzo.core import codeparser
        from pyzo.core.history import CommandHistory
        from pyzo.tools import ToolManager
        if trace:
            g.pr('\n===== MainWindowShim._populate: end of delayed imports\n')
            g.pr('initial_draw:', self.initial_draw)
            g.pr('    use_menu:', self.use_menu)
            g.pr('   use_shell:', self.use_shell)
        #
        # Instantiate tool manager
        pyzo.toolManager = ToolManager()
        #
        # Instantiate and start source-code parser
        if pyzo.parser is None:
            pyzo.parser = codeparser.Parser()
            pyzo.parser.start()
        #
        # Create editor stack and make the central widget
        pyzo.editors = EditorTabs(self)
        self.setCentralWidget(pyzo.editors)
        #
        # Create floater for shell
        self._shellDock = dock = QtWidgets.QDockWidget(self)
        if pyzo.config.settings.allowFloatingShell:
            dock.setFeatures(dock.DockWidgetMovable | dock.DockWidgetFloatable)
        else:
            dock.setFeatures(dock.DockWidgetMovable)
        dock.setObjectName('shells')
        dock.setWindowTitle('Shells')
        self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock)
        #
        # Create shell stack
        if self.use_shell:
            # Disabling the shell works.
            pyzo.shells = ShellStackWidget(self)
            dock.setWidget(pyzo.shells)
            pyzo.shells.menu = g.TracingNullObject(tag='pyzo.shells.menu')
            # To suppress menu events.
        else:
            pyzo.shells = g.TracingNullObject(tag='pyzo.shells')
        #
        # Initialize command history
        pyzo.command_history = CommandHistory('command_history.py')
        #
        # Create the default shell when returning to the event queue
        if self.use_shell:
            pyzo.core.main.callLater(pyzo.shells.addShell)
        #
        # Create statusbar
        if pyzo.config.view.showStatusbar:
            pyzo.status = self.statusBar()
        else:
            pyzo.status = None
            self.setStatusBar(None)
        #
        # Create the menu.
        if self.use_menu:
            from pyzo.core import menu
            pyzo.keyMapper = menu.KeyMapper()
            assert not isinstance(pyzo.keyMapper,
                                  (g.TracingNullObject, g.NullObject))
            # This should not be a Shim.
            menu.buildMenus(self.menuBar())
            pyzo.editors.addContextMenu()
            pyzo.shells.addContextMenu()
        else:
            # Shim:
            pyzo.shells = g.TracingNullObject(tag='pyzo.shells')
            pyzo.keyMapper = g.TracingNullObject(tag='pyzo.keyMapper')

            from pyzo.core.shellStack import ShellStackWidget

            def null_menu_callback(*args, **kwargs):
                pass  # g.trace(args, kwargs)

            # Apparently, doing nothing prevents the Shell from warming up.
            # For now, use_shell sets use_menu.
            assert not self.use_shell
            g.funcToMethod(null_menu_callback,
                           ShellStackWidget,
                           name='onShellStateChange')
            g.funcToMethod(null_menu_callback,
                           ShellStackWidget,
                           name='onShellDebugStateChange')
        #
        # Load tools
        if pyzo.config.state.newUser and not pyzo.config.state.loadedTools:
            pyzo.toolManager.loadTool('pyzosourcestructure')
            pyzo.toolManager.loadTool('pyzofilebrowser', 'pyzosourcestructure')
        elif pyzo.config.state.loadedTools:
            for toolId in pyzo.config.state.loadedTools:
                pyzo.toolManager.loadTool(toolId)
Exemple #42
0
def onStart (tag,keywords):

    import leo.core.leoNodes as leoNodes

    g.funcToMethod(newMoreHead,leoNodes.VNode,"moreHead")
Exemple #43
0
    def main_window_populate(self):
        """
        Simulate MainWindow._populate().
        
        This code, included commented-out code, is based on pyzo.
        Copyright (C) 2013-2019 by Almar Klein.
        """
        # EKR:change: replaces self in most places.
        main_window = g.app.gui.main_window

        # print('\nBEGIN main_window_populate\n')

        # EKR:change-new imports
        from pyzo.core.main import callLater

        # Delayed imports
        from pyzo.core.editorTabs import EditorTabs
        from pyzo.core.shellStack import ShellStackWidget
        from pyzo.core import codeparser
        from pyzo.core.history import CommandHistory
        from pyzo.tools import ToolManager

        # Instantiate tool manager
        pyzo.toolManager = ToolManager()

        # EKR: Disabled in original.
        # Check to install conda now ...
        # from pyzo.util.bootstrapconda import check_for_conda_env
        # check_for_conda_env()

        # Instantiate and start source-code parser
        if pyzo.parser is None:
            pyzo.parser = codeparser.Parser()
            pyzo.parser.start()

        # Create editor stack and make the central widget
        # EKR:change. Use None, not self.
        pyzo.editors = EditorTabs(None)

        # EKR:change. Create an Editors dock.
        self.make_global_dock('Editors', pyzo.editors)
        # self.setCentralWidget(pyzo.editors)

        # Create floater for shell
        # EKR:change: use a global *Leo* dock
        dock = g.app.gui.create_dock_widget(
            closeable=True,
            moveable=True,
            height=50,
            name='Shells',
        )
        # Old code
        # self._shellDock = dock = QtWidgets.QDockWidget(self)
        # if pyzo.config.settings.allowFloatingShell:
        # dock.setFeatures(dock.DockWidgetMovable | dock.DockWidgetFloatable)
        # else:
        # dock.setFeatures(dock.DockWidgetMovable)
        dock.setObjectName('shells')
        # dock.setWindowTitle('Shells')

        # EKR:change: Make the dock a *global* dock.
        main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock)
        # self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock)

        # Create shell stack
        # EKR:change. Use None, not self.

        # A hack: patch _get_interpreters_win
        if 1:
            import pyzo.util.interpreters as interps
            interps._get_interpreters_win = _get_interpreters_win

        pyzo.shells = ShellStackWidget(None)
        dock.setWidget(pyzo.shells)

        # Initialize command history
        pyzo.command_history = CommandHistory('command_history.py')

        # Create the default shell when returning to the event queue
        callLater(pyzo.shells.addShell)

        # EKR:change.
        pyzo.status = None
        # Create statusbar
        # if pyzo.config.view.showStatusbar:
        # pyzo.status = self.statusBar()
        # else:
        # pyzo.status = None
        # self.setStatusBar(None)

        from pyzo.core import menu
        pyzo.keyMapper = menu.KeyMapper()

        # EKR:change: Monkey-patch pyzo.keyMapper.setShortcut.
        g.funcToMethod(setShortcut, pyzo.keyMapper.__class__)