-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
51 lines (40 loc) · 1.49 KB
/
app.py
File metadata and controls
51 lines (40 loc) · 1.49 KB
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
import sys
from PySide6.QtWidgets import QApplication, QFileDialog, QMessageBox
from qt_material import apply_stylesheet
from lib import ImageCompressor, CompressionResult
from ui import MainWidget
class App(MainWidget):
def __init__(self) -> None:
super().__init__()
self._src_dir = None
self._dest_dir = None
def on_compress_btn_click(self) -> None:
obj = ImageCompressor(
self._src_dir, self._dest_dir,
self._check_optimize.isChecked(),
self._slider_quality.value()
)
result = obj.compress_images()
self.show_message(result)
def on_src_btn_click(self) -> None:
if (path := QFileDialog.getExistingDirectory()) is not None:
self._src_dir = path
self._te_source_dir.setText(path)
def on_dest_btn_click(self) -> None:
if (path := QFileDialog.getExistingDirectory()) is not None:
self._dest_dir = path
self._te_dest_dir.setText(path)
def show_message(self, result: CompressionResult) -> None:
QMessageBox(
QMessageBox.Icon.Information,
"Done",
f"{result.count} Image{'s' if result.count > 1 else ''} were compressed in {round(result.time, 2)}"
f" second{'s' if result.time > 1 else ''}",
parent=self
).exec()
if __name__ == '__main__':
q_app = QApplication()
apply_stylesheet(q_app, 'light_purple.xml')
app = App()
app.show()
sys.exit(q_app.exec())