Exemplo n.º 1
0
    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)
        socket_client.start_listening(self.incoming_message, show_error)
        self.bind(size=self.adjust_fields)
Exemplo n.º 2
0
    def __init__(self, **kwargs):
        # run init method from GridLayout
        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)

        # add grid with two columns containing message and send button
        bottom_line = GridLayout(cols=2)
        bottom_line.add_widget(self.new_message)
        bottom_line.add_widget(self.send)
        # add this to the widget
        self.add_widget(bottom_line)

        # bind function to use enter key to be able to send a message
        Window.bind(on_key_down=self.on_key_down)

        Clock.schedule_once(self.focus_text_input, 1)
        socket_client.start_listening(self.incoming_message, show_error)
        self.bind(size=self.adjust_fields)
Exemplo n.º 3
0
    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 = ScrollableView(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)

        socket_client.start_listening(self.incoming_message, show_error)

        self.bind(size=self.adjust_fields)
Exemplo n.º 4
0
    def adjust_fields(self, *_):

        # Chat history height - 90%, but at least 50px for bottom new message/send button part
        if Window.size[1] * 0.1 < 50:
            new_height = Window.size[1] - 50
        else:
            new_height = Window.size[1] * 0.9
        self.history.height = new_height

        # New message input width - 80%, but at least 160px for send button
        if Window.size[0] * 0.2 < 160:
            new_width = Window.size[0] - 160
        else:
            new_width = Window.size[0] * 0.8
        self.new_message.width = new_width

        # Update chat history layout
        # self.history.update_chat_history_layout()
        Clock.schedule_once(self.history.update_chat_history_layout, 0.01)

        # 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)

        # And now, as we have out layout ready and everything set, we can start listening for incimmong messages
        # Listening method is going to call a callback method to update chat history with new messages,
        # so we have to start listening for new messages after we create this layout
        socket_client.start_listening(self.incoming_message, show_error)
Exemplo n.º 5
0
def connect(image):

    # Get information for sockets client
    port = 6007
    # ip = '127.0.0.1'
    ip = '192.168.1.100'
    username = '******'

    if not socket_client.connect(ip, port, username, show_error):
        return
    socket_client.send(image)

    socket_client.start_listening(incoming_message, show_error)
Exemplo n.º 6
0
    def __init__(self, chat_id, **kwargs):

        super().__init__(**kwargs)
        self.chat_id = chat_id
        self.cols = 1
        self.rows = 5
        self.get_chat_message()
        self.get_user_data()
        ws_token = WSRequests()
        self.token = ws_token.load_token()

        self.back_button = Button(text="Вергуться к списку чатов",
                                  size=(200, 20))
        self.back_button.bind(on_press=self.back_page)
        self.add_widget(self.back_button)

        self.title_chat = Label(text=self.title)

        self.add_widget(self.title_chat)

        self.participants = Label(
            text=f'Учасники чата: {self.get_participants()}')
        self.add_widget(self.participants)

        self.message_box = ScrollableLabel(height=Window.size[1] * 0.7,
                                           size_hint_y=None)
        self.add_widget(self.message_box)

        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)

        Clock.schedule_once(self.ccc, 0)

        Clock.schedule_once(self.focus_text_input, 1)

        socket_client.start_listening(self.incoming_message, self.chat_id,
                                      self.token, self.user_name)

        self.bind(size=self.adjust_fields)
        Clock.schedule_once(self.adjust_fields1, 0.01)
        Window.bind(on_key_down=self.on_key_down)
    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)

        # 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)

        # And now, as we have out layout ready and everything set, we can start listening for incimmong messages
        # Listening method is going to call a callback method to update chat history with new messages,
        # so we have to start listening for new messages after we create this layout
        socket_client.start_listening(self.incoming_message, show_error)

        self.bind(size=self.adjust_fields)
Exemplo n.º 8
0
    def start_server(self):
        """
        When clicking on connect button, it will try t connect to the server with the IP and port number entered.
        """
        print("start server")
        port = int(self.port.text)
        ip = self.ip.text
        username = self.agent.text

        if not socket_client.connect(ip, port, username, show_error):
            print("not connected")
            self.connected.text = "Not connected"
        else:
            print("connected to server")
            self.connected.text = "Connected"
            self.ip.text = ""
            self.port.text = ""
            socket_client.start_listening(self.incoming_message, show_error)
