Body text pagesize hardcoded at 15 lines

21 views
Skip to first unread message

Brian Theado

unread,
Jan 22, 2012, 3:21:52 PM1/22/12
to leo-editor
I've long noticed page-up and page-down in the body text moves a fixed
15 lines at a time instead of a page at a time. My body text page
size is never 15 and I find it to be a nuisance.

I found the leoMoveCursorHelper method of the leoQTextEditWidget class
has a linesPerPage parameter which defaults to 15.

def leoMoveCursorHelper (self,kind,extend=False,linesPerPage=15):
[...]
if kind in ('page-down','page-up'):
cursor = w.textCursor()
cursor.movePosition(op,mode,linesPerPage)
w.setTextCursor(cursor)
[...]

I thought this would be easy to fix, but after long effort, I'm
stumped. I thought this would be easy because out of the box
QTextEdit has the behavior I want. The page-up and page-down keys
moves one screenful at a time. Here's some code which shows this:

import PyQt4.QtGui as QtGui
w = QtGui.QTextEdit()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('QTextEdit test')
for n in range(0,300):
w.insertPlainText('%d\n' % n)
w.show()
c.brian_test_w = w
# Now manually play with page-up, page-down, resize the window, etc.

I expected the docs would tell what the default keybindings are and
what public accessible methods are called by those bindings, but they
just tell the bindings:
http://developer.qt.nokia.com/doc/qt-4.8/qtextedit.html#editing-key-bindings

Maybe my next step should have been to dive into the QT source code,
but I thought that might be a rabbit hole and decided to try internet
searches instead. I got lost in the maze of QT class documentation
with little to show for it.

I did come up with this code which moves up 1 page:

sb = w.verticalScrollBar()
sb.setSliderPosition(sb.sliderPosition() - sb.pageStep())

but that doesn't actually move the text cursor--just the visible page
text. So the cursor would end up offscreen. Also, selecting text by
page (i.e. Shift-pageup/Shift-pagedown) would be broken. The method
w.textCursor().movePosition method needs to know the number of lines,
but w.verticalScrollBar().pageStep() returns the number of pixels. I
don't know how to convert from one to the other.

The answers to any of these questions would be helpful:

1. How to query the number of lines per page from a QTextEdit?
2. How to query the linenumber of the top-most and bottom-most visible
lines in QTextEdit?
3. How to find the height of each visible line in QTextEdit?
4. What code does the default Page-Up/Page-Down code call in QTextEdit?

Does anybody know or know a good way to find out?

Brian

Edward K. Ream

unread,
Jan 23, 2012, 11:24:21 AM1/23/12
to leo-e...@googlegroups.com
On Sun, Jan 22, 2012 at 2:21 PM, Brian Theado <brian....@gmail.com> wrote:

> I thought this would be easy to fix, but after long effort, I'm
> stumped.  I thought this would be easy because out of the box
> QTextEdit has the behavior I want.

I'm not too surprised. Qt's scrolling support classes are baroque.

One solution might be to hack Leo's key-binding code so that page
up/down keys get passed back to scrolling text widgets. But this will
not be easy, because of the complexity of Leo's key-handling code.

Edward

Brian Theado

unread,
Jan 31, 2012, 10:29:25 PM1/31/12
to leo-e...@googlegroups.com
On Mon, Jan 23, 2012 at 11:24 AM, Edward K. Ream <edre...@gmail.com> wrote:
[...]

>
> One solution might be to hack Leo's key-binding code so that page
> up/down keys get passed back to scrolling text widgets.  But this will
> not be easy, because of the complexity of Leo's key-handling code.

I looked at the QT C++ source code and found the functionality which
takes care of the paging. It looked to be a private(!) method so it
can't be called, I guess. However, the method was pretty
straightforward and only called public methods. So I ported the code
to python and replaced Leo's hard-coded 15 line scrolling with it.

I checked the code in and pushed to launchpad.

Brian

HansBKK

unread,
Jan 31, 2012, 11:50:54 PM1/31/12
to leo-e...@googlegroups.com
On Wednesday, February 1, 2012 10:29:25 AM UTC+7, btheado wrote:

I checked the code in and pushed to launchpad.

This may be premature, but does if this makes it to release, does this mean the # of lines per PgDn will be configurable?

Edward K. Ream

unread,
Feb 1, 2012, 11:39:07 AM2/1/12
to leo-e...@googlegroups.com
On Tue, Jan 31, 2012 at 9:29 PM, Brian Theado <brian....@gmail.com> wrote:

> I looked at the QT C++ source code and found the functionality which
> takes care of the paging.  It looked to be a private(!) method so it
> can't be called, I guess.  However, the method was pretty
> straightforward and only called public methods.  So I ported the code
> to python and replaced Leo's hard-coded 15 line scrolling with it.
>
> I checked the code in and pushed to launchpad.

Many thanks for this work. I'm not sure why I had so much trouble
merging your code, but just as a guess I think it was due to problems
on my side. Anyway, the code has survived the by-hand merges...

Edward

Edward K. Ream

unread,
Feb 1, 2012, 11:41:48 AM2/1/12
to leo-e...@googlegroups.com
On Tue, Jan 31, 2012 at 10:50 PM, HansBKK <han...@gmail.com> wrote:

> does this mean the # of lines per PgDn will be configurable?

As I read the code, it means that Leo will work just like typical
Qt.Text widgets do: which means that page up/down will "just work"
without any configuration needed.

Edward

Reply all
Reply to author
Forward
0 new messages