开发者

PyGTK Curve memory error

i need to draw a graph. and i use gtk.Curve widget for this. and when i add him a long vector it gives me this error:

GLib-ERROR **: /build/buildd/glib2.0-2.26.1/glib/gmem.c:170: failed to allocate 4294967276 bytes aborting...

the code is simple:

w = gtk.Window()
c = gtk.Curve()
c.set_vector(v)
c.set_curve_type(gtk.CURVE_TYPE_SPLINE)
w.add(c)
w.sho开发者_StackOverflow中文版w_all()
gtk.main()

the vector is a long list:

[0.80000000000000004, 0.29999999999999999, 0.29999999999999999, 0.80000000000000004, 0.90000000000000002, 0.20000000000000001, ...]

about 800 elements in this list. can anyone know whats the problem? thx


I do not know why but gtk.Curve does not seem to be able to manipulate data outside of the main loop. Try something like this to add the data after the main call.

import random, gtk, gobject

def createCurve(c):
    v = [random.random() for i in range(800)]
    c.set_vector(v)
    c.set_curve_type(gtk.CURVE_TYPE_SPLINE)
    return True

c = gtk.Curve()
vb = gtk.VBox()
vb.pack_start(c, True, True)
w = gtk.Window()
w.add(vb)
w.show_all()
gobject.timeout_add(2000, createCurve, c)
gtk.main()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