Exemplo n.º 9
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.cols = 1
        self.rows = 2

        self.history = Label(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.bind(on_press=self.send_message)

        #So we want row number 2 to have two columns instead of one, so we create a widget to do it,
        #instead of having the page be designed differently
        bottom_line = GridLayout(cols=2)
        bottom_line.add_widget(self.new_message)
        bottom_line.add_widget(self.send)
        self.add_widget(bottom_line)
        #To be able to send messages on key down, we need to listen for it
        Window.bind(on_key_down=self.on_key_down)
        Clock.schedule_once(self.focus_text_input, 1)
        socket_client.start_listening(self.incoming_message, show_error)
Exemplo n.º 10
0
    def __init__(
        self, **kwargs
    ):  #kwargs-double star allows us to pass through keyword arguments
        super().__init__(
            **kwargs
        )  #kwargs-double star allows us to pass through keyword arguments

        # We are going to use 1 column and 2 rows
        self.cols = 1
        self.rows = 2

        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
        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,
        bottom_line = GridLayout(cols=2)
        bottom_line.add_widget(self.new_message)
        bottom_line.add_widget(self.send)
        self.add_widget(bottom_line)

        # keypresses
        Window.bind(on_key_down=self.on_key_down)

        Clock.schedule_once(self.focus_text_input, 1)

        # And now, as we have out layout ready and everything set, we can start listening for incimmong messages

        socket_client.start_listening(self.incoming_message, show_error)
Exemplo n.º 11
0
    def __init__(self):
        self.count = 0
        socket_client.connect("127.0.0.1", 1234, "RailBot", self.show_error)

        self.vocab, self.documents, self.intent_categories = Intent(
        ).create_vocab()

        self.i = InferIntent()
        self.en = Entity()

        self.slots = {}
        self.pnr = None
        self.date = None
        self.intent = None

        self.query = socket_client.start_listening(self.incoming_message,
                                                   self.show_error)
        self.message = ''
Exemplo n.º 12
0
    def on_enter(self):
        print("Entered the screen")

        global SELECTED_THEME
        global THEMES
        if len(THEMES) == 0:
            SELECTED_THEME = ""
        else:
            SELECTED_THEME = random.sample(THEMES, 1)
        self.popup = Popup(title=f'Drawing: {str(SELECTED_THEME)}',
                           content=Label(text="You have 30 seconds to draw!"),
                           size_hint=(None, None),
                           size=(600, 400),
                           auto_dismiss=True)
        #self.popup.open()
        #self.popup.close()
        #Clock.schedule_once(self.close_popup, 3)
        paint_app.title = SELECTED_THEME

        socket_client.start_listening(self.incoming_message, show_error)
        num = 60
        self.add_widget(self.count)

        def count_it(num):
            if num == 0:
                fbo = Fbo(size=self.stencil.size, with_stencilbuffer=True)

                with fbo:
                    ClearColor(1, 1, 1, 0)
                    ClearBuffers()
                    img2 = self.paintscreen.bg.texture
                    fbo.add(self.stencil.canvas)
                    fbo.draw()
                    img = fbo.texture
                    fbo.remove(self.stencil.canvas)
                    self.remove_widget(self.paintscreen)
                    im = np.frombuffer(img.pixels, np.uint8)
                    data = np.reshape(im, (im.shape[0], 1)).tostring()

                    data2 = str(data)
                    data2 = str.encode(data2)

                    pix = np.frombuffer(data, np.uint8)
                    a = np.empty_like(pix)
                    a[:] = pix
                    texture = Texture.create(size=self.stencil.size)

                    texture.blit_buffer(a, colorfmt='rgba', bufferfmt='ubyte')
                    self.imge = Image(pos=(0, 0),
                                      size=self.paintscreen.stencil.size,
                                      texture=texture)
                    #self.paintscreen.stencil.add_widget(self.imge)

                    #img2 = self.paintscreen.grid_layout.bg.texture
                    im2 = np.frombuffer(img2.pixels, np.uint8)
                    data = np.reshape(im2, (im2.shape[0], 1)).tostring()

                    data2 = str(data)
                    data2 = str.encode(data2)

                    pix = np.frombuffer(data, np.uint8)
                    a2 = np.empty_like(pix)
                    a2[:] = pix

                    img2 = a2
                    print(img2.shape)

                    print(img2)
                    img1 = a
                    print(img1.shape)

                    import cv2
                    #setting alpha=1, beta=1, gamma=0 gives direct overlay of two images
                    # in theory this would give a direct overlay...
                    #img3 = cv2.addWeighted(img1, 1, img2, 1, 0)
                    #print(img3.shape)

                    im = img1.reshape(1200, 1200, 4)
                    # for i in range(0, 1200):
                    #     for j in range(0,1200):
                    #         points = im[i,j,:]
                    #         if (points[3] == 0):#points[0] == 255 & points[1] == 255 & points[2] == 255):
                    #             im[i,j,:] = [255,255,255,0]
                    img_2 = img2.reshape((1200, 1200, 4))
                    for i in range(0, 1200):
                        for j in range(0, 1200):
                            points1 = im[i, j, :]
                            if (points1[3] != 0):
                                img_2[i, j, :] = im[i, j, :]

                    socket_client.send(img_2)

                    while MESSAGE is None:
                        pass
                    if MESSAGE is not None:
                        new_img = MESSAGE
                    else:
                        new_img = img_2

                    texture = Texture.create(size=(1200, 1200))

                    texture.blit_buffer(np.reshape(new_img,
                                                   (1200 * 1200 * 4, )),
                                        colorfmt='rgba',
                                        bufferfmt='ubyte')

                    self.paintscreen = PaintScreen()
                    self.add_widget(self.paintscreen)
                    self.paintscreen.bg.texture = texture
                return
            num -= 1
            self.count.text = str(num)
            Clock.schedule_once(lambda dt: count_it(num), 1)

        Clock.schedule_once(lambda dt: count_it(1), 10)
Exemplo n.º 13
0
 def on_listen(self):
     socket_client.start_listening(self.incoming_message, show_error)
Exemplo n.º 14
0
 def message_listening(self, _):
     socket_client.start_listening(self.incomming_message, show_error)
Exemplo n.º 15
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        # self.user_list = ['join']
        # Window.color = (0,3,0,1)

        with self.canvas:

            # Color(.234, .456, .678, .9)  # set the colour

            # Seting the size and position of canvas
            self.rect = Rectangle(source='back2.jpg',
                                  pos=self.center,
                                  size=self.size)

            # Update the canvas as the screen size change
            self.bind(pos=self.update_rect, size=self.update_rect)

        self.cols = 1
        self.rows = 2

        # self.side_but = Button(text='cool')
        self.history = ScrollableLabel(height=Window.size[1] * 0.9,
                                       size_hint_y=None)
        self.history_recv = ScrollableLabel(height=Window.size[1] * 0.9,
                                            size_hint_y=None)
        # self.add_widget(self.side_but)
        side_bar = GridLayout(cols=3)
        self.box = BoxLayout(orientation='vertical')
        self.box.size_hint_x = .4

        # user_list = self.set_arr()
        # if len(user_list) > 0:
        # stack = Stack()

        # for i in stack.stk:
        self.side_label = MyLabel(text='Joined',
                                  pos=(20, 20),
                                  size_hint=(1, 0.5))

        self.side_label.text = user_list[0].upper()
        self.side_label.text = self.side_label.text
        self.side_label.font_size = '25sp'
        self.side_label.color = [0.41, 0.42, 0.74, 1]
        # self.side_label.text_size = (6,4)
        self.box.add_widget(self.side_label)
        # else:
        #     label = MyLabel(
        #             text="Joined Users",
        #             pos=(20, 20),
        #             size_hint=(1, 0.5))

        #     box.add_widget(label)

        # with label.canvas:
        #     Color(0, 1, 0, 0.25)
        #     Rectangle(pos=label.pos, size=label.size)

        side_bar.add_widget(self.box)
        side_bar.add_widget(self.history)
        side_bar.add_widget(self.history_recv)
        self.add_widget(side_bar)  #########################################

        self.new_message = TextInput(width=Window.size[0] * 0.8,
                                     size_hint_x=None,
                                     multiline=False)
        self.send = Button(text="Send", background_color=(0, 0, 255, 0.8))
        # self.send.halign = 'right'
        # self.send.size = 80,50
        # self.send.size_hint = None,None
        self.send.bind(on_press=self.send_message)

        bottom_line = GridLayout(cols=2,
                                 row_force_default=True,
                                 row_default_height=40)
        bottom_line.size_hint_y = .07
        bottom_line.add_widget(self.new_message)
        bottom_line.add_widget(self.send)

        # bottom_line = FloatLayout()
        # bottom

        self.add_widget(
            bottom_line)  ############################################

        Window.bind(on_key_down=self.on_key_down)

        Clock.schedule_once(self.focus_text_input, 1)
        socket_client.start_listening(self.incoming_message, show_error)
        self.bind(size=self.adjust_fields)