Skip to content

Commit 2a01a9d

Browse files
committed
Add release 1.0.0 beta
1 parent 563438e commit 2a01a9d

File tree

4 files changed

+79
-109
lines changed

4 files changed

+79
-109
lines changed

projects/MenuManager.py

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,62 @@
1+
from PIL import Image
2+
from PyQt5.QtWidgets import QApplication, QFileDialog
3+
from filters import *
4+
from movements import *
5+
16
class MenuManager:
2-
def __init__(self, tree):
3-
self.tree = tree
7+
def __init__(self):
8+
self.img = None
9+
self.function_dict = None
10+
self.tree = None
11+
self.loadImg()
412

5-
def displayMenu(self, tree=None):
6-
dict = self.tree if tree == None else tree
13+
def displayMenu(self, depth=0, tree=None, menuName="Menu"):
14+
dict = self.tree if tree is None else tree
15+
print("\n"+"==="*(3*depth)+"========"+menuName+"========"+"==="*(3*depth))
716
for index in dict:
817
branch = dict[index]
9-
print(f"{branch['name']} ({list(dict.keys())[list(dict.values()).index(branch)]})")
10-
listener = input("Your choice : ")
18+
print("\t" * depth + f"-{branch['name']} ({list(dict.keys())[list(dict.values()).index(branch)]})")
19+
listener = input("\nYour choice: ")
1120
if listener in dict.keys():
12-
if dict[listener]["type"] == "function" :
21+
if dict[listener]["type"] == "function":
22+
dict[listener]["function"](self.img)
23+
self.displayMenu()
24+
elif dict[listener]["type"] == "speFunction":
1325
dict[listener]["function"]()
1426
self.displayMenu()
15-
elif dict[listener]["type"] == "folder" :
16-
self.displayMenu(dict[listener]["children"])
17-
18-
else :
19-
quit = input("Do you want to quit ? (Y/n) : ")
20-
quits = ["y", "yes", "ouais", "q", "quit", "quitter", "exit", "bye", "oui", "si"]
27+
elif dict[listener]["type"] == "folder":
28+
self.displayMenu(depth + 1, dict[listener]["children"], dict[listener]["name"])
29+
else:
30+
quit = input("Do you want to quit? (Y/n): ")
31+
quits = ["y", "yes", "ouais", "q", "quit", "quitter", "exit", "bye", "o", "oui", "si", "return"]
2132
if quit.lower() not in quits:
2233
self.displayMenu()
34+
35+
def loadImg(self):
36+
_ = QApplication([])
37+
filePath, _ = QFileDialog.getOpenFileName()
38+
extension = filePath[-4:]
39+
if extension == ".png":
40+
self.img = Image.open(filePath)
41+
self.loadTree()
42+
self.displayMenu()
43+
elif filePath != "":
44+
self.tree = {"1": {"type": "speFunction", "function": self.loadImg, "name": "Load image (png)"}}
45+
self.displayMenu()
46+
47+
def loadTree(self):
48+
self.tree = {
49+
"1": {"type": "folder", "name": "Filters", "children": {
50+
"1": {"type": "function", "function": filterNegative, "name": "Negative filter"},
51+
"2": {"type": "function", "function": filterBlackAndWhite, "name": "Black and White filter"},
52+
"3": {"type": "function", "function": filterWithHexadecimal, "name": "Custom filter"},
53+
"4": {"type": "speFunction", "function": self.displayMenu, "name": "Retour au menu principal"},
54+
}},
55+
"2": {"type": "folder", "name": "Movements", "children": {
56+
"1": {"type": "function", "function": verticalMirror, "name": "Vertical mirror"},
57+
"2": {"type": "function", "function": horizontalMirror, "name": "Horizontal mirror"},
58+
"3": {"type": "function", "function": rotate, "name": "Rotate"},
59+
"4": {"type": "speFunction", "function": self.displayMenu, "name": "Retour au menu principal"},
60+
}},
61+
"3": {"type": "speFunction", "function": self.loadImg, "name": "Load another image (png)"}
62+
}

projects/filters.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from PIL import Image
22
from utils import *
33

4-
5-
def filtreNegative(img):
6-
4+
def filterNegative(img):
75
(largeur,hauteur)=img.size
86
newImg = Image.new('RGB', (largeur,hauteur), color = (0, 0, 0))
97
for i in range (largeur):
@@ -13,9 +11,20 @@ def filtreNegative(img):
1311
newImg.show()
1412
saveImg(newImg)
1513

