After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 481715 - Need way to assign to a GtkTextIter
Need way to assign to a GtkTextIter
Status: RESOLVED FIXED
Product: pygtk
Classification: Bindings
Component: gtk
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2007-09-29 23:14 UTC by Owen Taylor
Modified: 2008-09-11 19:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch (2.16 KB, patch)
2007-10-29 00:04 UTC, Owen Taylor
reviewed Details | Review
ctypes-based work around (1.09 KB, text/plain)
2007-10-29 01:34 UTC, Owen Taylor
  Details

Description Owen Taylor 2007-09-29 23:14:07 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.
Comment 1 Owen Taylor 2007-10-29 00:04:25 UTC
Created attachment 98055 [details] [review]
Proposed patch

Here's a patch to add the functionality.
Comment 2 Owen Taylor 2007-10-29 01:34:38 UTC
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 :-)
Comment 3 Paul Pogonyshev 2008-07-12 13:48:01 UTC
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.
Comment 4 Owen Taylor 2008-07-13 15:21:38 UTC
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.



Comment 5 Paul Pogonyshev 2008-09-11 19:15:25 UTC
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.