我想将一个Gtk.Entry(已Gtk.EntryCompletion连接)打包到Gtk.TreeView. 有谁知道如何做到这一点?(我只需要对表格视图中的文本条目进行输入完成。)
Do I perhaps need to subclass Gtk.CellRenderer or Gtk.CellRendererText, and override the start_editing method (or similar)? I can find examples of subclassing Gtk.CellRenderer, but not modifying the editable behaviour. I can't find the source-code for the Gtk.CellRendererText class, either.
I'm using Gobject Introspection (i.e. from gi.repository import Gio, Gtk, GLib, Gdk).
配置gobject-introspection时找不到Python头文件.
我已经下载了tar:-----
gobject-introspection-1.34.2
Run Code Online (Sandbox Code Playgroud)
命令:-----
gobject-introspection-1.34.2$ LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:$LD_LIBRARY_PATH ./configure --disable-static
Run Code Online (Sandbox Code Playgroud)
错误:----
checking for python script directory... ${prefix}/lib/python2.7/dist-packages
checking for python extension module directory... ${exec_prefix}/lib/python2.7/dist-packages
checking for headers required to compile python extensions... not found
configure: error: Python headers not found
Run Code Online (Sandbox Code Playgroud)
如何解决此错误,请提出建议?
我正在使用glib的测试框架进行单元测试.我的库也使用了gobject,在我的测试unities中我想检查在每个对象的最后一次_unref之后是否正确释放了对象.当g_test_trap_fork可用时,我在每次_unref之后使用它,第二次调用_unref,然后检查g_test_trap_assert_failed().
但是,现在g_test_trap_fork正在被弃用,我正朝着g_test_trap_subprocess迈进.问题是现在我必须为每个要检查的_unref编写一个单独的测试用例,因为每个case都可以包含几个对象,这些对象意味着每个测试用例的重复,为每个已经存在的测试用例添加第二个_unref.
例如,我试图像这样修复:
NcmVector *v = test->v;
GVariant *var = ncm_vector_get_variant (v);
g_assert (!g_variant_is_floating (var));
g_assert (g_variant_is_container (var));
g_assert_cmpuint (ncm_vector_len (v), ==, g_variant_n_children (var));
{
NcmVector *nv = ncm_vector_new_variant (var);
gint i;
g_assert_cmpuint (ncm_vector_len (v), ==, ncm_vector_len (nv));
for (i = 0; i < ncm_vector_len (v); i++)
{
ncm_assert_cmpdouble (ncm_vector_get (v, i), ==, ncm_vector_get (nv, i));
}
ncm_vector_free (nv);
NCM_TEST_FAIL (ncm_vector_free (nv));
}
g_variant_unref (var);
NCM_TEST_FAIL (g_variant_unref (var); fprintf (stderr, "fail (%s)", g_variant_get_type_string (var)));
Run Code Online (Sandbox Code Playgroud)
宏NCM_TEST_FAIL由下式给出:
#define NCM_TEST_FAIL(cmd) \
G_STMT_START { …Run Code Online (Sandbox Code Playgroud) 我必须在Linux上为学校项目开发本机应用程序.我选择与GTK合作,我开始阅读官方指南.
GTK API本身很容易理解,但是我遇到了GObject和GLib的问题,它们很难学习,我不知道为什么它们习惯了.我应该学习GObject和GLib来使用GTK吗?
GObject官方文档是非常庞大的https://developer.gnome.org/gobject/stable/我需要几个星期才能学习GObject才能最终学习GTK.
我刚刚开始学习GTK。我正在查看gtk + 3.0.0的源代码,发现某些gtk对象类型的_get_type()方法的实现,但有些则没有此方法的实现,例如GtkRange。有什么理由吗?据《 GObject参考手册》了解,_get_type()方法在类型系统中注册对象类型。
我试图在python/gtk3中创建一个弹出菜单.到目前为止,我尝试了以下代码:
from gi.repository import Gtk
def show_menu(self, *args):
menu = Gtk.Menu()
i1 = Gtk.MenuItem("Item 1")
menu.append(i1)
i2 = Gtk.MenuItem("Item 2")
menu.append(i2)
i2.show()
i1.show()
menu.popup(None, None, None, None, 0, Gtk.get_current_event_time())
print("Done")
window = Gtk.Window()
button = Gtk.Button("Create pop-up")
button.connect("clicked", show_menu)
window.add(button)
window.show_all()
Gtk.main()
Run Code Online (Sandbox Code Playgroud)
但弹出菜单没有出现?我究竟做错了什么?
在GObject 手册的样板代码一章中,当使用G_DECLARE_FINAL_TYPE将 ViewerFile 声明为最终类型时,我们如何向其添加公共数据,因为它隐藏在未包含的viewer-file.c后面?
我想使用 GObject 调用的函数如下所示:
char * some_object_fun(SomeObject *self, char *input);
Run Code Online (Sandbox Code Playgroud)
有没有好的方法来实现这一目标?我对一个优雅的解决方案非常感兴趣。
我正在尝试为网络项目学习 glib 和 gObject。
这是用于编译的命令(使用 pkg-config 获取输出后):
gcc socket1.c -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgobject-2.0 -lglib-2.0
Run Code Online (Sandbox Code Playgroud)
socket1.c,剥离后,找出问题是:
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <gio/gio.h>
static GSocket *mySocket;
int main(int argc, char **argv) {
GError *err1 = NULL;
mySocket = g_socket_new ( G_SOCKET_FAMILY_IPV4,
G_SOCKET_TYPE_STREAM,
G_SOCKET_PROTOCOL_TCP,
&err1);
}
Run Code Online (Sandbox Code Playgroud)
错误是:
/tmp/ccKIEXOi.o: In function `main':
socket1.c:(.text+0x3d): undefined reference to `g_socket_new'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我尝试使用readelf -Ws 和nm来查看是否可以在链接的任何 .so 文件中看到 g_new_socket 。我没有看到任何。我需要链接到一个单独的图书馆吗?它在哪里/哪个?
我在做的油嘴一些严重的软件。我意识到有些主题我不太了解。IRC也无济于事...
当我们进行继承时,我们可以有两个类。第一个A直接从GObject继承,B直接从A继承。然后我来到这里:
https://developer.gnome.org/gobject/stable/chapter-gobject.html
static void
viewer_file_constructed (GObject *obj)
{
/* update the object state depending on constructor properties */
/* Always chain up to the parent constructed function to complete object
* initialisation. */
G_OBJECT_CLASS (viewer_file_parent_class)->constructed (obj);
}
static void
viewer_file_class_init (ViewerFileClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = viewer_file_constructed;
}
Run Code Online (Sandbox Code Playgroud)
但是,当你有这样的安排。子类执行此操作:object_class-> constructed = viewer_file_constructed; 实际上,在B覆盖中唯一构造的内存地址。因此,这意味着G_OBJECT_CLASS(viewer_file_parent_class)-> constructed(obj); 将调用B->递归构成。这不是我们想要的。
也许我听不懂,但我想B中的内存结构是这样的:
struct _B
{
A parent_instance;
/* instance members */
};
Run Code Online (Sandbox Code Playgroud)
内部表示应类似于:
[ Gobject struct memory ]
[ ]
[ …Run Code Online (Sandbox Code Playgroud) 我正在使用g_object_set_dataevent_box设置用户名,所以在回调中我可以在event_box指针中获取它.
g_object_set_data(G_OBJECT(event_box), "user_name", (gpointer)(user_name) );
Run Code Online (Sandbox Code Playgroud)
但问题是我设置的user_name不是指针分配的字符串.
它是一个本地字符串(未在臀部分配)被破坏.
所以有必要分配然后使用指针,我只想将一个名称与此event_box关联.