[Twisted-Python] Can I connect multiple class instances to 1 Twisted factory?

exarkun at divmod.com exarkun at divmod.com
Fri Apr 2 10:35:36 EST 2004

On Thu, 1 Apr 2004 07:52:33 -0500, "Kaleb Brasee" <qpalzm at alltel.net> wrote:
> Is this even possible?  I'm designing a simple chat and game
> client/server as an intro to Python, and it would be nice to represent
> the different interfaces (public chat room, private chat rooms, game
> instances) as totally seperate classes and show them in totally seperate
> windows.
> Given my basic understanding of Twisted, I see no way of doing this, and
> my whole GUI is contained in one class.  The project is doable this way,
> it would just be much better with multiple class and multiple window
> seperation.

  Twisted doesn't enforce any design strategies with respect to any GUI
code you use it with.  If you simply require that your ServerFactory
or ClientFactory be able to reference multiple GUI objects, this seems as
simple as:

    f = YourFactory(chatRoomGUIObject, privateRoomGUIObject,
                    gameGUIObject, ...)

  Not that I would go down that particular road myself.

> I am using Tkinter to design my GUIs, using the specialized Twisted
> support code to setup the reactor.
> If anyone can give me any direction, I would appreciate it very much.

  Think about what information needs to move between the network layer
(where information is received from sockets), the application layer (where
messages from a particular user are differentiated from messages from 
another particular user), and the UI layer (where messages are rendered
in some fashion so as to be visible to the end user).

  Try and come up with the narrowest interface possible that lets that
information move between those layers.  In this instance, "narrow" would
mean not passing every GUI class you have to your factory.  Perhaps an
event broadcasting system would be useful, or maybe a single "GUI" class
that knows how to delegate messages down to the various other GUI classes
you have defined.

> Thanks



More information about the Twisted-Python mailing list