简体   繁体   English

PyGObject GTK + GLib.Date strftime()

[英]PyGObject GTK+ GLib.Date strftime()

A method call in Poppler returns a GDate object in my Python code. Poppler中的方法调用在我的Python代码中返回GDate对象。 I cannot find a way how to nicely print this object. 我找不到一种方法来很好地打印此对象。

Following the Python GI API Reference , I came up with the following: 遵循Python GI API参考 ,我提出了以下内容:

gdate_object = annot_mapping.annot.get_date()
destination_buffer = '.' * 50
print('Output:', GLib.Date.strftime(destination_buffer, 50, '%c', gdate_object))
print('Buffer:', annot_time)

However, this places nothing in the buffer, while it does output the written buffer size. 但是,这不会在缓冲区中放置任何内容,但输出写入的缓冲区大小。

How do I get access to the destination buffer? 如何访问目标缓冲区?

Looks like nobody documented that API so it will be broken for introspection bindings. 似乎没有人记录该API,因此将无法进行自省绑定。

I made a simple patch but it seems pygobject doesn't like allocating string buffers, I will talk with upstream about it. 我做了一个简单的补丁,但pygobject似乎不喜欢分配字符串缓冲区,我将在上游与之讨论。

diff --git a/glib/gdate.c b/glib/gdate.c
index bea2448..bacdb93 100644
--- a/glib/gdate.c
+++ b/glib/gdate.c
@@ -2418,8 +2418,8 @@ win32_strftime_helper (const GDate     *d,

 /**
  * g_date_strftime:
- * @s: destination buffer
- * @slen: buffer size
+ * @s: (out caller-allocates) (array length=slen): destination buffer
+ * @slen: (in): buffer size
  * @format: format string
  * @date: valid #GDate
  *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM