def run(self):
        while True:
            try:
                all_files_and_folders_in_current_folder = list(self.ftp.nlst())
                if "image_source_to_retrieve.jpg" not in all_files_and_folders_in_current_folder:
                    return_code, crude_frame = self.video_stream.read()

                    if crude_frame is not None:
                        frame = cv2.cvtColor(crude_frame, cv2.COLOR_BGR2RGB)
                        unprocessed_image_object = Image.fromarray(frame)
                        unprocessed_image_object.save(self.temp_image_to_send_filepath)
                        # We save the image to a file, that we will open to send to the FTP, quickly coded.

                        binary_image_file = open(self.temp_image_to_send_filepath, "rb")

                        time_start_upload = time.time()
                        self.ftp.storbinary("STOR " + "image_source_writing.jpg", binary_image_file)
                        self.ftp.rename("image_source_writing.jpg", "image_source_to_retrieve.jpg")
                        self.count_send_source_images += 1
                        print(f"Image source #{self.count_send_source_images} has been fully send and renamed in {time.time() - time_start_upload}s")
                    else:
                        raise Exception("The webcam was not correctly identified. Try changing the index of the VideoCapture of the video_stream variable.")

            except Exception as error:
                print(f"Error : {error}")
                self.ftp = ftp_factory.get_ftp(extra_filepath_to_navigate_to="/images")
                print(f"Upload image source ftp client has been reinitialized")

            time.sleep(0.1)
 def __init__(self):
     threading.Thread.__init__(self)
     self.temp_image_generated_to_send_filepath = os.path.join(
         temp_folderpath, "image_generated_to_send.jpg")
     self.ftp = ftp_factory.get_ftp(extra_filepath_to_navigate_to="/images")
     self.count_send_generated_images = 0
     self.last_modified_time_of_image_generated_to_send = 0
     self.new_generated_image_to_send_has_been_created = False
     self.last_generated_image_has_completed_its_upload = True
    def __init__(self, video_stream: cv2.VideoCapture):
        threading.Thread.__init__(self)
        self.video_stream = video_stream

        self.temp_image_to_send_filepath = os.path.join(temp_folderpath, "image_source_to_send.jpg")
        self.ftp = ftp_factory.get_ftp(extra_filepath_to_navigate_to="/images")

        self.count_send_source_images = 0
        self.seconds_interval_to_wait_before_sends = 0.25
    def __init__(self):
        threading.Thread.__init__(self)
        self.ftp = ftp_factory.get_ftp(extra_filepath_to_navigate_to="/images")

        self.temp_image_processed_writing_filepath = os.path.join(temp_folderpath, "image_processed_received_writing.jpg")
        self.temp_image_processed_complete_filepath = os.path.join(temp_folderpath, "image_generated_received_complete.jpg")

        self.count_received_generated_images = 0
        self.received_new_received_generated_image_not_yet_displayed = False
        self.received_at_least_one_generated_image = False
    def __init__(self):
        threading.Thread.__init__(self)
        self.temp_image_source_received_writing_filepath = os.path.join(
            temp_folderpath, "image_source_received_writing.jpg")
        self.temp_image_source_received_complete_filepath = os.path.join(
            temp_folderpath, "image_source_received_complete.jpg")

        self.ftp = ftp_factory.get_ftp(extra_filepath_to_navigate_to="/images")
        self.count_received_images = 0
        self.image_source_been_modified_and_not_yet_used = False
        self.retrieved_image_at_least_once = False
    def __init__(self):
        threading.Thread.__init__(self)
        self.ftp = ftp_factory.get_ftp()
        self.count_lines_last_retrieved_channel_infos_file = 0

        self.has_style_name_just_changed = False
        self.current_selected_style_name_or_type = None
        self.last_selected_style_name_or_type = None
        self.need_to_save_pictures = False
        self.additional_text_to_use_in_filenames = None

        self.finished_upload_of_last_channel_infos = False
    def run(self):
        while True:
            if self.new_generated_image_to_send_has_been_created is True:
                # We check if we need to send a new generated image, like so we do not spam the
                # network, but only send the image if it is a new one that has been generated.
                try:
                    all_files_and_folders_in_current_folder = list(
                        self.ftp.nlst())
                    if "image_generated_to_retrieve.jpg" not in all_files_and_folders_in_current_folder:
                        if os.path.isfile(
                                self.temp_image_generated_to_send_filepath):
                            current_file_last_modified_time = os.path.getmtime(
                                self.temp_image_generated_to_send_filepath)
                            if current_file_last_modified_time != self.last_modified_time_of_image_generated_to_send:
                                binary_image_file = open(
                                    self.temp_image_generated_to_send_filepath,
                                    "rb")

                                time_start_upload = time.time()
                                self.ftp.storbinary(
                                    "STOR " + "image_generated_writing.jpg",
                                    binary_image_file)
                                self.count_send_generated_images += 1

                                self.ftp.rename(
                                    "image_generated_writing.jpg",
                                    "image_generated_to_retrieve.jpg")
                                print(
                                    f"Generated image {self.count_send_generated_images} has been fully uploaded and renamed in {time.time() - time_start_upload} seconds."
                                )

                                self.last_modified_time_of_image_generated_to_send = current_file_last_modified_time
                                self.new_generated_image_to_send_has_been_created = False
                                self.last_generated_image_has_completed_its_upload = True
                        else:
                            raise Exception(
                                f"No file was found at {self.temp_image_generated_to_send_filepath}"
                            )

                except Exception as error:
                    print(f"Error : {error}")
                    self.ftp = ftp_factory.get_ftp(
                        extra_filepath_to_navigate_to="/images")
                    print(
                        f"Upload generated image ftp client has been reinitialized"
                    )

            time.sleep(0.1)
    def run(self):
        while True:
            try:
                all_files_and_folders_in_current_folder = list(self.ftp.nlst())
                if FILENAME_CHANNEL_INFOS_TXT in all_files_and_folders_in_current_folder:
                    time_start_retrieve = time.time()

                    self.count_lines_last_retrieved_channel_infos_file = 0
                    self.ftp.retrlines(f"RETR {FILENAME_CHANNEL_INFOS_TXT}", self.lines_been_retrieved)
                    print(f"Delay to retrieve the channel infos from the ftp : {time.time() - time_start_retrieve}s")

            except Exception as error:
                print(f"Error : {error}")
                self.ftp = ftp_factory.get_ftp()
                print(f"Get channel infos from ftp ftp client has been reinitialized")

            time.sleep(0.1)
    def run(self):
        while True:
            try:
                with open(os.path.join(temp_folderpath, FILENAME_CHANNEL_INFOS_TXT), "w") as txt_file:
                    txt_file.write(str({"test": 10000}))

                with open(os.path.join(temp_folderpath, FILENAME_CHANNEL_INFOS_TXT), "rb") as txt_file:
                    time_start_upload = time.time()
                    self.ftp.storlines(f"STOR {FILENAME_CHANNEL_INFOS_TXT}", txt_file)
                    print(f"Delay to upload the channel infos to the ftp : {time.time() - time_start_upload}s")

            except Exception as error:
                print(f"Error : {error}")
                self.ftp = ftp_factory.get_ftp()
                print(f"Get channel infos from ftp ftp client has been reinitialized")

            time.sleep(0.1)
    def run(self):
        while True:
            if self.received_new_received_generated_image_not_yet_displayed is False:
                try:
                    all_files_and_folders_in_current_folder = list(self.ftp.nlst())
                    if FILENAME_IMAGE_GENERATED_TO_RETRIEVE_JPG in all_files_and_folders_in_current_folder:
                        time_start_retrieve = time.time()
                        self.ftp.retrbinary(f"RETR {FILENAME_IMAGE_GENERATED_TO_RETRIEVE_JPG}", open(self.temp_image_processed_writing_filepath, "wb").write)
                        self.count_received_generated_images += 1

                        all_files_and_folders_in_current_folder_after_retrieving_generated_image = list(self.ftp.nlst())
                        if FILENAME_IMAGE_GENERATED_TO_RETRIEVE_JPG in all_files_and_folders_in_current_folder_after_retrieving_generated_image:
                            self.ftp.delete("image_generated_to_retrieve.jpg")
                            print(f"Deleted the retrieved generated image file #{self.count_received_generated_images} from the ftp")
                        print(f"Retrieved generated image #{self.count_received_generated_images} in {time.time() - time_start_retrieve}")

                        if os.path.isfile(self.temp_image_processed_writing_filepath):
                            need_to_update_image = False
                            if os.path.isfile(self.temp_image_processed_complete_filepath):
                                if open(self.temp_image_processed_writing_filepath, "rb").read() != open(self.temp_image_processed_complete_filepath, "rb").read():
                                    need_to_update_image = True
                                else:
                                    print(f"Received generated image #{self.count_received_generated_images} is the same as generated image #{self.count_received_generated_images - 1}.")
                            else:
                                need_to_update_image = True

                            if self.received_at_least_one_generated_image is False:
                                print(f"Since received generated image #{self.count_received_generated_images} was the first received image, it will be displayed what so ever.")
                                need_to_update_image = True
                                self.received_at_least_one_generated_image = True

                            if need_to_update_image is True:
                                if os.path.isfile(self.temp_image_processed_complete_filepath):
                                    os.remove(self.temp_image_processed_complete_filepath)

                                os.rename(self.temp_image_processed_writing_filepath, self.temp_image_processed_complete_filepath)
                                print(f"New generated image #{self.count_received_generated_images} has been received.")
                                self.received_new_received_generated_image_not_yet_displayed = True

                except Exception as error:
                    print(f"Error : {error}")
                    self.ftp = ftp_factory.get_ftp(extra_filepath_to_navigate_to="/images")
                    print(f"Save generated image ftp client has been reinitialized")

            time.sleep(0.1)
    def run(self):
        while True:
            if self.image_source_been_modified_and_not_yet_used is False:
                # We make sure that the image has been used before changing it, otherwise we
                # might be writing again to the filepath while or before its being accessed.
                try:
                    all_files_and_folders_in_current_folder = list(
                        self.ftp.nlst())
                    if "image_source_to_retrieve.jpg" in all_files_and_folders_in_current_folder:
                        time_start_retrieve = time.time()
                        self.ftp.retrbinary(
                            "RETR " + "image_source_to_retrieve.jpg",
                            open(
                                self.
                                temp_image_source_received_writing_filepath,
                                "wb").write)
                        self.ftp.delete("image_source_to_retrieve.jpg")
                        print(
                            f"Delay to retrieve and delete the image source from the ftp : {time.time() - time_start_retrieve}s"
                        )

                        if os.path.isfile(
                                self.
                                temp_image_source_received_writing_filepath):
                            need_to_update_image = False
                            if os.path.isfile(
                                    self.
                                    temp_image_source_received_complete_filepath
                            ):
                                if open(
                                        self.
                                        temp_image_source_received_writing_filepath,
                                        "rb"
                                ).read() != open(
                                        self.
                                        temp_image_source_received_complete_filepath,
                                        "rb").read():
                                    need_to_update_image = True
                            else:
                                need_to_update_image = True

                            if self.retrieved_image_at_least_once is False:
                                need_to_update_image = True
                                self.retrieved_image_at_least_once = True

                            if need_to_update_image is True:
                                if os.path.isfile(
                                        self.
                                        temp_image_source_received_complete_filepath
                                ):
                                    os.remove(
                                        self.
                                        temp_image_source_received_complete_filepath
                                    )

                                os.rename(
                                    self.
                                    temp_image_source_received_writing_filepath,
                                    self.
                                    temp_image_source_received_complete_filepath
                                )

                                self.image_source_been_modified_and_not_yet_used = True
                                self.count_received_images += 1
                                print(
                                    f"The #{self.count_received_images} image source has been received."
                                )

                except Exception as error:
                    print(f"Error : {error}")
                    self.ftp = ftp_factory.get_ftp(
                        extra_filepath_to_navigate_to="/images")
                    print(
                        f"Save image source ftp client has been reinitialized")

            time.sleep(0.1)