The following behavior can be observed, on both Ubuntu and Windows, using 
slight variant of Terry's benchmark script.  See the P.S.

I notice the following behavior while loading big text (20K lines or more) 
in Leo, but alas, it happens also with the benchmark script.

**Important**: this script has nothing to do either with Leo or syntax 
coloring: this is a pure Qt text issue.

===== Flaw number 1: data loss

To see the bug, do the following:

1. Run the bench mark: python benchmark.py.  A window appears.

2. Click the "Add Text" button.

3. Now click the text area until text appears.

4.  Immediately click again to set the cursor and then type <return>.

5.  Type Ctrl-End to put the cursor at the end of the text.

6.  Notice that there are less than the 500000 lines of text.  Alas, the 
text never gets updated after you type the first <return>.  Boo hoo.

Folks, this is data loss.  There seems to be no way to distinguish the 
missing lines of text produced by the <return> character from any other 
text deletion.

This looks like a fatal flaw in the QTextEdit class. To repeat, it exists 
in both Ubuntu and Windows.  It is not a trait of the underlying OS widget.

We (probably) haven't noticed this loss in Leo because the initial update 
of small body text happens quickly.

===== Flaw number 2: wretched performance

While researching this sad state of affairs, I copied large text into the 
Scite text editor.  It was shocking to see that the text appears 
*instantly* and fully colored.  To me, this could be called a second fatal 
flaw in QTextEdit: it's just way too slow.

===== Time to use QScintilla?

As a result, I have begun investigating QScintilla: 
http://qt-project.org/wiki/QScintilla  Note that some people already use 
QScintilla in Leo.  I think it's time to consider ways to make QScintilla 
Leo's default editor.  At the least, this would involve extending 
QScintilla's syntax coloring to handle Leo's extra markup.  There are 
indications that this may be possible: 
http://www.scintilla.org/ScintillaDoc.html

This is a good time to consider switching to scintilla: the PQSH class 
gives Leo great control over syntax coloring: a modification of this class 
should be able to drive scintilla syntax coloring as desired.  Otoh, it 
remains to be seen what kind of text-changed notifications scintilla can 
generate: there are no guarantees.

Your comments, please, Amigos.

Edward

P.S.  Here is the script I used to show the problem. ### mark the 
substantial changes from Terry's script.

import sys
import time
from PyQt4 import QtGui

def add_text(w,s):
    start = time.time()
    ### w.setText(s)
    w.setPlainText(s) ### No guessing: should be faster, so harder to 
demonstrate the bug.
    w.update()
    print(time.time()-start)

app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
l = QtGui.QVBoxLayout()
w.setLayout(l)
tw = QtGui.QTextEdit()
b = QtGui.QPushButton('Add text')
l.addWidget(tw)
l.addWidget(b)
w.resize(800,800)
s = '\n'.join(["This is one line %s of text here"%(i+1)
    for i in range(500000)]) ###
b.clicked.connect(lambda checked: add_text(tw,s))
w.show()
exit(app.exec_())

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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to