Skip to content

Commit 8a7edab

Browse files
committed
Fix some issues
1 parent 1aab4a8 commit 8a7edab

File tree

1 file changed

+45
-24
lines changed

1 file changed

+45
-24
lines changed

converter_rgb332.py

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,58 @@ def convert_rgb_to_rgb332(image_load, path_file):
4040
def program_menu():
4141
#Simple menu with options to execute
4242

43-
while True:
44-
45-
print(' Converter RGB to RGB332:')
46-
print(' [1] -- Select an image --')
47-
print(' [2] -- Save as a file --')
48-
print(' [3] -- Exit program --')
43+
try:
44+
while True:
45+
46+
print(' Converter RGB to RGB332:')
47+
print(' [1] -- Select an image --')
48+
print(' [2] -- Save as a file --')
49+
print(' [3] -- Exit program --')
4950

50-
option = input(' Please choose an option [1-3]: ')
51+
option = input(' Please choose an option [1-3]: ')
5152

52-
if option == '1':
53+
if option == '1':
54+
55+
try:
56+
print(' [First option has selected]')
57+
im_path = im_load()
58+
print('\n [INFO]: Image has loaded from: ' + im_path + '\n')
59+
except TypeError:
60+
print()
61+
print(' [WARN]: Please choose an image to load \n')
5362

54-
print(' [First option has selected]')
55-
im_path = im_load()
56-
print('\n INFO: Image has loaded from: ' + im_path + '\n')
63+
elif option == '2':
64+
65+
try:
66+
print(' [Second option has selected]')
67+
save_output = file_save()
68+
convert_rgb_to_rgb332(im_path, save_output)
69+
print('\n [INFO]: File has saved in: ' + save_output + '\n')
70+
except TypeError:
71+
print()
72+
print(' [WARN]: Something went wrong, please try again \n')
73+
74+
except UnboundLocalError:
75+
print()
76+
print(' [WARN]: No data to save, please load image first to the program \n')
5777

58-
elif option == '2':
59-
60-
print(' [Second option has selected]')
61-
save_output = file_save()
62-
convert_rgb_to_rgb332(im_path, save_output)
63-
print('\n [INFO]: File has saved in: ' + save_output + '\n')
78+
elif option == '3':
79+
80+
print(' Third option has selected')
81+
print('\n [INFO]: Program has closed \n')
82+
exit()
6483

65-
elif option == '3':
66-
67-
print(' Third option has selected')
68-
print('\n [INFO]: Program has closed \n')
69-
exit()
84+
else:
7085

71-
else:
86+
print('\n [WARNING]: Something went wrong, please choose option again \n')
7287

73-
print('\n [WARNING]: Something went wrong, please choose option again \n')
88+
except EOFError:
89+
print()
90+
print(' [ERROR]: Unexpected action in program')
91+
except KeyboardInterrupt:
92+
print()
93+
print(' [INFO]: Program has closed unexpected ')
94+
exit()
7495

7596
msg = open("non-GUI/logo", "r")
7697
print(msg.read())

0 commit comments

Comments
 (0)