Question

i'm trying to use the terminal from python VTE binding (python-vte from debian squeeze) as a virtual terminal emulator (just for ANSI/control chars text processing)

in interactive python console, everything looks (almost) all right:

>>> import vte
>>> term = vte.Terminal()
>>> term.feed("a\nb")
>>> print repr(term.get_text(lambda *a: True).rstrip())
'a\n b'

however, launching this code (little modified) as python script, different result is yielded:

$ python vte_wiredness_1.py 
''

strangely enough, pasting the code back into the (new) interactive python session also yields empty string:

>>> import vte
>>> term = vte.Terminal()
>>> term.feed("a\nb")
>>> print repr(term.get_text(lambda *a: True).rstrip())
''
>>>

first thing caming on my mind was that the only difference between the two cases is the timing - there had to be some delay before get_text. unfortunately, preluding get_text with some seconds sleep did not help

then i thought it has something to do with X window environment. but the results are the same pure linux console (with some warning on missing graphics).

i wonder what causes such an unpredictable behavior (interactive console - pasted vs typed, and it's not the delay.. ant the interactive console has nothing to do with the vte terminal object.. i guess)

can someone explain what is happening? is it possible to use the VTE Term such way?

that the "b" letter in the output is preceded by the space, is another strangeness (all consecutive lines are preceded by more spaces.. looks like I have to send carriage return before the string.)

(the lambda *a: True get_text method argument i'm using is a dummy callback, it's is some SlotSelectedCallback.. for its explanation i'd be grateful as well :) )

Was it helpful?

Solution

..posting myself the solution i have found elsewhere

problem was that i was ignoring fact that vte.Terminal is an gtk applet, so gtk main loop has to be called.

example of working code:

import gtk
import vte

term = vte.Terminal()

term.feed("a\r\nb")

def get_text(term):
    print repr(term.get_text(lambda *a: True).rstrip())    
    gtk.main_quit()

term.connect('contents-changed', get_text)
gtk.main()

thanks Juhaz@irc://freenode.net/##gnome

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top