def on_sticker_gallery_img_click(self, obj_response, clicked_sticker_data): self._clicked_img_name = clicked_sticker_data[0] if clicked_sticker_data[1] != 'uploaded': super().on_img_clicked(obj_response) else: self._clicked_img_path = utils.create_filepath( STICKER_FOLDER, self._clicked_img_name)
def on_wall_gallery_img_click(self, obj_response, clicked_wall_data): self._clicked_img_name = clicked_wall_data[0] self.__common_substring_of_wall_and_appropriate_mask_names = self._clicked_img_name.split( 'wall-')[-1].split('.')[0] if clicked_wall_data[1] != 'uploaded': self.__response_wall_to_canvas(obj_response) else: self._clicked_img_path = utils.create_filepath( WALL_FOLDER, self._clicked_img_name) self._gallery_img_thumb_path = utils.create_filepath( self._IMG_THUMBNAILS, self._clicked_img_name) self.__response_mask_to_canvas(obj_response)
def on_input_custom_mask_bttn_click(self, obj_response, custom_mask_data): self.__get_loaded_custom_mask_data(custom_mask_data) custom_mask_with_black_path = utils.create_filepath( MASK_WITH_BLACK_FOLDER, custom_mask_data[0]) custom_mask_with_transparent_path = utils.create_filepath( MASK_WITH_TRANSPARENT_FOLDER, custom_mask_with_black_path.split('/')[-1]) self.__delete_old_masks() imgutils.decode_img_and_save_to_folder( self.__custom_mask_src, custom_mask_with_transparent_path) imgutils.decode_img_and_save_to_folder(self.__custom_mask_src, custom_mask_with_black_path) imgutils.transparent_to_black(custom_mask_with_black_path) self.__custom_mask_src = imgutils.encode_img( custom_mask_with_black_path) self.__define_target_html_element_id_for_mask_adding() self.response_custom_mask(obj_response)
def __get_mask_path(self, mask_folder): self.__common_substring_of_wall_and_appropriate_mask_names = self._gallery_img_thumb_path.split( 'wall-')[-1].split('.')[0] if utils.find_file_in_folder_by_filename_substring( mask_folder, self. __common_substring_of_wall_and_appropriate_mask_names) != None: mask_path = utils.find_file_in_folder_by_filename_substring( mask_folder, self.__common_substring_of_wall_and_appropriate_mask_names) else: mask_name = 'mask-{}{}'.format( self.__common_substring_of_wall_and_appropriate_mask_names, '.png') mask_path = utils.create_filepath(mask_folder, mask_name) imgutils.process_mask(self._gallery_img_thumb_path, mask_path) return mask_path
def download_file(item, path, course, output_dir): filepath = create_filepath(course, path) description = item["Description"]["Html"] topic_type = item["TopicType"] title = item["Title"] if topic_type == 1: filename = create_filename(item) full_path = f"{output_dir}/{filepath}/{filename}" # These documents are real files that we want to download download_from_url(f"""{ufora}{item["Url"]}""", full_path) if item["Url"].endswith(".html"): # HTML files on Ufora need a little special treatment # We'll prepend a title, <base> tag and convert them to pdf with open(full_path, "r") as f: content = f.read() filename_without_extension = ".".join(filename.split(".")[:-1]) description_path = f"{output_dir}/{filepath}/{filename_without_extension}.pdf" create_metadata(description_path, content, filename_without_extension) new_content = f"<base href={ufora}><h1>{title}</h1>{content}" with open(full_path, "w") as f: f.write(new_content) elif description: # Choosing this filename might cause an overlap... filename_without_extension = ".".join(filename.split(".")[:-1]) description_path = f"{output_dir}/{filepath}/{filename_without_extension}.pdf" create_metadata(description_path, description, filename_without_extension) elif topic_type == 3: # These documents are just clickable links, we'll render them in a pdf url = item["Url"] filename = create_filename_without_extension(item) full_path = f"{output_dir}/{filepath}/{filename}" create_metadata(f"{full_path}.pdf", f"<a href={url}>{url}</a>{description}", item["Title"]) else: print(f"Don't know this topic type: {topic_type}") exit()
def download_module(item, path, course, output_dir): description = item["Description"]["Html"] if description: filepath = create_filepath(course, path) description_path = f"{output_dir}/{filepath}/metadata.pdf" create_metadata(description_path, description, filepath.split("/")[-1])
def __on_custom_img_loaded_to_canvas(self): custom_img_name, custom_img_src = self.__custom_img_data[ 0], self.__custom_img_data[1] custom_img_path = utils.create_filepath(TMP_FOLDER, custom_img_name) imgutils.decode_img_and_save_to_folder(custom_img_src, custom_img_path) return custom_img_path
def __create_mask_with_transparent(self): black_mask_path = self.__get_mask_path(MASK_WITH_BLACK_FOLDER) transparent_mask_path = utils.create_filepath( MASK_WITH_TRANSPARENT_FOLDER, black_mask_path.split('/')[-1]) imgutils.black_to_transparent(black_mask_path, transparent_mask_path)
def on_img_clicked(self, obj_response): self._clicked_img_path = utils.create_filepath(self._IMG_FOLDER, self._clicked_img_name) self._clicked_img_src = imgutils.encode_img(self._clicked_img_path) self._send_img_to_canvas(obj_response)
def _create_img_thumb_path(self): return utils.create_filepath(self._IMG_THUMBNAILS, self._loaded_img_path.split('/')[-1])
def _create_img_path(self): img_file_ext = utils.get_file_extension(self._loaded_img_src) img_name = utils.create_filename('{}-'.format(self._img_name_prefix), img_file_ext) return utils.create_filepath(self._IMG_FOLDER, img_name)