def add(self, component): """Make a message to add the component.""" if component.added_to_hicp is not None: # Already added. Maybe update instead. self.logger.debug("Alread added component") # debug if self == component.added_to_hicp: # Component was added to this HICP object, it can be # updated. self.logger.debug("about to update instead") # debug self.update(component) return component.added_to_hicp = self component.component_id = self.get_gui_id() # Add component to list first - when the other end gets it, it # might send an event right away, and this side should be ready for # processing without delay. self.__component_list[str(component.component_id)] = component message = Message() message.set_type(Message.COMMAND, Message.ADD) component.fill_headers_add(message) component.changed_header_list.clear() self.__write_thread.write(message)
def send_add_text_message(self, text_id, text_string): message = Message() message.set_type(Message.COMMAND, Message.ADD) message.add_header(Message.CATEGORY, Message.TEXT) message.add_header(Message.ID, str(text_id)) message.add_header(Message.TEXT, text_string) self.__write_thread.write(message)
def run(self): is_disconnect = False while not is_disconnect: message = Message(in_stream=self.in_stream) if message.get_type() != Message.EVENT: # Ignore all non-event messages continue is_disconnect = self.got_event_msg(message)
def text_direction(self, first_direction, second_direction): message = Message() message.set_type(Message.COMMAND, Message.MODIFY) message.add_header(Message.CATEGORY, Message.GUI) message.add_header(Message.TEXT_DIRECTION, first_direction + "," + second_direction) self.__write_thread.write(message)
def remove(self, component): if component.added_to_hicp is None: # Not added yet, so can't remove. self.logger.debug( "Can't remove component, has not been added.") # debug return if self != component.added_to_hicp: # Component was added to different HICP object, it # cannot be updated. self.logger.debug("Component has different hicp value.") # debug return message = Message() message.set_type(Message.COMMAND, Message.REMOVE) message.add_header(Message.CATEGORY, Message.GUI) message.add_header(Message.ID, str(component.component_id)) self.__write_thread.write(message) # If there were changed headers, they don't matter now. component.changed_header_list.clear() # Remove from component list. del self.__component_list[str(component.component_id)]
def update(self, component): """Normally, the component's update method is called, then it calls this method.""" if component.added_to_hicp is None: # Not added yet. Only happens if added_to_hicp.update(component) is # called, component.update() can't call this because it has # no hicp component to pass that call to. self.add(component) else: if self != component.added_to_hicp: # Component was added to different HICP object, it # cannot be updated. self.logger.debug( "Component has different hicp value.") # debug return header_list = component.changed_header_list if 0 == len(header_list): # There are no modified fields. return message = Message() message.set_type(Message.COMMAND, Message.MODIFY) component.fill_headers_modify(message) # Add all changed headers. for header_key in list(header_list.keys()): message.add_header(header_key, header_list[header_key]) self.__write_thread.write(message) component.changed_header_list.clear()
def authenticate(self): message = Message() message.set_type(Message.COMMAND, Message.AUTHENTICATE) message.add_header(Message.METHOD, ', '.join(self.authenticator.get_methods())) self.write_thread.write(message)
def disconnect(self): message = Message() message.set_type(Message.COMMAND, Message.DISCONNECT) self.write_thread.write(message)