在布局上绘制我自己的对象:子类化 gtk.drawable 的问题
我想在布局上绘制自己的对象,所以我尝试子类化 gdk.drawable,
class link(gtk.gdk.Drawable):
def __init__(self,comp1,comp2,layout):
super(link, self).__init__()
self.x1=comp1.xpos
self.y1=comp1.ypos
self.x2=comp2.xpos
self.y2=comp2.ypos
self.layout=layout
错误:
无法创建抽象(不可实例化)类型“GdkDrawable”的实例
我可以在链接对象的方法drawlink()中使用layout.bin_window.draw_line()子类化可绘制对象来做到这一点,但我无法创建自定义每个对象的图形上下文 gdk.gc ,我必须使用layout.get_style(),这对于我的所有链接都是相同的!
def drawlink(self):
gc = self.layout.get_style().fg_gc[gtk.STATE_NORMAL]
gc.line_style=gtk.gdk.LINE_ON_OFF_DASH
gc.line_width=6
self.layout.bin_window.draw_line(gc,self.x1, self.y1, self.x2, self.y2)
这就是我想要子类化drawable的原因。如果我可以使用自定义 gc 而无需子类化可绘制对象或(窗口,像素图),那就太好了。
谢谢
I want to draw my own object on a layout, so I'm trying to subclass gdk.drawable,
class link(gtk.gdk.Drawable):
def __init__(self,comp1,comp2,layout):
super(link, self).__init__()
self.x1=comp1.xpos
self.y1=comp1.ypos
self.x2=comp2.xpos
self.y2=comp2.ypos
self.layout=layout
error:
cannot create instance of abstract (non-instantiable) type `GdkDrawable'
I can do it without subclassing drawable using layout.bin_window.draw_line() in a method drawlink() of my link object, but I'm not able to create a custom graphic context gdk.gc for each object and I have to use the layout.get_style() which will be the same for all my links!
def drawlink(self):
gc = self.layout.get_style().fg_gc[gtk.STATE_NORMAL]
gc.line_style=gtk.gdk.LINE_ON_OFF_DASH
gc.line_width=6
self.layout.bin_window.draw_line(gc,self.x1, self.y1, self.x2, self.y2)
this is the reason I want to subclass drawable. if I can use a custom gc without subclassing drawable or(window, pixmap) it would be great.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,您想要做的不是子类化 gtk.gdk.Drawable 而是填充
gtk.DrawingArea
小部件 包含您自己的内容。该小部件的描述是:If I understand you correctly, what you want to do is not subclassing
gtk.gdk.Drawable
but populating agtk.DrawingArea
widget with your own content. The description of that widget is: