Example #1
0
def main():
    with StateReader(ChatParticipant,
                     onData=onData,
                     onNoMoreData=onNoMoreData,
                     onDispose=onDispose) as reader:
        with StateWriter(ChatParticipant) as writer:
            s1 = ChatParticipant(name="me", room="kitchen", state="busy")
            d1 = ChatParticipant(name="me", room="kitchen")
            u1 = ChatParticipant(name="me", room="kitchen", state="away")

            s2 = ChatParticipant(name="you", room="terras", state="idle")
            d2 = ChatParticipant(name="you", room="terras")
            u2 = ChatParticipant(name="you", room="terras", state="away")
            while True:
                cmd = raw_input("Enter command: ")
                if cmd == "s1": writer.write(s1)
                elif cmd == "s2": writer.write(s2)
                elif cmd == "u1": writer.write(u1)
                elif cmd == "u2": writer.write(u2)
                elif cmd == "d1": writer.remove(d1)
                elif cmd == "d2": writer.remove(d2)
                elif cmd == "q": break

            writer.remove(d1)
            writer.remove(d2)
Example #2
0
    def __initQeo(self):
        self.participantReader = StateReader(
            ChatParticipant,
            onData=self.forwardData,
            onNoMoreData=lambda cls="ChatParticipant": self.forwardNoMoreData(
                cls),
            onDispose=self.forwardDispose)
        self.msgReader = EventReader(
            ChatMessage,
            onData=self.forwardData,
            onNoMoreData=lambda cls="ChatMessage": self.forwardNoMoreData(cls))

        self.connect(self, SIGNAL("onData"), self.onData)
        self.connect(self, SIGNAL("onNoMoreData"), self.onNoMoreData)
        self.connect(self, SIGNAL("onDispose"), self.onDispose)