在 gtk.TextView 上画线
我试图显示某个子字符串的“选择” gtk.TextView 通过在单词周围绘制边框。唯一的标记方法 到目前为止我发现的 TextView 中的文本是通过将 TextTags 放置 修改的属性。这似乎没有提供一种绘制边界的方法, 不过,GTK 支持这个还是 ONLT PYGTK 有问题
I'm trying to show the "selection" of a certain sub-string in a
gtk.TextView by drawing a border around the word. The only way to mark
text in a TextView that I've found so far is by placing TextTags with
modified properties. This does not seem to offer a way to draw a border,
though, DOES GTK SUPPORT THIS OR IS THIS A PROBLEM WITH ONLT PYGTK
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想出了如何在文本视图上绘图!
首先,让我们假设对 gtk.TextView 的引用位于一个名为“viewer”的变量中,位于您的一个类中
另外,绘图函数必须使用名为“expose-event”的事件来调用,否则绘图将被刷新并且不会保留在屏幕上。
下一部分是 gtk.TextView,它由 7 种类型的 gtk.gdk.windows 组成,您可以在其中使用 gtk.gdk.windows。 示例
为了让绘图出现在 gtk.TextView 上,我们必须在 gtk.TEXT_WINDOW_TEXT 上绘图,
代码如下所示
I figured out how to draw on a text view !!!
To begin with lets assume the reference to your gtk.TextView is in a variable called viewer, Inside one of ur classes
Also the draw function has to be called with an event called expose-event else the drawings will be refreshed and will not stay on the screen
The next part is the gtk.TextView consists of 7 types of gtk.gdk.windows on which u can draw
For the drawing to appear on gtk.TextView We have to draw on gtk.TEXT_WINDOW_TEXT
An Example Code is as shown Below
在
gtk.TextBuffer
标签中,用于设置一个或多个预定义的文本属性。如果没有子类化,这仅限于 gtk.TextTag 的属性,并且不包括类似于边框或轮廓属性的任何内容。在这方面,PyGTK 和普通 GTK+ 没有区别。虽然有点 hacky,但完成您想做的事情的最简单方法是连接到
gtk.TextView
的expose-event
,获取字符串的坐标并绘制在event.window
上,这是公开回调中提供的事件的gdk.Window
。(请注意,您不必获取并存储 gtk.TEXT_WINDOW_TEXT 窗口,您只需在回调中检查暴露事件适用于哪个窗口,如果不是针对文本窗口,则可能会忽略该暴露。)
相反,您大概可以子类化 TextBuffer/TextView/TextTag 中的一个或多个来添加
border
标记,但这样做是否合理是另一个问题。In a
gtk.TextBuffer
tags are used to set one or more pre-defined text attributes. Without subclassing, this is limited to the properties of agtk.TextTag
, and doesn't include anything akin to a border or outline property. There is no difference between PyGTK and plain GTK+ in this regard.While somewhat hacky, the easiest way to do what you want to do is to connect to the
expose-event
of yourgtk.TextView
, get the coordinates of your string and draw onevent.window
, which is thegdk.Window
of the event provided in the expose callback.(Note that you don't have to get and store the gtk.TEXT_WINDOW_TEXT window, you just need to check what window the expose event is for in the callback, probably ignoring the expose if it's not for the text window.)
Instead, you could presumably subclass one or more of TextBuffer/TextView/TextTag to add a
border
tag, but whether it's reasonable to do so is another question.