[pygtk] metaclass -- skip gobject.type_register(...)
Hi everyone, I have been playing with metaclasses in Python and thought the following code was cool... It is the signal.py demo with a metaclass. I bet it is pretty easy to add the metaclass attribute to the C PyGObject class somewhere in gobjectmodule.c... then we could forget about type_register and the __metaclass__ attribute. Of course you can also look at the 'dict' from the class statment and create signals and and properties according to __signals__, __properties__, or something like that, but I understand those features are already in CVS, though I don't know if they were implemented using a metaclass or not. -Rob import gobject class PyGObjectSubClass(type): # called before __init__ to actually create an object # here we are creating a class (or type) object def __new__(t, cname, bases, dict): # super is probably overkill here, type.__new__ would be fine klass = super(PyGObjectSubClass, t).__new__(t, cname, bases, dict) print 'Created new class, now registering it.' gobject.type_register(klass) return klass class C(gobject.GObject): # we must tell Python to create this class as an 'instance' of # PyGObjectSubclass, rather than plain type. We # could also inherit the metaclass attribute from gobject.GObject __metaclass__ = PyGObjectSubClass def __init__(self): self.__gobject_init__() # default constructor using our new GType def do_my_signal(self, arg): print C: class closure for `my_signal' called with argument, arg # gobject.type_register(C) gobject.signal_new(my-signal, C, gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_INT, )) class D(C): def do_my_signal(self, arg): print D: class closure for `my_signal' called. Chaining up to C C.do_my_signal(self, arg) # gobject.type_register(D) def my_signal_handler(object, arg, *extra): print handler for `my_signal' called with argument, arg, \ and extra args, extra inst = C() inst2 = D() inst.connect(my_signal, my_signal_handler, 1, 2, 3) inst.emit(my_signal, 42) inst2.emit(my_signal, 42) ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] textview iter position
Hi, I am trying to popup a widget in a TextView (for auto-completion options in an editor). It looks like I need to use the 'add_child_in_window' method of TextView. I am trying to get the coordinates with text_view.get_iter_location(iter, rect) and it wants a GdkRectangle to fill in as the second arg. Problem: gtk.gdk.Rectangle() raises: NotImplementedError: GdkRectangle can not be constructed How do I get the coords to add the widget? Or can I add a widget another way? Thanks, Rob ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] Generic Tree/List Model improvement.
Robert Nikander wrote: snip stuff about emitting signals from GenericTreeModel James Henstridge wrote: The GenericTreeModel class has a number of limitations (you just ran into some). For 0.99.5, you probably can't do what you want. Note that GenericTreeModel will leak lots of references (and can't really be fixed). James. Well I did get it to emit signals. I have to call get_iter to get a TreeIter. Can't use tuples. But you were not kidding about it leaking references. I have been running a process overnight that has a few lists with 1000+ rows in them and 'top' reveals the memory footprint is now an obese 78 Megs. I am interested in your comment 'it can't be fixed.' I really like this toolkit -- it is so much more pleasant than trying to write GTK stuff in C! -- and I would take a hack at changing some source and seeing if I can't get a good abstract TreeModel working, but I don't want to waste my time if you have discovered that there is some reason it 'can't be done' -- some kind of essential design problem that I will run into after 5 days of hacking. Can you elaborate a little on that comment? Who is working on that code? Thanks, Rob ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Tree/ListStore remove(iter)?
On 2001.12.05 21:09 James Henstridge wrote: iter = model.get_iter(1, 6) Ah. I was confused about tuples/paths vs iterators. Thanks a ton to both Matt and James for answering all my questions. How about getting the number of children in the list? According to GTK docs it is model.iter_n_childen( NULL ) ... but how to get a PyObject Iterator that is wrapped around NULL? I appreciate the help, thanks, Rob ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] how to connect a TreeModel with View
Hi, I am trying to use the new TreeModel/View stuff in the latest pygtk (1.99.5). In short, I need to know how to 'notify' the view when my model is updated. I have copied from the example that shows a class that subclasses gtk.GenericTreeModel and overrides a bunch of on_* methods. Now, my database gets updated and I want to signal the attached tree-view. I tried: self.emit('row-inserted', new_iter, new_iter) but got: Traceback (most recent call last): File ./gtktest.py, line 105, in change_tree tree_model.add_row() File ./gtktest.py, line 19, in add_row self.emit('row-inserted', new_iter, new_iter) TypeError: could not convert type tuple to GtkTreeIter required for parameter 1 I tried subclassing TreeIter and got the NotImplemented exception. So, how are people using TreeModels? Thanks, Rob ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] TreeItem gtk_object_unref error
Hi, I have been using GtkTreeItem and getting some errors from the underlying GTK C code. It seems that when python determines that the object can be garbage colleted, it is calling the gtk_object_unref on the wrong object. I was wondering if this is a bug, or am I doing something bass ackwards... I thought I could just loose references to widgets, and python/pygtk should take care of it. Here is my code. I want to create a new GtkTreeItem and stick in in the dictionary, with 'ad' as the key. The old TreeItem gets wiped out, but that is when the GTK errors start coming... If I save a reference to 'oldti' somewhere, I don't get the error. def _add_tree_item_for_app_data(self,ad): print 1 if self.app_data_2_ti.has_key(ad): oldti = self.app_data_2_ti[ ad ] print oldti: , oldti ti = self.app_data_2_ti[ ad ] = gtk.GtkTreeItem(ad.name) print 2 Here is the console output when this function is called... 1 oldti: gtk.GtkTreeItem instance at 0x102b55f0 2 Log from: MainView: added tree item for app data object Gtk-CRITICAL **: file gtkobject.c: line 1172 (gtk_object_unref): assertion `GTK_IS_OBJECT (object)' failed. thanks for any help, Rob ps. I am using 0.6.8 and gtk 1.2.10 ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] generating defs
Hi, I just got the lastest pygtk from CVS and I am getting some compile errors because the .defs files are from an older GTK. So, is there a standard operating procedure for generating new .defs files from GTK headers? (1.3.10) The best I can come up with is: h2def.py --onlyobjectdefs ${PATH_TO_GTK_HEADERS}/gtk/*.h gtk-types.defs h2def.py --onlyenums ${PATH_TO_GTK_HEADERS}/gtk/*.h gtk-types.defs h2def.py ${PATH_TO_GTK_HEADERS}/gtk/*.h gtk.defs ## but then this has all the objs and enums, not just methods... Maybe there is a script somewhere that I am missing? Thanks, Rob ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk