GNOME Bugzilla – Bug 481715
Need way to assign to a GtkTextIter
Last modified: 2008-09-11 19:15:25 UTC
Sometimes you need to modify the location of an existing GtkTextIter; for example, if override delete_range() on a GtkTextBuffer you are required to revalidate the iters passed in after any modifications you make. For this purpose, it would be handy to by able to assign the *value* of one iter to another iter. Perhaps: iter2.copy_from(iter1) [ This obviously is different from iter2 = iter1.copy() ] I can't figure out a general workaround for this, you'd think you could do: iter2.set_line(iter1.get_line()); iter2.set_line_offset(iter1.get_line_offset()); But you can't call iter2.set_line() if iter2 is not currently valid.
Created attachment 98055 [details] [review] Proposed patch Here's a patch to add the functionality.
Created attachment 98056 [details] ctypes-based work around Here's a hack using ctypes and knowledge of the structure layouts to implement the functionality without pygtk modification; attaching it here in case anybody else will find it useful. In theory it should work cross-architecture, and until the pygtk and/or GTK+ API is changed, but I've done only basic testing, and for all I know it corrupts memory even on my system :-)
Maybe it is better to name the method e.g. assign(), assign_from() or set_from(), just to avoid confusion between copy() and copy_from()? Also, please use correct name in PyArg_ParseTupleAndKeywords(). BTW, a test case could be added, though probably not required.
I don't care much about the name ... all of your proposals sound OK to me. Good catch for PyArg_ParseTupleAndKeywords() ... the cut-and-paste-and-modify nature of the patch shows up :-) I'm not going to have a chance to do another version at least for another week; if someone wants to fix it up and apply it, that would be appreciated, since I'm likely to forget about it.
I committed the patch with some modification (most importantly, renamed the method to 'assign') and one test case. Sending ChangeLog Sending gtk/gtktextview.override Sending tests/test_textview.py Transmitting file data ... Committed revision 3041. 2008-09-11 Paul Pogonyshev <pogonyshev@gmx.net> Bug 481715 – Need way to assign to a GtkTextIter * gtk/gtktextview.override (_wrap_gtk_text_iter_assign): New function (based on patch by Owen Taylor). * tests/test_textview.py (TextIterTest): New test.