내 맞춤 위젯 용 Python을 사용하여 GTK에 Heigh-for-width Geometry Management을 구현하려고합니다. 내 위젯은 Gtk.DrawingArea
의 하위 클래스이며 이미지의 일부분을 그립니다.PyGObject의 가상 메소드 오버라이드
I는 GTK 문서 (위 링크) I는 다음의 4 개 가지 방법을 구현할 필요가 이해할 수있는 바와 같이 :
- GtkWidgetClass.get_preferred_width()를
- GtkWidgetClass.get_preferred_height()
- GtkWidgetClass.get_preferred_height_for_width()
- GtkWidgetClass.get_preferred_width_for_height()
이 이제 원 여기서 파이썬으로 이것을 구현할 수 있습니다.
나는이 시도 :from gi.repository import Gtk
class Patch(Gtk.DrawingArea):
def __init__(self, model, image, position):
super(Patch,self).__init__()
#…
def get_preferred_width(self, *args, **kargs):
print("test")
def get_preferred_height(self, *args, **kargs):
print("test")
def get_preferred_width_for_height(self, *args, **kargs):
print("test")
def get_preferred_height_for_width(self, *args, **kargs):
print("test")
을하지만 방법이 호출되지 않습니다. C에서는 함수를 정의하고이 같은 위젯으로 설정 :이 파이썬에서
static void
my_widget_get_preferred_height (GtkWidget *widget, gint *minimal_height,
gint *natural_height)
{
/* ... */
}
/* ... */
static void
my_widget_class_init (MyWidgetClass *class)
{
/* ... */
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
widget_class->get_preferred_height = my_widget_get_preferred_height;
/* ... */
}
을 수행하는 방법?
pyGObject는 GObject-Introspection을 위해 더 이상 사용되지 않습니다. – liberforce
PyGObject가 Python에서 GObject-Introspection을 사용하는 방법이 아닙니까? PyGTK가 PyGObject를 위해 더 이상 사용되지 않는다는 것을 의미 했습니까? – thorink
@liberforce : GObject Introspection의 Python 구현은 PyGObject라고도합니다. PyGI라고 잠시 동안 불렀지 만, 지금은 공식 이름 인 것 같습니다. 오래된 PyGObject는 이제는 더 이상 사용되지 않는 PyGTK의 일부였습니다. (그러나 가상 메서드를 재정의하는 방법은 같았습니다.) – ptomato