Moving pyzo features into Leo promises to be easier than expected. This Engineering Notebook post discusses recent good news.
*pyzo.leo* This has already been well worth the effort required to create. You can find it in my clone of pyzo <https://github.com/edreamleo/pyzo>. pyzo.leo allows me to change pyzo at will, safely, since everything is in the git repo. *Startup* Yesterday I started investigating the pyzo code in earnest. I use a script, pz.bat, to start pyzo from a console: python <path to>\pyzo\source\pyzo\__main__.py The name pz.bat prevents conflicts with pyzo's own startup script, which executes pyzo.exe. pyzo.exe is "frozen", which prevents any changes from taking effect. In contrast, invoking pyzo as shown above allows me to change pyzo at will. Print statements go to the console only when started as above. *Imports* Pyzo's import structure seems unlikely to hinder using any of the code that I want to move into Leo. *Settings* Pyzo stores various settings, including user settings, in config.ssdf. This is a flat representation of a python dict. pyzo/utils/zon.py parses that file into the actual python dict. Details don't matter, since Leo will never use this code. What does matter is how pyzo accesses the dict and what the dict contains. *pyzo.config* is the entire dict, *pyzo.config.state* contains internal pyzo state, and *pyzo.config.settings* contains user settings. I added code to handle pyzo.config.settings.dark_theme and pyzo.config.settings.dark_background. This allows me to specify that pyzo should use a (solarized) dark theme and, when that is in effect, what background to use for all panes *except* text panes. This gave me experience with how pyzo updates config.ssdf. The real gold is in pyzo.config.state. Here are the important parts, edited, as shown by g.printObj(pyzo.config.state): { editorState2:[ ['C:\\apps\\pyzo\\source\\pyzo\\codeeditor\\highlighter.py', 3279, 96], ['C:\\apps\\pyzo\\source\\pyzo\\core\\editorTabs.py', 22913, 693], ['C:\\apps\\pyzo\\source\\pyzo\\codeeditor\\highlighter.py', 'hist' ], ['C:\\apps\\pyzo\\source\\pyzo\\core\\editorTabs.py', 'hist'] ], loadedTools:['pyzofilebrowser', 'pyzologger', 'pyzosourcestructure'], windowGeometry:'an array of bytes', windowState:['an array of byte strings'] } Pyzo uses these settings to recreate the arrangement of panes on startup. Leo must do something similar! A big Aha came from doing a cff on windowState. QMainWindow has saveState and restoreState methods that can do most of the work or saving and restoring windows!! I haven't studied the details of how all this works, but it looks as though Qt can do most the work for us. This is a big deal. *Colorizing Leo using pygments* Pyzo has a very simple syntax coloring loop, based on a stream of tokens. The guts of the main loop are: tokens = list(parser.parseLine(line, previousState)) for token in tokens : styleFormat = nameToFormat(token.name) charFormat = styleFormat.textCharFormat self.setFormat(token.start,token.end-token.start,charFormat) This suggests that Leo should use pygments to deliver a stream of tokens. The "hello world" pygments example is: code = 'print "Hello World"' print(highlight(code, PythonLexer(), HtmlFormatter())) But this too much. Instead, the following suffices!: for token in PythonLexer().get_tokens(p.b): kind, val = token print('%35r %r' % (kind, val)) This will eliminate *all* of Leo's syntax coloring pattern matchers, and all the files in leo/modes! Leo's code will be more complex than pyzo's, for at least the following reasons: - @language directives are heritable. - Leo nodes may have multiple @language directives. - Leo nodes may have @nocolor and @killcolor directives. Furthermore, Leo's settings related to syntax coloring use the jedit terms, not pyzo terms. So a "redirection" of style names must be done somewhere. In any case, Leo's syntax coloring code can use pygments relatively easily. *Next steps* I want to understand the following: - How pyzo allows users to drag pyzo "tool" windows around the screen. - How pyzo (and Qt) save/restore the positions of tool windows. This will allow Leo to use the same scheme. *Summary* I have now entered the "acceleration" phase of study. I have full control over pyzo's sources. I can modify them, single step through them and trace them. I understand pyzo's settings machinery in all essential aspects. Qt's QMainWindow.save/restoreState do the heavy lifting involved in loading/saving "sessions". I'll be studying exactly how this all works. Leo should be able to do the same, with relatively little effort. Leo's syntax coloring code can use pygments relatively easily. Edward -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+unsubscr...@googlegroups.com. To post to this group, send email to leo-editor@googlegroups.com. Visit this group at https://groups.google.com/group/leo-editor. For more options, visit https://groups.google.com/d/optout.