def input(self): ## print "TkinterGui::MainWindow::input" cmd = self.inputField.get(1.0, Tkinter.END) self.inputField.delete(1.0, Tkinter.END) state = 'mmp' mmp = MMPState() psyc = PSYCState() for line in cmd.split('\n'): if line == ".": #end of packet break if line == "" or (not _isModifier(line) and state == 'mmp'): state = 'psyc' if state == 'mmp': mmp.set_state(line) continue if state == 'psyc': if _isModifier(line): psyc.set_state(line) elif line.__len__() and line[0] == '_': psyc.set_mc(line) else: psyc.append_text(line) self.center.send(mmp, psyc)
def packetReceived(self, mmp, data): self.state.reset_state() state = 'psyc' for line in data: if _isModifier(line) and state == 'psyc': self.state.set_state(line) continue elif line.__len__() and line[0] == '_' and state != 'text': ## print "mc:", line ## print "source:", mmp.get_source() self.state.set_mc(line) state = 'text' continue elif state == 'text': self.state.append_text(line) else: print "unknown psyc stuff:", line ## print "PSYCProtocol::packetReceived from", mmp.get_source() ## print "=>PSYC :", self.state.get_state() ## print "=>mc :", self.state.get_mc() ## print "=>text :", self.state.get_text() ## print "----" self.callback.handle(mmp, self.state)
def lineReceived(self, line): # kind of state machine line = line.strip() if line == ".": ## print "<<EOP>>" self.packetReceived(self.mmp, self.data) # reset state, clear temporary variables, etc self.mmp.reset_state() self.data = [] self.state = "mmp" return if (line == "" or not _isModifier(line)) and self.state == "mmp": # if we have _length for data then # binary support if self.mmp._query("_length"): self.set_terminator(self.mmp._query("_length")) self.state = "data" ## print "<<" + self.state + ">> " + line ## comment out if self.state == "mmp": # maybe else with the above could also work... self.mmp.set_state(line) return elif line != "": self.data += [line]