def main(): if TESTING: dt = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()) write(f"Testing Pyzo source ({dt} UTC)") write(platform.platform()) write(sys.version) write(f"Pyzo {pyzo.__version__}") pyzo.start() write("Stopped") # may be written to log twice because Pyzo defers stdout
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()
# The full license can be found in 'license.txt'. """ pyzolauncher.py script This is a script used to startup Pyzo. Added for convenience. Pyzo can be installed as a package, but it does not have to. You can start Pyzo in a few different ways: * execute this script (pyzolauncher.py) * execute the pyzo directory (Python will seek out pyzo/__main__.py) * execute the pyzo package ("python -m pyzo") Only in the latter must Pyzo be installed. """ import sys # faulthandler helps debugging hard crashes, it is included in py3.3 try: if sys.executable.lower().endswith("pythonw.exe"): raise ImportError("Dont use faulthandler in pythonw.exe") import faulthandler faulthandler.enable() except ImportError: pass import pyzo pyzo.start()
def main(): pyzo.start()
# The full license can be found in 'license.txt'. """ pyzolauncher.py script This is a script used to startup Pyzo. Added for convenience. Pyzo can be installed as a package, but it does not have to. You can start Pyzo in a few different ways: * execute this script (pyzolauncher.py) * execute the pyzo directory (Python will seek out pyzo/__main__.py) * execute the pyzo package ("python -m pyzo") Only in the latter must Pyzo be installed. """ import sys # faulthandler helps debugging hard crashes, it is included in py3.3 try: if sys.executable.lower().endswith('pythonw.exe'): raise ImportError('Dont use faulthandler in pythonw.exe') import faulthandler faulthandler.enable() except ImportError: pass import pyzo pyzo.start()