Exemplo n.º 1
0
class ModalMessageDialogue(Frame):
    def __init__(self, incoming_frame, gui):
	Frame.__init__(self, Toplevel())
	self['borderwidth'] = 2
	self['relief'] = 'ridge'
	self.pack(side='top', fill = 'both')
	self.master.title("Unit tester response window")
	self.dialogue = None
	self.original_msg = ScrollPane(self, label = "Incoming message",
				       label_justification = "center")
	self.original_msg.Write(incoming_frame.PPrint())
	self.original_msg.pack(side = 'top')
	# Button to send a new message.
	b1 = Button(self, text = "Send new message",
		    relief = 'groove',
		    command = lambda g = gui: g.SendNewMessage(from_modal = 1))
	b1.pack(side = 'top')
	# Radiobuttons for reply type.
	self.reply_var = StringVar()
	radio_frame = Frame(self, borderwidth = 2,
			    relief = 'ridge')
	radio_frame.pack(side = 'top', fill = 'x', expand = 1)
	rb1 = Radiobutton(radio_frame, text = "Normal reply",
			  variable = self.reply_var,
			  value = "normal")
	self.grid_equal(rb1, 0, 0)
	rb2 = Radiobutton(radio_frame, text = "Error reply",
			  variable = self.reply_var,
			  value = "error")
	self.grid_equal(rb2, 0, 1)
	rb3 = Radiobutton(radio_frame, text = "Destroy reply",
			  variable = self.reply_var,
			  value = "destroy")
	self.grid_equal(rb3, 1, 0)
	if gui.as_hub:
	    rb3['state'] = 'disabled'
	rb4 = Radiobutton(radio_frame, text = "Dummy reply",
			  variable = self.reply_var,
			  value = "dummy")
	self.grid_equal(rb4, 1, 1)
	self.dismiss_row = ConfirmRow(self)
	self.dismiss_row.pack(side='top')

    def grid_equal(self, win, row, col):
	win.grid(row = row, column = col, sticky = 'w')
	win.grid_columnconfigure(col, weight = '1')
	win.grid_rowconfigure(row, weight = '1')
	
    def Pass(self):
	pass				       

    def succeed(self):
	if self.dialogue is not None:
	    self.dialogue.confirmation_result = 1, self.reply_var.get()
	self.master.destroy()
	
    def fail(self):
	if self.dialogue is not None:
	    self.dialogue.confirmation_result = 0, None
	self.master.destroy()
Exemplo n.º 2
0
    def __init__(self, master, height = 12, width = 60,
		 label = '', label_justification = 'left',
		 action_button_label = None, action_button_action = None):
	ScrollPane.__init__(self, master, height, width,
			    label, label_justification,
			    action_button_label, action_button_action)
	self.textbox['state']='normal'
	self.textbox['background'] = 'white'
Exemplo n.º 3
0
    def __init__(self, master = None, env = None, as_hub = 0):
	TkMGalaxy.CommunicatorInterface.__init__(self, master, env)
	self.master.title("Communicator Unit Tester")
	self['borderwidth'] = 2
	self.pack(fill = 'both', expand = 1)
	self.history = ScrollPane(self,
				  label = "Interaction history",
				  label_justification = 'center',
				  width = 40,
				  height = 10)
	self.history.pack(side = 'top', anchor = 'w',  
			  fill = 'both', expand = 1)
	self.button_row = Frame(self, relief = 'flat',
				borderwidth = 2)
	self.button_row.pack(side = 'top')
	b1 = Button(self.button_row, text = "Quit",
		    relief = 'groove',
		    command = self.Quit)
	b1.pack(side = 'left')
	b2 = Button(self.button_row, text = "Send new message",
		    relief = 'groove',
		    command = self.SendNewMessage)
	b2.pack(side = 'left')
	self.env = env
	self.as_hub = as_hub

	# Register a timer poll, if you're a Hub.
	if self.as_hub:
	    self.poll_timer = self.tk.createtimerhandler(100, self.__PollTimer)
	else:
	    self.poll_timer = None
	self.frame_history = self.seed_frame_history
