def __init__(self, name): Screens.__init__(self, name) self.sending_clear = False self.message_clear = False self.layout = BoxLayout(padding=5, orientation='vertical') self.info = Modify(Label(text="New Messages")) self.info.size(1, 0.1) self.layout.add_widget(self.info.get_widget()) self.input_uname = Modify(TextInput()) self.input_uname.size(1, 0.1) self.input_uname.text("To: ") self.input_message = Modify(TextInput()) self.input_message.size(1, 0.6) self.input_message.text("Message: ") self.send = Modify(Button(text="Send", on_press=self.send)) self.send.size(1, 0.3) self.send.background_color(0.3, 0.6, 1, 1) self.cancel = Modify(Button(text="Cancel", on_press=self.back)) self.cancel.size(1, 0.3) self.cancel.background_color(0.3, 0.6, 1, 1) self.layout.add_widget(self.input_uname.get_widget()) self.layout.add_widget(self.input_message.get_widget()) self.layout.add_widget(self.send.get_widget()) self.layout.add_widget(self.cancel.get_widget())
def display_message_func(self): """ Provide Ui rules for displaying messages """ self.display_message.multiline = True self.display_message.disabled = True self.display_message = Modify(self.display_message) self.display_message.size(1, 0.7)
def get_conversations(self): """ Get all conversation of the user from the business logic and display it in the ui """ self.message_list = self.mi.get_conversations() for item in self.message_list: item_button = Modify(ConvoItem(item)) item_button.size(1, 0.3) item_button.background_color(0.3, 0.6, 1, 1) self.left_layout.add_widget(item_button.get_widget())
def __init__(self, name): Screens.__init__(self, name) self.main_layout = BoxLayout(padding=10) self.mi = MessageInterface(GlobalData._user_model) self.left_layout = BoxLayout(padding=10, orientation='vertical') convo_label = Modify( Label(text=GlobalData._user_model.get_username() + "'s Conversations")) convo_label.size(1, 0.2) self.new_convo = Modify( Button(text="Compose New Message", on_press=self.start_new)) self.new_convo.size(1, 0.2) self.new_convo.background_color(0.4, 1, 1, 1) self.new_convo.text_color(1, 1, 1, 1) self.left_layout.add_widget(convo_label.get_widget()) self.left_layout.add_widget(self.new_convo.get_widget()) self.right_layout = BoxLayout(padding=10, orientation='vertical') self.message_list = list() self.get_conversations() self.display_message = TextInput(text="No Message Selected") self.display_message_func() display_layout = GridLayout(rows=1) display_layout.add_widget(self.display_message.get_widget()) self.right_layout.add_widget(display_layout) self.send_message = TextInput() self.send_message.disabled = True self.send_message = Modify(self.send_message) self.send_message.size(1, 0.4) self.right_layout.add_widget(self.send_message.get_widget()) self.send_button = Modify(Button(text="Send", on_press=self.send)) self.send_button.size(1, 0.2) self.send_button.background_color(0.3, 0.6, 1, 0.8) self.send_button.get_widget().disabled = True self.right_layout.add_widget(self.send_button.get_widget())
class MessageScreen(Screens): """ Init all ui elements and connects to business and data logic for messages :param name: The name of the screen """ def __init__(self, name): Screens.__init__(self, name) self.main_layout = BoxLayout(padding=10) self.mi = MessageInterface(GlobalData._user_model) self.left_layout = BoxLayout(padding=10, orientation='vertical') convo_label = Modify( Label(text=GlobalData._user_model.get_username() + "'s Conversations")) convo_label.size(1, 0.2) self.new_convo = Modify( Button(text="Compose New Message", on_press=self.start_new)) self.new_convo.size(1, 0.2) self.new_convo.background_color(0.4, 1, 1, 1) self.new_convo.text_color(1, 1, 1, 1) self.left_layout.add_widget(convo_label.get_widget()) self.left_layout.add_widget(self.new_convo.get_widget()) self.right_layout = BoxLayout(padding=10, orientation='vertical') self.message_list = list() self.get_conversations() self.display_message = TextInput(text="No Message Selected") self.display_message_func() display_layout = GridLayout(rows=1) display_layout.add_widget(self.display_message.get_widget()) self.right_layout.add_widget(display_layout) self.send_message = TextInput() self.send_message.disabled = True self.send_message = Modify(self.send_message) self.send_message.size(1, 0.4) self.right_layout.add_widget(self.send_message.get_widget()) self.send_button = Modify(Button(text="Send", on_press=self.send)) self.send_button.size(1, 0.2) self.send_button.background_color(0.3, 0.6, 1, 0.8) self.send_button.get_widget().disabled = True self.right_layout.add_widget(self.send_button.get_widget()) def on_init(self): """ Final inits that the class should make before being ran """ '''list of all conversations''' self.main_layout.add_widget(self.left_layout, 1) '''display specific messages''' self.main_layout.add_widget(self.right_layout, 0) self.add_widget(self.main_layout) def get_conversations(self): """ Get all conversation of the user from the business logic and display it in the ui """ self.message_list = self.mi.get_conversations() for item in self.message_list: item_button = Modify(ConvoItem(item)) item_button.size(1, 0.3) item_button.background_color(0.3, 0.6, 1, 1) self.left_layout.add_widget(item_button.get_widget()) def display_message_func(self): """ Provide Ui rules for displaying messages """ self.display_message.multiline = True self.display_message.disabled = True self.display_message = Modify(self.display_message) self.display_message.size(1, 0.7) def update(self): """ Update the message by checking across the business logic and update the ui upon getting a new message. """ try: if GlobalData._current_convo is not None: message = self.mi.get_message(GlobalData._current_convo) if self.send_message.get_widget().disabled is True: self.send_message.get_widget().disabled = False self.send_button.get_widget().disabled = False text = "" for talk in message: text = text + "___________________________________________\n" text = text + "Sender: " + talk['sender'] + "\n" text = text + "Message: " + talk['content'] + " \n" text = text + "Time Sent: " + talk['time'] + " \n" self.display_message.get_widget().text = text except ValueError: pass def send(self, param): """ Send a new message to a the user currently in coversation with the logged in user. """ if GlobalData._current_convo is not None: if len(self.send_message.get_widget().text) > 0: self.mi.send_message(GlobalData._current_convo, self.send_message.get_widget().text) self.send_message.get_widget().text = "" else: Error(title="Message Error", content=Label(text="No blank messages")).open() def start_new(self, param): """ Switch to the compose screen for starting a new message string to a new user """ self.display_message.text("No Message Selected") self.send_message.get_widget().disabled = True self.send_button.get_widget().disabled = True Screens._manager.active_screen("new_messages")
class ComposeScreen(Screens): """ Init all ui elements and connects to business and data logic for messages :param name: The name of the screen """ def __init__(self, name): Screens.__init__(self, name) self.sending_clear = False self.message_clear = False self.layout = BoxLayout(padding=5, orientation='vertical') self.info = Modify(Label(text="New Messages")) self.info.size(1, 0.1) self.layout.add_widget(self.info.get_widget()) self.input_uname = Modify(TextInput()) self.input_uname.size(1, 0.1) self.input_uname.text("To: ") self.input_message = Modify(TextInput()) self.input_message.size(1, 0.6) self.input_message.text("Message: ") self.send = Modify(Button(text="Send", on_press=self.send)) self.send.size(1, 0.3) self.send.background_color(0.3, 0.6, 1, 1) self.cancel = Modify(Button(text="Cancel", on_press=self.back)) self.cancel.size(1, 0.3) self.cancel.background_color(0.3, 0.6, 1, 1) self.layout.add_widget(self.input_uname.get_widget()) self.layout.add_widget(self.input_message.get_widget()) self.layout.add_widget(self.send.get_widget()) self.layout.add_widget(self.cancel.get_widget()) def on_init(self): """ Final inits that the class should make before being ran """ self.add_widget(self.layout) def update(self): pass def send(self, parm): """ Send a new message to the user with the valid username provided """ to_name = self.filter_logic(self.input_uname.get_widget().text, "to:", len("to:")) if to_name is None: Error( title="Username Error", content=Label(text="Please provide a valid username")).open() else: to_id = GlobalData._user_model.get_user(to_name) if to_id is None: Error(title="Username Error", content=Label(text="User not found")).open() else: to_id = to_id['uid'] message_name = self.filter_logic( self.input_message.get_widget().text, "Message:", len("Message:")) if message_name is None: Error(title="Messgae Error", content=Label(text="Please Proper fill " + "the message field")).open() else: message_interface = MessageInterface( GlobalData._user_model) message_interface.send_message(to_id, message_name) GlobalData._current_convo = to_id self.input_uname.text("to:") self.input_message.text("message:") Screens._manager.active_screen("messages") def filter_logic(self, text, holder, width): """ Filter through the information in a specific text field and get useful data :param text: the text of the text input :param holder: the placeholder in the text input :param the length of the placeholder """ if len(text) > 0: reciever = text.strip() if len(reciever) > width: if reciever[:width].lower() == holder.lower(): reciever = reciever[width:].strip() else: reciever = reciever.strip() return reciever else: return None else: return None def back(self, param): """ Return to the message ui screen """ GlobalData._current_convo = None Screens._manager.active_screen("messages")