def __init__(self, **kwargs): super().__init__(**kwargs) self.cols = 1 self.rows = 2 self.history = ScrollableLabel(height=Window.size[-1]*0.9, size_hint_y=None) self.add_widget(self.history) self.new_message = TextInput( width=Window.size[0]*0.8, size_hint_x=None, multiline=False ) self.send = Button(text="Send") self.send.bind(on_press=self.send_message) bottom_line = GridLayout(cols=2) bottom_line.add_widget(self.new_message) bottom_line.add_widget(self.send) self.add_widget(bottom_line) Window.bind(on_key_down=self.on_key_down) Clock.schedule_once(self.focus_text_input, 1) client.start_listening(self.incoming_message, show_error) self.bind(size=self.adjust_fields)
def __init__(self, **kwargs): super().__init__(**kwargs) # We are going to use 1 column and 2 rows self.cols = 1 self.rows = 2 # First row is going to be occupied by our scrollable label # We want it be take 90% of app height self.history = ScrollableLabel(height=Window.size[1] * 0.9, size_hint_y=None) self.add_widget(self.history) # In the second row, we want to have input fields and Send button # Input field should take 80% of window width # We also want to bind button click to send_message method self.new_message = TextInput(width=Window.size[0] * 0.8, size_hint_x=None, multiline=False) self.send = Button(text="Send") self.send.bind(on_press=self.send_message) # To be able to add 2 widgets into a layout with just one collumn, we use additional layout, # add widgets there, then add this layout to main layout as second row bottom_line = GridLayout(cols=2) bottom_line.add_widget(self.new_message) bottom_line.add_widget(self.send) self.add_widget(bottom_line) Window.bind(on_key_down=self.on_key_down) Clock.schedule_once(self.focus_text_input, 1) client.start_listening(self.incoming_message, show_error) self.bind(size=self.adjust_fields)
def __init__(self, **kwargs): super().__init__(**kwargs) self.cols = 1 self.rows = 2 # First row is going to be occupied by our scrollable label # We want it be take 90% of app height self.history = ScrollableLabel(height=Window.size[1] * 0.9, size_hint_y=None) self.add_widget(self.history) self.new_message = TextInput(width=Window.size[0] * 0.8, size_hint_x=None, multiline=False) self.send = Button(text="Send") self.send.bind(on_press=self.send_message) # To be able to add 2 widgets into a layout with just one collumn, we use additional layout, # add widgets there, then add this layout to main layout as second row bottom_line = GridLayout(cols=2) bottom_line.add_widget(self.new_message) bottom_line.add_widget(self.send) self.add_widget(bottom_line) # Gets called when either Send button or Enter key is being pressed # (kivy passes button object here as well, but we don;t care about it) # To be able to send message on Enter key, we want to listen to keypresses Window.bind(on_key_down=self.on_key_down) # We also want to focus on our text input field # Kivy by default takes focus out out of it once we are sending message # The problem here is that 'self.new_message.focus = True' does not work when called directly, # so we have to schedule it to be called in one second # The other problem is that schedule_once() have no ability to pass any parameters, so we have # to create and call a function that takes no parameters Clock.schedule_once(self.focus_text_input, 1) client.start_listening(self.incoming_message, show_error)
def __init__(self): # Get a username before launching the main chat application username_popup = tkinter.Tk() username_popup.withdraw() self.username = simpledialog.askstring("Username", "Please enter a username", parent=username_popup) # Connect to the server and assign the username entered above if not client.connect(IP, PORT, self.username, show_error): return # Start the GUI Thread(target=self.loop).start() # Start listening for messages from the server client.start_listening(self.receive_message, show_error)
def __init__(self, **kwargs): super().__init__(**kwargs) self.cols = 1 self.rows = 3 self.padding = 5 self.add_widget(MDLabel()) self.history = ScrollableLabel( height=Window.size[1]*0.788, size_hint_y=None) self.add_widget(self.history) self.new_msg = MDTextField( size_hint_x=None, multiline=False, pos_hint={'center_x':0,'center_y':1}) bottom_line = GridLayout(cols=1) bottom_line.add_widget(self.new_msg) self.add_widget(bottom_line) Window.bind(on_key_down=self.on_key_down) Clock.schedule_once(self.focus_text_input, 3) client.start_listening(self.incoming_message, show_error) self.bind(size=self.adjust_fields)