Exemplo n.º 4
0
    def __init__(self, incoming_frame, gui):
	Frame.__init__(self, Toplevel())
	self['borderwidth'] = 2
	self['relief'] = 'ridge'
	self.pack(side='top', fill = 'both')
	self.master.title("Unit tester response window")
	self.dialogue = None
	self.original_msg = ScrollPane(self, label = "Incoming message",
				       label_justification = "center")
	self.original_msg.Write(incoming_frame.PPrint())
	self.original_msg.pack(side = 'top')
	# Button to send a new message.
	b1 = Button(self, text = "Send new message",
		    relief = 'groove',
		    command = lambda g = gui: g.SendNewMessage(from_modal = 1))
	b1.pack(side = 'top')
	# Radiobuttons for reply type.
	self.reply_var = StringVar()
	radio_frame = Frame(self, borderwidth = 2,
			    relief = 'ridge')
	radio_frame.pack(side = 'top', fill = 'x', expand = 1)
	rb1 = Radiobutton(radio_frame, text = "Normal reply",
			  variable = self.reply_var,
			  value = "normal")
	self.grid_equal(rb1, 0, 0)
	rb2 = Radiobutton(radio_frame, text = "Error reply",
			  variable = self.reply_var,
			  value = "error")
	self.grid_equal(rb2, 0, 1)
	rb3 = Radiobutton(radio_frame, text = "Destroy reply",
			  variable = self.reply_var,
			  value = "destroy")
	self.grid_equal(rb3, 1, 0)
	if gui.as_hub:
	    rb3['state'] = 'disabled'
	rb4 = Radiobutton(radio_frame, text = "Dummy reply",
			  variable = self.reply_var,
			  value = "dummy")
	self.grid_equal(rb4, 1, 1)
	self.dismiss_row = ConfirmRow(self)
	self.dismiss_row.pack(side='top')
