This repository has been archived by the owner on Apr 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
200 lines (144 loc) · 6.4 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# coding: utf-8
""" This is the main file to launch the Image-Viewer. """
import sys
import webbrowser
from tkinter import Tk, Menu, Toplevel, messagebox, Canvas, Label, Entry, Button
from loguru import logger
from PIL import Image, ImageTk
logger.add('DEBUG.log', format='{time} {level} {message}',
level='DEBUG', rotation='10 KB', compression='zip')
@logger.catch
def show_license():
""" This function shows the license of the project. """
logger.info('Function show_license was initialized.')
messagebox.showinfo('License', """
MIT License
Copyright (c) 2020 RIDERIUS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
""")
logger.info('Function show_license was closed.')
@logger.catch
def opening_github():
""" This function opens the github of the project. """
logger.info('Function opening_github was initialized.')
webbrowser.open('https://github.com/RIDERIUS/Image-Viewer')
logger.info('Function opening_github was closed.')
@logger.catch
def show_version():
""" This function shows the version of the project. """
logger.info('Function show_version was initialized.')
messagebox.showinfo('Version', 'Version 0.5.0')
logger.info('Function show_version was closed.')
@logger.catch
def crop_image():
""" This function is needed to crop images. """
@logger.catch
def cropping():
"""This function will crop images."""
root.geometry(
f"{x_entry_cropping_window.get()}x{y_entry_cropping_window.get()}")
logger.info(
f"""
x_entry_cropping_window - {x_entry_cropping_window.get()}
y_entry_cropping_window - {y_entry_cropping_window.get()}""")
logger.info('cropping was successful')
root.mainloop()
logger.info('Function crop_image and cropping was closed.')
cropping_window = Tk()
cropping_window.geometry('404x65')
cropping_window.title('Crop Image')
cropping_window.resizable(False, False)
x_label_cropping_window = Label(cropping_window, text='Width Image')
x_label_cropping_window.grid(column=0, row=0)
y_label_cropping_window = Label(cropping_window, text='Height Image')
y_label_cropping_window.grid(column=2, row=0)
x_entry_cropping_window = Entry(cropping_window,)
x_entry_cropping_window.grid(column=1, row=0)
y_entry_cropping_window = Entry(cropping_window)
y_entry_cropping_window.grid(column=3, row=0)
button_cropping_window = Button(
cropping_window, text='Submit', command=cropping)
button_cropping_window.grid(column=2, row=1)
logger.info('Function crop_image was initialized.')
cropping_window.mainloop()
@logger.catch
def resize_image():
""" This function is needed to resizing images. """
@logger.catch
def resizing():
"""This function will resize images."""
global root
logger.info('Function resize_image and resizing was closed.')
logger.info(
f"""
x_entry_resizing_window - {x_entry_resizing_window.get()}
y_entry_resizing_window - {y_entry_resizing_window.get()}""")
resize = int(x_entry_resizing_window.get()), int(
y_entry_resizing_window.get())
resized_img = image_pil.resize(resize)
resized_img.save('resized_image.png')
reimage_pil = Image.open('resized_image.png')
(width, height) = reimage_pil.size
reimage = ImageTk.PhotoImage(reimage_pil)
root.destroy()
root = Toplevel()
root.geometry(f'{width}x{height}')
main(width, height, reimage)
resizing_window = Tk()
resizing_window.geometry('404x65')
resizing_window.title('Resize Image')
resizing_window.resizable(False, False)
x_label_resizing_window = Label(resizing_window, text='Width Image')
x_label_resizing_window.grid(column=0, row=0)
y_label_resizing_window = Label(resizing_window, text='Height Image')
y_label_resizing_window.grid(column=2, row=0)
x_entry_resizing_window = Entry(resizing_window,)
x_entry_resizing_window.grid(column=1, row=0)
y_entry_resizing_window = Entry(resizing_window)
y_entry_resizing_window.grid(column=3, row=0)
button_resizing_window = Button(
resizing_window, text='Submit', command=resizing)
button_resizing_window.grid(column=2, row=1)
logger.info('Function resize_image was initialized.')
resizing_window.mainloop()
@logger.catch
def main(width, height, image):
root.title('Image-Viewer')
root.resizable(False, False)
menu = Menu(root)
root.config(menu=menu)
about_menu = Menu(menu)
edit_image_menu = Menu(menu)
about_menu.add_command(label='License', command=show_license)
about_menu.add_command(label='Github', command=opening_github)
about_menu.add_command(label='Version', command=show_version)
edit_image_menu.add_command(label='Crop Image', command=crop_image)
edit_image_menu.add_command(label='Resize Image', command=resize_image)
menu.add_cascade(label='About', menu=about_menu)
menu.add_cascade(label='Edit Image', menu=edit_image_menu)
canvas = Canvas(root, width=width, height=height)
canvas.create_image(width / 2, height / 2, image=image)
canvas.pack()
logger.info('Root window was initialized.')
root.mainloop()
FILE_PATH = str(sys.argv[1])
image_pil = Image.open(FILE_PATH)
(width, height) = image_pil.size
root = Toplevel()
root.geometry(f'{width}x{height}')
main_image = ImageTk.PhotoImage(image_pil)
main(width, height, main_image)