16-
def filterWithMask(img, mask):
14+
15+
def filterWithHexadecimal(img):
16+
hexa = input("Enter the hexadecimal code of the color for the filter : ")
17+
while not isHexa(hexa):
18+
print("Wrong hexadecimal format.")
19+
hexa = input("Enter the hexadecimal code of the color for the filter (No to return to the menu): ")
20+
quits = ["n", "no", "non", "nan", "quit", "quitter", "exit", "return", "bye"]
21+
if hexa.lower() in quits :
22+
return
23+
24+
if len(hexa)==7:
25+
hexa = hexa[1:]
26+
mask = list(map(lambda x : int(x, 16), [hexa[0:2],hexa[2:4], hexa[4:]]))
1727
mask = normalizeMask(mask)
18-
print(mask)
1928
(largeur,hauteur)=img.size
2029
newImg = Image.new('RGB', (largeur,hauteur), color = (0,0,0))
2130
for i in range (largeur):
@@ -25,19 +34,7 @@ def filterWithMask(img, mask):
2534
newImg.show()
2635
saveImg(newImg)
2736

28-
29-
def filterWithHexadecimal(img, hexa):
30-
if not isHexa(hexa):
31-
print("Wrong hexadecimal format.")
32-
return isHexa(hexa)
33-
34-
if len(hexa)==7:
35-
hexa = hexa[1:]
36-
mask = list(map(lambda x : int(x, 16), [hexa[0:2],hexa[2:4], hexa[4:]]))
37-
filterWithMask(img, mask)
38-
3937
def filterBlackAndWhite(img):
40-
4138
(largeur,hauteur)=img.size
4239
newImg = Image.new('RGB', (largeur,hauteur), color = (0, 0, 0))
4340
for i in range (largeur):
@@ -46,8 +43,4 @@ def filterBlackAndWhite(img):
4643
couleur=int((p[0]+p[1]+p[2])/3)
4744
newImg.putpixel((i,j),(couleur,couleur,couleur))
4845
newImg.show()
49-
saveImg(newImg)
50-
51-
52-
53-
46+
saveImg(newImg)

projects/main.py

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,3 @@
1-
from PIL import Image
2-
from filters import *
3-
from movements import *
4-
import os
5-
import tkinter
6-
from tkinter import filedialog
1+
from MenuManager import MenuManager
72

8-
tkinter.Tk().withdraw()
9-
10-
filePath = filedialog.askopenfilename()
11-
monImage=Image.open(filePath)
12-
13-
#choix entre filtre ou rotation :
14-
15-
while True :
16-
print ("\nWhat do you want to do with your loaded image ? : \n")
17-
print (" -Apply a filter ? (f)")
18-
print (" -Apply a movement ? (r)")
19-
20-
choix=input()
21-
22-
while choix!="f" and choix!="F" and choix!="r" and choix!="R" and choix!="exit" :
23-
choix=input("\nDidn't understand, try again :")
24-
25-
#filtre :
26-
27-
if choix == "f" or choix == "F" :
28-
while True :
29-
print ("\nWhich filter do you want to use ? : ")
30-
print ("Available filters : \n")
31-
print (" -Green (1)")
32-
print (" -Negative (2)")
33-
print (" -Black and white (3)")
34-
choix=input()
35-
36-
while choix!="1" and choix!="2" and choix!="3" and choix!="exit" :
37-
choix=input("\nDidn't understand, try again :")
38-
39-
if choix == "1":
40-
filterWithMask(monImage, [0,1,0])
41-
42-
elif choix == "2":
43-
filtreNegative(monImage)
44-
45-
elif choix == "3":
46-
filterBlackAndWhite(monImage)
47-
elif choix == "exit":
48-
break
49-
#rotation :
50-
51-
elif choix == "R" or choix == "r" :
52-
while True :
53-
print ("Which movement do you want to use ? : ")
54-
print ("\nAvailable movements :")
55-
print ("\n -Vertical Mirror (m)")
56-
print ("\n -Rotate 180 degrees (d)")
57-
choix=input()
58-
59-
while choix!="m" and choix!="d" and choix!="M" and choix!="D" and choix!="exit":
60-
choix=input("\nJe n'ai pas compris, veuillez répéter :")
61-
62-
if choix == "m" or choix == "M" :
63-
verticalMirror(monImage)
64-
65-
elif choix == "d" or choix == "D" :
66-
rotateCustomAngle(monImage, 180)
67-
68-
elif choix =="exit":
69-
break
70-
elif choix =="exit":
71-
break
3+
MenuManager()

projects/movements.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
from PIL import Image
22
from utils import *
33

4-
def rotateCustomAngle(img, angle):
5-
img = img.rotate(angle)
6-
img.show()
7-
saveImg(img)
4+
def rotate(img):
5+
angle = input("How much angle ? : ")
6+
try:
7+
angle = int(angle)
8+
img = img.rotate(angle)
9+
img.show()
10+
saveImg(img)
11+
except:
12+
return
813

914
def verticalMirror(img):
1015
img = img.transpose(Image.FLIP_LEFT_RIGHT)

0 commit comments

Comments
 (0)