Exemplo n.º 5
0
class UnitTesterInterface(TkMGalaxy.CommunicatorInterface):
    def __init__(self, master = None, env = None, as_hub = 0):
	TkMGalaxy.CommunicatorInterface.__init__(self, master, env)
	self.master.title("Communicator Unit Tester")
	self['borderwidth'] = 2
	self.pack(fill = 'both', expand = 1)
	self.history = ScrollPane(self,
				  label = "Interaction history",
				  label_justification = 'center',
				  width = 40,
				  height = 10)
	self.history.pack(side = 'top', anchor = 'w',  
			  fill = 'both', expand = 1)
	self.button_row = Frame(self, relief = 'flat',
				borderwidth = 2)
	self.button_row.pack(side = 'top')
	b1 = Button(self.button_row, text = "Quit",
		    relief = 'groove',
		    command = self.Quit)
	b1.pack(side = 'left')
	b2 = Button(self.button_row, text = "Send new message",
		    relief = 'groove',
		    command = self.SendNewMessage)
	b2.pack(side = 'left')
	self.env = env
	self.as_hub = as_hub

	# Register a timer poll, if you're a Hub.
	if self.as_hub:
	    self.poll_timer = self.tk.createtimerhandler(100, self.__PollTimer)
	else:
	    self.poll_timer = None
	self.frame_history = self.seed_frame_history

    # Receiving a new message which requires a reply
    # should provide a popup, always.
    # This is necessary in the case of the unit tester as server,
    # because nothing will happen until the dispatch function
    # callback returns (in the case of a message which
    # doesn't require a return, we can just provide a return
    # immediately). We'll maintain the same behavior when
    # the unit tester is the Hub for consistency.
    
    def __PollTimer(self):
	response, msg_type = self.env.conn.ReadFrame(blocking = 0)
	if response is not None:
	    # Strip the administrative information.
	    try:
		admin_info = response[Galaxy.GAL_HUB_OPAQUE_DATA_FRAME_KEY]
		del response[Galaxy.GAL_HUB_OPAQUE_DATA_FRAME_KEY]
	    except KeyError:
		admin_info = None
	    if (msg_type == GalaxyIO.GAL_MESSAGE_MSG_TYPE):
		# Update the environment object. This will
		# decode the administrative info.
		self.env = FakeCallEnvironment(self.env.conn, None,
					       admin_info = admin_info,
					       frame_name = response.name)
		_DoGenericDispatch(self.env, response)
	    else:
		self.RecordMessage(response, "Received", msg_type)
		
	self.poll_timer = self.tk.createtimerhandler(100, self.__PollTimer)

    def ModalMessageReply(self, frame, just_return = 0):
	# Here, I need to pop up a modal interaction to
	# send a message reply. It should probably be seeded
	# with the incoming message. It's a different
	# dialogue than the reply dialogue.
	if just_return:
	    self.RecordMessage(frame, "Sending", GalaxyIO.GAL_REPLY_MSG_TYPE)
	    self.env.Reply(frame)
	else:
	    yes_or_no, val = ConfirmationDialogue(ModalMessageDialogue(frame, self)).Confirm()
	    # "Cancel" is like returning a dummy, as is not selecting
	    # a value.
	    if yes_or_no and val and (val != "dummy"):
		if val == "normal":
		    # Get reply.
		    self.SendReply()
		elif val == "error":
		    # Get error.
		    self.SendErrorReply()
		elif val == "destroy":
		    # Send destroy.
		    self.SendDestroyReply()
	    else:
		# If we cancelled, or we didn't have a val, or
		# the val was "dummy", we need to send the incoming
		# frame as the reply.
		self.RecordMessage(frame, "Sending",
				   GalaxyIO.GAL_REPLY_MSG_TYPE)
		self.env.Reply(frame)
	# So you're always guaranteed to have sent a reply.
	
    def SendNewMessage(self, from_modal = 0):
	self._SendMessage("Enter new message:", GalaxyIO.GAL_MESSAGE_MSG_TYPE,
			  from_modal)

    def RecordMessage(self, message, dir, mtype):
	self.history.Write(("[%s: " % dir) + MsgTypeNameTable[mtype] + "]\n")
	m = message.PPrint()
	self.history.Write(m + "\n")
	if m not in self.frame_history:
	    self.frame_history.append(m)

    def _SendMessage(self, typein_prompt, msg_type, from_modal = 0):
	cur_frame_string = None
	while 1:
	    d = ConfirmationDialogue(ConfirmationFrameTypein(typein_prompt, msg_type, self, from_modal))
	    if cur_frame_string is not None:
		d.confirmation_window.msg.Write(cur_frame_string)
	    yes_or_no, val = d.Confirm()
	    if yes_or_no:
		f_text, s_text, round_trip, lock = val
		cur_frame_string = f_text
		try:
		    new_f = Galaxy.Frame(str = f_text)
		except Galaxy.FrameParsingError:
		    retry_val, ignore = ConfirmationDialogue(ConfirmationPopup("Couldn't parse the frame. Retry?")).Confirm()
		    if not retry_val:
			print "Cancelled."
			sys.stdout.flush()
			return
		    else:
			continue
		self.RecordMessage(new_f, "Sending", msg_type)
		if msg_type == GalaxyIO.GAL_REPLY_MSG_TYPE:
		    self.env.Reply(new_f)
		elif msg_type == GalaxyIO.GAL_MESSAGE_MSG_TYPE:
		    # Do something, not sure what yet.
		    if s_text and lock:
			self.env.SetSession(s_text,
					    GalaxyIO.GAL_SERVER_READS_ONLY_FROM_SESSION | GalaxyIO.GAL_SESSION_WRITES_ONLY_TO_SERVER | GalaxyIO.GAL_SERVER_WRITES_ONLY_TO_SESSION)
		    elif s_text:
			self.env.UpdateSessionID(s_text)
		    # Only want to wait for the reply if we're
		    # not a Hub.
		    if round_trip and (not self.as_hub):
			try:
			    reply_f = self.env.DispatchFrame(new_f)
			    del reply_f[Galaxy.GAL_HUB_OPAQUE_DATA_FRAME_KEY]
			    self.RecordMessage(reply_f, "Received",
					       GalaxyIO.GAL_REPLY_MSG_TYPE)
			except GalaxyIO.DispatchError, error_frame:
			    del error_frame[Galaxy.GAL_HUB_OPAQUE_DATA_FRAME_KEY]
			    self.RecordMessage(error_frame, "Received",
					       GalaxyIO.GAL_ERROR_MSG_TYPE)
		    elif round_trip:
			# We need to write a frame with the
			# round trip set to 1. But we don't want to
			# wait for the response. This will also only
			# be fired when we're pretending to be a Hub,
			# so we can use a special version of WriteFrame.
			self.env.WriteFrame(new_f, round_trip = 1)
		    else:
			self.env.WriteFrame(new_f)
	    else:
		print "Cancelled."
		sys.stdout.flush()
	    return