GtkWidgetPathの *_to_string() 関数が見つからないので、その内容を簡単に調べて問題をデバッグするにはどうすればよいですか? そのテキスト表現をコンソールに出力するのは素晴らしいことです。
2 に答える
1
あなたが正しいことを理解したら、次のようなものを置きたい
<Widget>#<Name>: <NameOfObject>#<Name>
The widget belongs to the following style classes: <listOfClasses>
Complete Path: <Path>
画面上の特定のウィジェット用。
仕事をする次の2つの関数を書きました。コードは他の言語に簡単に翻訳できる必要があり、リファレンスが手元にあれば一目瞭然です。
gchar *
widget_path_get_style_classes (GtkWidgetPath * path)
{
GSList *list;
gchar *str = NULL, *ptr;
list = gtk_widget_path_iter_list_classes (path, -1);
if (list == NULL)
return NULL;
do {
ptr = str;
str = g_strdup_printf (".%s", (gchar *) list->data);
str = g_strjoin (", ", str, ptr, NULL);
g_free (ptr);
} while (list = g_slist_next (list));
g_slist_free(list);
return str;
}
void
widget_path_dumper (GtkWidget * widget)
{
GtkWidgetPath *path;
guint i, length;
gchar *str;
GType type;
path = gtk_widget_get_path (widget);
length = gtk_widget_path_length (path) - 1;
type = gtk_widget_path_iter_get_object_type (path, length);
str = (gchar *) gtk_widget_path_iter_get_name (path, length);
if (str != NULL)
g_print ("<Widget>#<Name>: %s#%s\n", g_type_name (type), str);
else
g_print("<Widget>: %s\n", g_type_name(type));
str = widget_path_get_style_classes (path);
if (str != NULL) {
g_print
("\tThe widget belongs to the following style classes: %s\n", str);
g_free (str);
}
g_print ("\tComplete Path: ");
for (i = 0; i <= length; i++) {
type = gtk_widget_path_iter_get_object_type (path, i);
g_print ("/%s", g_type_name (type));
}
g_print ("\n");
}
例:
添付された ui ファイルwidget_path_dumper
のインスタンス化されたウィジェットを呼び出すと、button1
<Widget>#<Name>: GtkButton#myspecialbutton
The widget belongs to the following style classes: .button
Complete Path: /GtkWindow/GtkGrid/GtkFrame/GtkAlignment/GtkButton
画面上。
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="border_width">10</property>
<signal name="destroy" handler="gtk_main_quit" swapped="no"/>
<child>
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">out</property>
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_right">10</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="left_padding">12</property>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="name">myspecialbutton</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="use_action_appearance">False</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes"><b>frame1</b></property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
于 2013-08-11T11:38:04.857 に答える