File: pymailgui-products/unzipped/Launch_PyEdit.pyw
#!/usr/bin/python3 """ ============================================================================= Bonus program: launch the embedded PyEdit text editor for standalone use. *Update* - PyEdit is now also available in standalone form, as source, Mac app, and Windows and Linux executable: see learning-python.com/pyedit. The nested version launched here is the same as the source package. PyEdit is used by and shipped with PyMailGUI for displaying text in both mail View/Write windows and miscellaneous popups, but it can also be used as a general text editor independently of PyMailGUI. PyEdit is fairly basic by modern editor standards, though it is also cross-platform and open source, and features flexible Unicode, tailorable auto-saves, fonts and colors, external-file search, Python program-code execution, and more. PyEdit comes from the book Programming Python, 4th Edition, but has been enhanced here in numerous ways for PyMailGUI 4.0 (details in its source code; as of May, 2017, PyEdit's code is over 3 times larger than its book version). This launcher script doesn't require Python 3.X, but the spawned PyEdit does. It accepts an optional filename argument, passed on to PyEdit's main script (not normally used, except for pyedit.bat clicks on Windows per below). See also: 1) textConfig.py in PyEdit's source dir, named below, for all end-user configuration settings. These are used to customize initial colors, fonts, sizes, auto-save folder, and Unicode policies and behavior. 2) pyedit.bat here, to open text files with PyEdit when clicked in a Windows file explorer window. See that file for usage instructions. It passes a filename to sys.argv (but on Mac, OpenDoc events are used). 3) Your system's support for shortcuts (Windows) or aliases (Mac OS X): use this to install this script on your desktop for quick access. 4) Stand-alone app and exe distributions of PyEdit, which more readily support filename-association opens, document drag-and-drop, and more. Coding note: we wait() for the spawned PyEdit to exit here, in order to keep its streams valid; else, code run by all PyEdit Run Code except Capture fails on inputs when using this launcher (but not when running PyEdit's main script directly). This is not done in PyMailGUI's launcher, because it (and thus its grandparent streams) are generally longer-lived, and PyEdit is less likely to be used for programming in this context: it impacts PyEdit's Run Code console streams iff console-run launcher closed. 4.0.1: no need to route child stdout/err to /dev/null for Mac apps here, because the parent is kept alive manually (for a prior console use case). ============================================================================= """ import subprocess, os, sys # launcher may have been run from a cmdline elsewhere mypath = os.path.dirname(os.path.abspath( __file__ )) # != os.getcwd()? # no need to use pyw to suppress console on Windows (if subprocess) unixpath = 'PyMailGui-PP4E/PP4E/Gui/TextEditor/textEditor.py' localpath = unixpath.replace('/', os.sep) # change to '\' on Windows abspath = os.path.join(mypath, localpath) # add launcher's path prefix scriptpath = os.path.dirname(abspath) # where to run: dir scriptfile = os.path.basename(abspath) # what to run: file # use sequence: args auto-quoted cmdline = [sys.executable, scriptfile] # use python path for unixen cmdline += sys.argv[1:] # pass along filename, if given sub = subprocess.Popen(cmdline, cwd=scriptpath) # cd to dir for imports, etc sub.wait() # retain streams for Run Code