I have a application written in PyGtk. I need to convert a particular line number into its corresponding window co-ordinates in a GtkTextView. How can this be done?
A:
It can't be done, in general. If you're talking about a line of your pygtk program, then you would need an API for your IDE (development environment) to find out where a particular source code line is currently displayed on the screen, if anywhere. If by "line number" you mean something else, then as Ignacio says, you'll need to provide a lot more detail.
garyo
2010-01-26 05:25:33
Nope that was exactly wat i wanted to do .. Line Number to text view coordinates conversion. I'm Developing an IDE and i was implementing Code Folding. And i Wanted to place the code folder based on the line numbers
Akash A
2010-01-26 08:21:22
Ah, I see -- you're *writing* an IDE. The question sounded like you were using an IDE and writing a pygtk within it, and wanted to know what screen coord a particular source line of the program was. I think unwind's answer is the right idea.
garyo
2010-01-26 17:11:44
+2
A:
Begin by using gtk_text_buffer_get_iter_at_line()
to get a handle on the line. Then use gtk_text_view_get_line_yrange()
to convert that into pixel coordinates. Finally use gtk_text_view_buffer_to_window_coords()
to convert the buffer pixel coordinates into window coordinates.
These are links to the C API calls, but converting to PyGtk should be trivial.
unwind
2010-01-26 08:44:13