pythonwxpythonresolution-independence

Finding out how many lines can be displayed in wx.richtext.RichTextCtrl without scrolling


I'm writing an e-book reader in Python + wxPython, and I'd like to find out how many lines of text can be displayed in a given RichTextCtrl with the current formatting without scrolling.

I thought of using and dividing the control's height by RichTextCtrl.GetFont().GetPixelSize(), but it appears that the pixel size parameter of wx.Font is only specified on Windows and GTK. In addition, this won't cover any additional vertical spacing between lines/paragraphs.

I could of course get the font size in points, attempt to get the display's resolution in ppi, and do it that way, but 1) the line spacing problem still remains and 2) this is far too low a level of abstraction for something like this.

Is there a sane way of doing this?

EDIT: The objective is, to divide the ebook up into pages, so the scrolling unit is a whole page, as opposed to a line.


Solution

  • Source code of PageDown method suggest that there is not a sane way to do this...

    Here is my insane proposition (which breaks widget content, caret, displayed position...) which scroll one page and measure how long this scroll is...

    def GetLineHeight(rtc):
        tallString = "\n".join([str(i) for i in xrange(200)])
        rtc.SetValue(tallString)
        rtc.SetInsertionPoint(0)
        rtc.PageDown()
        pos = rtc.GetInsertionPoint()
        end = tallString.find("\n",pos)
        lineHeight=int(tallString[pos:end])
        return lineHeight