-
Notifications
You must be signed in to change notification settings - Fork 0
/
icomaker.py
70 lines (48 loc) · 1.97 KB
/
icomaker.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from PIL import Image
import sys
from PySide6.QtCore import QObject
from PySide6.QtWidgets import QApplication, QMainWindow, QFileDialog
from PySide6.QtWidgets import QPushButton, QLabel, QVBoxLayout, QHBoxLayout, QWidget
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("IcoMaker")
self.mylayout = QVBoxLayout()
self.line1 = QHBoxLayout()
self.mylayout.addLayout(self.line1)
self.lbl_img = QLabel("Selectionner l'image source")
self.line1.addWidget(self.lbl_img)
self.button_get_img = QPushButton("...")
self.button_get_img.clicked.connect(self.selectimg)
self.line1.addWidget(self.button_get_img)
self.line2 = QHBoxLayout()
self.mylayout.addLayout(self.line2)
self.button_create = QPushButton("Générer icone")
self.button_create.clicked.connect(self.createico)
self.mylayout.addWidget(self.button_create)
self.container = QWidget()
self.container.setLayout(self.mylayout)
self.setCentralWidget(self.container)
self.format = [(64, 64)]
self.path_n_file = ""
self.file_extension = []
def selectimg(self):
dialog = QFileDialog(self)
dialog.setNameFilter(QObject().tr("Images (*.png *.jpg)"))
if dialog.exec():
path = str(dialog.directory().path())
self.path_n_file = str(dialog.selectedFiles()[0])
file = self.path_n_file[len(path)+1:]
self.file_extension = file.split('.')
def createico(self):
img = Image.open(self.path_n_file)
dialog = QFileDialog(self)
dialog.setFileMode(QFileDialog.Directory)
if dialog.exec():
chemin = str(dialog.directory().path())
img.save(chemin+"/"+self.file_extension[0]+'_ico.ico', sizes=self.format)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()