On Saturday, February 4, 2017 at 3:21:26 AM UTC-6, Edward K. Ream wrote: Hiding <img> tags will use the same machinery as hiding parts of urls. But > full support for pictures will involve numerous complications. >
*tl;dr:* No plan survives contact with the enemy. But the battle is not lost. *Using explicit <img> elements seems dubious* The immediate problem is that there appears to be no way to update a text line during colorizing. That is, there is no methods on QDocument or QTextBlock that will update the present block. Blocks look like they are read-only. Sure, it would be possible to call body.widget.setAllText in the colorizer, but that seems extreme. *Pasting images directly into QTextEdit is easy* I found an excellent resource here <http://stackoverflow.com/questions/3254652/>on stack overflow. The following code works: from leo.core.leoQt import QtGui body = c.frame.body table = ( 'application-x-leo-outline.png', 'LeoDoc.ico', ) d = g.app.permanentScriptDict images = d.get('images', []) for image in table: path = g.os_path_finalize_join(g.app.loadDir, '..', 'Icons', image) assert g.os_path_exists(path), repr(path) image = QtGui.QImage(path) images.append(image) body.wrapper.setInsertPoint(len(p.b)) cursor = body.widget.textCursor() cursor.insertImage(image) for i, ch in enumerate(p.b): if ord(ch) > 128: print('new', i, ord(ch)) d ['images'] = images # # *Notes* 1. The four image characters at the end were preserved across invocations of Leo, but they aren't visible on reload. 2. The script saves references to images in g.app.permanentScriptDict, so once images are visible they *stay* visible. *A problem* I kinda expected this problem. If I run *another *version of this script, with *different* images, then images in newly-selected nodes correspond to the last *created *images, not necessarily the desired images. My mental model (possibly inaccurate) says that the QDocument for the widget associates image N with image character N. A possible solution would be to switch QDocuments when switching nodes. Another would be to use uA's to give QDocument some guidance. This would be more localized, but I have no idea how it would work. *The way forward* Inserting images directly into Leo's body text is the simplest thing that could possibly work from the user's point of view. Indeed, the stack-overflow page has a discussion of using canInsertFromMimeData and insertFromMimeData functions. These are prerequisites for cutting/pasting images. Inserting images directly into Leo's body text requires no changes at all to the colorizer. That's a good thing, because having the colorizer change text seems fraught with danger. The big question is whether Leo can help QDocument show the correct image when switching node. If the answer is yes, then Leo will use uA's to make images persistent when Leo reloads a .leo file. I am going to do everything I can to make this strategy successful. It's worth any amount of work. Edward P. S. The colorizer will still hide UNLs and URLs as previously discussed. EKR -- 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.