wiki-mode: invisible text in a QTextEdit widget

317 views
Skip to first unread message

Terry Brown

unread,
Oct 28, 2014, 2:38:03 PM10/28/14
to leo-e...@googlegroups.com
Everyone seems to have different views of where the challenge is here,
but to me it's how, in a Qt QTextEdit widget, do you make some text
sometimes invisible, *without* a new layer of text loading / unloading
code that would be a huge pain to get right. So you text might be:

`Character formatting
<http://qt-project.org/doc/qt-5/qtextcursor.html#setCharFormat>`_

and you want to see just "Character formatting" without quotes, in a
different color.

But, from Leo and the QTextEditors perspective, you want the text to
just be what it is above, the long form.

Attached is a screen shot of my proof of concept so far. The sharp
eyed will notice a small dot before the 'S' in the second window.
That's because Qt ignores font-size = 0 or letter spacing = 0. So
that's what you get with font-size = 0.1 and letter spacing = 1
(percent). Code below. If we want them to be completely invisible we
can make them the background color.

If you cursor through this compressed text area the cursor seems to
stall as it moves through the 70 plus almost hidden chars. But that's
fine, because I think we'd want it to suddenly appear normal size if
you put the cursor in it anyway, so the weird stalling wouldn't be an
issue.

The advantages of this is that everything else just works, copy paste,
etc. etc.

Up top I show an rst example, but this approach can apply to other
syntaxes as well.

All the time I have for now.

Cheers -Terry

import sys
from PyQt4 import Qt

app = Qt.QApplication(sys.argv)

hello = Qt.QTextEdit()

hello.setText("""First

file:///home/tbrown/t/Proj/GLRI/Monitor/esriapp/doc/build/html/deploy.html
Second One

Third""")

hello.show()

doc = hello.document()
curse = Qt.QTextCursor(doc)

cfmt = Qt.QTextCharFormat()
cfmt.setFontPointSize(23)

while True:
print curse.block().text()
if 'Second' in curse.block().text():
curse.movePosition(curse.Right)
curse.movePosition(curse.Right, curse.KeepAnchor, 74)
cfmt = curse.charFormat()
cfmt.setFontPointSize(0.1)
cfmt.setFontLetterSpacing(1)
curse.setCharFormat(cfmt)
print 'SET'
if not curse.movePosition(curse.NextBlock):
break

app.exec_()
c.png

Terry Brown

unread,
Oct 28, 2014, 2:43:45 PM10/28/14
to leo-e...@googlegroups.com
On Tue, 28 Oct 2014 13:37:26 -0500
"'Terry Brown' via leo-editor" <leo-e...@googlegroups.com> wrote:

> Up top I show an rst example, but this approach can apply to other
> syntaxes as well.

Including one we make up to jump around inside Leo docs. - we already
have UNLs that work this way.

Cheers -Terry

karh...@gmail.com

unread,
Oct 28, 2014, 3:17:07 PM10/28/14
to leo-e...@googlegroups.com
On Tuesday, October 28, 2014 6:38:03 PM UTC, Terry Brown wrote:
Everyone seems to have different views of where the challenge is here,
but to me it's how, in a Qt QTextEdit widget, do you make some text
sometimes invisible, *without* a new layer of text loading / unloading
code that would be a huge pain to get right.

Just wondering, how do wiki engines generally manage to make some text invisible? If this issue indeed is the major stumbling block towards implementing wiki-like links, it's worth looking around and find out how the others solved it, rather than just trying to re-invent the wheel.

Cheers

Serg

Terry Brown

unread,
Oct 28, 2014, 4:11:02 PM10/28/14
to leo-e...@googlegroups.com
Good question. Most wikis / wiki editors are HTML editors, where
there is what you see and the entirely different underlying HTML
markup, where any amount of auxiliary information like URLs can be
safely stored. Leo is a *text* editor, the body editor content needs to
behave like plain text for most of what Leo does.

So the question would be how have *text* editors solved this in the
past. Things like Tomboy notes, but that's really a custom widget
specifically for this use case. Do vim or Emacs do this kind of
thing? And even if they did have solutions (I don't know), we need a
Qt solution.

So I can't think of any cases where this has been handled before.

Come to think of it, it's not just making

`Character formatting <http://qt-.org/.../qtextcursor.html#setChar>`_
appear as 'Character formatting' that would be cool, but

\subsubsection{Other steps}
(from LaTeX) could be presented as just 'Other steps', etc. - I'm sure
there are applications we haven't thought of.

Cheers -Terry
Reply all
Reply to author
Forward
0 new messages