-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (35 loc) · 1.56 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
from args import command_line_arguments
from img_to_mc import image, object
argv = command_line_arguments(object.itm_Image.Convert, [
'progress_connect',
'finish_connect',
'error_connect'
],
{
'image_file': (str, command_line_arguments.OBLIGATORY),
'save_file': (str, './output/{img_name}.mcfunction')
}
)
all_args = argv.get_arguments()
other_args = argv.get_otherArgs()
funct_args = argv.get_functArgs()
image_file_path = other_args['image_file']
save_file_path = other_args['save_file'].format(img_name=os.path.splitext(os.path.basename(image_file_path))[0])
imaget = image.load_file(image_file_path)
def Convert_progress(x, y, color, progress, nomber_pixls):
print(f'x:{str(x):4} y:{str(y):4} | {str(color):20} | {progress}/{str(nomber_pixls):5} = {progress/nomber_pixls*100} %')
def Convert_finish(number_pixels):
print(f"Programme finish | Total particles : {number_pixels}")
def Convert_error(e):
print(f'ERROR : {e}')
image_formate = imaget.Convert(**funct_args ,progress_connect=Convert_progress, finish_connect=Convert_finish, error_connect=Convert_error)
save_success = image_formate.save(save_file_path)
# Si l'anre
if save_success:
if os.path.exists(save_file_path) and os.path.getsize(save_file_path) > 0:
print(f'The process went well. The result was saved in "{os.path.abspath(save_file_path)}"')
else:
print(f"An error has occurred. The {save_file_path} file was not saved or is empty.")
else:
print(f"An error occurred when saving the {save_file_path} file")