2

I am running a twisted process which needs to interact with the user, without blocking. The idea is that the user will be asked to input some data, and once a complete line has been entered, the program will process it, eventually triggering events. During the period that the user is entering data, the reactor must keep on running normally.

Is there any support in twisted for that?

blueFast
  • 41,341
  • 63
  • 198
  • 344

1 Answers1

1

You can read from standard input using twisted.internet.stdio. See stdiodemo.py and stdin.py at http://twistedmatrix.com/documents/current/core/examples/.

You can also use Gtk using twisted.internet.gtk2reactor. See the pbgtk2.py example at the same examples page.

You can also use other GUI toolkits, though Gtk is the most well supported.

Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122
  • Is it possible to use the input take by this receiver and feed it off to another protocol so it can be piped over the network? – DeaconDesperado Jul 02 '12 at 19:48
  • Sure. Input is handled by a protocol, which is just a bunch of Python code you write in a class you define. Feeding it to another protocol is just another way of saying "calling a method on an object", which is a great thing to do, and Twisted won't prevent you from doing that. :) A hurdle a lot of people seem to struggle with is arranging their code so they have a *reference* to a good object to call that method on. However, there's also nothing special involved in doing that. eg, pass the object as an __init__ argument or set it as an attribute later on. Nothing fancy required. – Jean-Paul Calderone Jul 03 '12 at 12:39
  • Calderon What I'm struggling with is that I have a stdio protocol that takes the input... I assign the factory for the network protocol as the `factory` attribute inside the stdio protocol, and then try to call methods by name (on the cli) of the network protocol. I am sure I have misunderstood this example somehow: http://share11.appspot.com/1421 My code: https://github.com/DeaconDesperado/swfty-share/blob/master/client.py – DeaconDesperado Jul 03 '12 at 13:42
  • I don't think this can be answered in the comments section of this question. Consider posting a new question. – Jean-Paul Calderone Jul 03 '12 at 14:18
  • Sorry, i meant to post the link - I had one up http://stackoverflow.com/questions/11297032/twisted-client-protocol-attaching-an-interface-frontend/11297404#11297404 – DeaconDesperado Jul 03 '12 at 14:21