找出wx.richtext.RichTextCtrl在不滚动的情况下可以显示多少行
我正在用 Python + wxPython 编写一个电子书阅读器,我想知道在给定的 RichTextCtrl 中可以在不滚动的情况下以当前格式显示多少行文本。
我想过使用控件的高度并将其除以 RichTextCtrl.GetFont().GetPixelSize()
,但似乎 wx.Font
的像素大小参数仅在Windows 和 GTK。此外,这不会覆盖行/段落之间的任何额外垂直间距。
我当然可以获取以点为单位的字体大小,尝试以 ppi 为单位获取显示器的分辨率,然后这样做,但是 1)行间距问题仍然存在,2)对于类似的东西来说,这是一个太低的抽象级别这。
有没有明智的方法来做到这一点?
编辑:目标是将电子书分为页面,因此滚动单位是整个页面,而不是一行。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PageDown 的源代码 方法表明没有一种明智的方法可以做到这一点...
这是我的疯狂提议(它破坏了小部件内容、插入符、显示位置...),它滚动一页并测量此滚动的长度。 ..
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...
您是否尝试调用 GetNumberOfLines() 方法?根据 Robin Dunn 的说法,这应该可行,尽管它没有考虑换行。
Did you try calling the GetNumberOfLines() method? According to Robin Dunn, that should work, although it doesn't take wrapped lines into account.