create pixmap from data
Hi there. I have a list containing integer values from 0 to 255. With this list I have informations width and height, as width * height = len(my_list) What I want to do is to convert this array into a pixmap of dimension width * height in order to draw it inside a pygtk GUI. Any suggestions about a way to display those informations ? cheers Thomas -- http://mail.python.org/mailman/listinfo/python-list
GdkColor : the phantom class ?
Hi. No matter how I try, I just can't find this GdkColor class. I'm trying to convert some data into a pixmap in order to display it. Here is my code : import pygtk pygtk.require('2.0') import gtk xbm = #define dump_width 4 #define dump_height 4 static unsigned char dump_bits[] = { 0xaa, 0x6c, 0x55, 0x58, 0x4f, 0x4d, 0xb, 0x9b, 0xf8, 0xcc, 0x1d, 0xd5, 0x61, 0xa4, 0xd8, 0x78, }; class Ex: def __init__(self): window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.show() pixmap = gtk.gdk.pixmap_create_from_data(window.window, ##display xbm, ##data 28,28, ##width/height 8, ##depth fg,bg) image = gtk.Image() image.set_from_pixmap(pixmap, None) image.show() def main(self): gtk.main() return 0 e = Ex() e.main() -- The error comes from fg / bg. It says this have to be of type GdkColor, but I can't find this class anywhere. Plus, can anyone explain me the utility of those parameters, as I don't understand the need to set a background and a foreground when you fill every damn pixel with data ... -- http://mail.python.org/mailman/listinfo/python-list
Re: GdkColor : the phantom class ?
I found an answer : color = gtk.gdk.Color() and then use color for fg et bg -- http://mail.python.org/mailman/listinfo/python-list
new-style classes and len method
Hi there. I'm trying to use new-style classes, but there is something i'm obviously missing here it is : class Data(list): __slots__ = [width, height, label] def __init__(self,width,height,label=None): list.__init__(self) self.width = width self.height = height self.label = label def clear(cls): while len(cls) 0: del cls[0] return clear = classmethod(clear) # d = Data(2,2) # d.clear() TypeError: len() of unsized object off course it was working with : [...] def clear(self): while len(self) 0: del self[0] return So, I guess you can't use cls as a replacement for self. So, what do I have to use ??? -- http://mail.python.org/mailman/listinfo/python-list
Re: new-style classes and len method
Or maybe I'm mixing up what we call a classmethod with what we could call an instance method ? -- http://mail.python.org/mailman/listinfo/python-list
Re: new-style classes and len method
It's alright I found where my mistake came from. I was misunderstanding the meaning of classmethod, thinking of it as an instance method. -- http://mail.python.org/mailman/listinfo/python-list
Re: read a file line by line using readline()
If your code is exactly what you've copy-pasted, then you are not testing against an empty string but a one blank space string ... I've just tried with : while line != : and it works very well. -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple inheritance
thanks, you pointed exactly on what distrurbed me. I'll see what I can do with cooperative methods. -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple inheritance
That's perfect. thanks. -- http://mail.python.org/mailman/listinfo/python-list
Code organization
Hi. I found a lot of documentation about how to code in Python, but not much about how you organize your code in various modules / packages ... As I am not yet used to python, this puzzle me a bit. So, can anyone explain how one should organize and store its code ? the uses of __init__.py files ? Maybe my question is not very clear, but I hope someone will understand anyway ... Thomas -- http://mail.python.org/mailman/listinfo/python-list
multiple inheritance
Hi. I think I'm missing something about multiple inheritance in python. I've got this code. class Foo: def __init__(self): self.x = defined by foo self.foo = None class Bar: def __init__(self): self.x = defined by bar self.bar = None class Foobar(Foo,Bar): pass fb = Foobar() print fb.x print fb.__dict__ which returns : defined by foo {'x': 'defined by foo', 'foo': None} So I guess not defining __init__ in my class Foobar will call __init__ from my superclass Foo. Also __dict__ doesn't show an attribute 'bar':None so I guess Bar.__init__ is not called at all. I would like to have a subclass with all attributes from superclasses defined, and only the attribute from the first when there is conflict (i.e. in this case, Foobar would be like this but with bar:None) I tried this : class Foobar(Foo,Bar): def __init__(self): Foo.__init__(self) Bar.__init__(self) defined by bar {'x': 'defined by bar', 'foo': None, 'bar': None} Here I have all I want, except the value of 'x' comes from the 'Bar' superclass rather than Foo. So, to have what I want, I would have to invert the two calls to __init__ in order to have the right x value. What I find awkward here is that the order of __init__ calls matters, rather than the order of the classes in the class declaration. Do you have any ideas of a way to get this multiple inheritance thing solved without having to do those __init__ calls ? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: listing attributes
Thanks a lot for all your answers ! Thanks to you I resolved this problem. Here is what i've done : [...] for (_,v) in getmembers(self): if isinstance(v,Property): st += \t%s\n % str(v) [...] as all the attributes I want to get are instances of Property or a subclass of Property, it does the trick. -- http://mail.python.org/mailman/listinfo/python-list
listing attributes
Hi there. I'm trying to get a list of attributes from a class. The dir() function seems to be convenient, but unfortunately it lists to much - i don't need the methods, neither the built-in variables. In fact, all my variables are referencing to objects of the same type. Can anyone suggest me a way to get this list of variables ? Thanks Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: variables preceeded with @
Yum, food for thoughts. Thanks Diez. -- http://mail.python.org/mailman/listinfo/python-list