GNOME Bugzilla – Bug 676999
get_text method moved
Last modified: 2012-12-10 19:52:27 UTC
We are using VTE in a terminal (writed in python) for the sugar environment, git.sugarlabs.org/terminal. Now we are porting this application to GTK3, and we don't found the get_text method. Where is?
*** Bug 677000 has been marked as a duplicate of this bug. ***
As Agustin said, vte_terminal_get_text () of VteTerminal is not available via the Python introspection bindings.
The method is available in the C library: vte_buffer_get_text(VteBuffer *buffer, VteSelectionFunc is_selected, gpointer user_data, GArray *attributes) But the method vte_view_get_buffer(VteView *terminal) or vte_terminal_get_buffer isn't available in the Python Bindings.
Also is this the right place to put this bug on?
This looks like the right place for this bug report. Next steps would be to look at the vte source code, does vte_buffer_get_text have annotations? (https://live.gnome.org/GObjectIntrospection/Annotations) If so, look at the vte build logs. It should explain why the function is not available via introspection. It may be choking on that GArray parameter...
(In reply to comment #5) > Next steps would be to look at the vte source code, does vte_buffer_get_text > have annotations? The problem is bigger: first it would consist in check for annotations at vte_view_get_buffer and the VteBuffer type.
build log: http://armpkgs.fedoraproject.org/packages/vte3/0.34.1/1.fc18/data/logs/armv7hl/build.log Current annotation: {{{ <method name="get_text" c:identifier="vte_terminal_get_text" introspectable="0"> <doc xml:whitespace="preserve">Extracts a view of the visible part of the terminal. If @is_selected is not %NULL, characters will only be read if @is_selected returns %TRUE after being passed the column and row, respectively. A #VteCharAttributes structure is added to @attributes for each byte added to the returned string detailing the character's position, colors, and other characteristics.</doc> <return-value transfer-ownership="full"> <doc xml:whitespace="preserve">a newly allocated text string, or %NULL.</doc> <type name="utf8" c:type="char*"/> </return-value> <parameters> <parameter name="is_selected" transfer-ownership="none" scope="call" closure="1"> <doc xml:whitespace="preserve">a #VteSelectionFunc callback</doc> <type name="SelectionFunc" c:type="VteSelectionFunc"/> </parameter> <parameter name="user_data" transfer-ownership="none"> <doc xml:whitespace="preserve">user data to be passed to the callback</doc> <type name="gpointer" c:type="gpointer"/> </parameter> <parameter name="attributes" direction="out" caller-allocates="0" transfer-ownership="full"> <doc xml:whitespace="preserve">location for storing text attributes</doc> <array zero-terminated="0" name="GLib.Array" c:type="GArray*"> <type name="CharAttributes"/> </array> </parameter> </parameters> </method> }}}
Created attachment 227965 [details] [review] Move definition of VteCharAttributes up I found the element-type for the attributes in vte_terminal_get_text vte_terminal_get_text_include_trailing_spaces and vte_terminal_get_text_range strange to be of type "Vte.CharAttributes" and not VteCharAttributes but when I changed it I only got a warning. Then I saw that there was already a warning about "Unknown namespace for identifier 'vte_char_attributes'", so I moved the definition of VteCharAttributes and now those functions are introspectable. The warning "<unknown>:: Warning: Vte: Unknown namespace for identifier 'vte_char_attributes'" is still there, though.
Patch looks good. ChPe, which branches should I commit this to? Or, can you please commit?
If this could get in as a bug fix for vte3-0.34, that would be terrific.
Pushed the fix to the vte3-0.34 branch: http://git.gnome.org/browse/vte/commit/?h=vte-0-34&id=2ba27999b537300f4beb92ca27830fbd4197740e
Marking fixed. I assume ChPe will cherry pick from there eventually if it needs to be on other branches.
I have found two issues trying to use the get_text method in vte with python after apply this patch. The first is I can't set is_selected as None, the c code can manage it (vte.c line 6293) but the introspection annotations don't allow this. Can be solved doing: - * @is_selected: (scope call): a #VteSelectionFunc callback + * @is_selected: (scope call) (allow-none): a #VteSelectionFunc callback The second issue is more difficult to solve in a proper way: The attributes parameter is marked as: - * @attributes: (out) (transfer full) (array) (element-type Vte.CharAttributes): location for storing text attributes but if is a out parameter, I can't pass it as a parameter from python, and the first line using the parameter in the c code is: line 6298 if (attributes) g_array_set_size (attributes, 0); Then should be None or a already created GArray. Right now the application crash when I do: vte.get_text(None, None) The only workaround I have found is change: - * @attributes: (out) (transfer full) (array) (element-type Vte.CharAttributes): location for storing text attributes + * @attributes: (array) (element-type Vte.CharAttributes): location for storing text attributes and calling from python doing: vte.get_text(None, None, []) now the application don't crash, but of course the attributes array is not loaded. A test case is attached, and a diff to test these changes.
Created attachment 231197 [details] Test case using the proposed workaround
Created attachment 231198 [details] [review] Path to test the proposed solution
Please don't report new issues in resolved bugs. I'll clone this bug for your issues.