Python VTE Terminal Oddity

I am trying to use terminal from python VTE binding (python-vte from debian squeeze) as a virtual terminal emulator (only for handling ANSI / control text messages)

in the python interactive console everything looks (almost) ok:

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

      

however, running this code (slightly modified) as a python script produces a different result:

$ python vte_wiredness_1.py 
''

      

strangely, pasting the code back into a (new) interactive python session also gives an empty string:

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

      

The first thing about my mind was that the only difference between the two cases is the time - there must have been some delay before get_text

. unfortunately turning on get_text

with a few seconds of sleep didn't help

then I thought it had something to do with the X Window environment. but the results are the same clean linux console (with some warning about missing graphics).

I wonder what is causing this unpredictable behavior (the interactive console is insertable and injected and this is not a delay .. ant interactive console has nothing to do with the vte terminal object.) I suppose)

can someone explain what is going on? can the term VTE be used this way?

that the letter "b" is preceded by a space in the output, this is another oddity (all consecutive lines are preceded by more spaces .. it looks like I should send a carriage return before the line.)

(the lambda *a: True

get_text argument of the method I'm using is a dummy callback, this is some SlotSelectedCallback .. for an explanation I would appreciate it too :))

+2


a source to share


1 answer


.. by posting myself the solution I found elsewhere

the problem was that I was ignoring the fact that vte.Terminal is a gtk applet, so the main gtk loop must be called.

example 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

+3


a source







All Articles