diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..edd9d60 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +dist/ diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d1e22ec --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/comepress_pyinstaller.py b/comepress_pyinstaller.py deleted file mode 100644 index c0c3d8b..0000000 --- a/comepress_pyinstaller.py +++ /dev/null @@ -1,195 +0,0 @@ -import fnmatch -import glob -import os -import shutil -import sys -from os.path import isdir, join -from pathlib import Path - -from PIL import Image -from pynput.keyboard import Key, Listener -from PyQt5 import QtCore, QtGui, QtWidgets, uic -from PyQt5.QtGui import QCursor -from PyQt5.QtWidgets import * - -mode = "folder" # or "folder" -os.chdir(sys._MEIPASS) - -def restart_program(): - python = sys.executable - os.execl(python, python, * sys.argv) - - -def include_patterns(*patterns): - def _ignore_patterns(path, all_names): - # Determine names which match one or more patterns (that shouldn't be - # ignored). - keep = (name for pattern in patterns - for name in fnmatch.filter(all_names, pattern)) - # Ignore file names which *didn't* match any of the patterns given that - # aren't directory names. - dir_names = (name for name in all_names if isdir(join(path, name))) - return set(all_names) - set(keep) - set(dir_names) - - return _ignore_patterns - - -def ignore_list(path, files): - filesToIgnore = [] - for fileName in files: - fullFileName = os.path.join(os.path.normpath(path), fileName) - if (not os.path.isdir(fullFileName) - and not fileName.endswith('jpg') - and not fileName.endswith('jpeg') - and not fileName.endswith('png') - and not fileName.endswith('mp4')): - filesToIgnore.append(fileName) - return filesToIgnore - - -class MyGUI(QMainWindow): - def __init__(self): - super(MyGUI, self).__init__() - uic.loadUi("comepress.ui", self) - - # Remove Titlebar and background - self.setWindowFlags(QtCore.Qt.FramelessWindowHint) - self.setAttribute(QtCore.Qt.WA_TranslucentBackground) - self.setStyleSheet("""QToolTip { - border: none; - color: white; - }""") - # BUTTONS - self.pushButton.clicked.connect(self.browse) - - self.checkBox.clicked.connect(self.checked) - self.checkBox.setCursor(QCursor(QtCore.Qt.PointingHandCursor)) - - self.closeButton.clicked.connect(self.close) - self.closeButton.setToolTip("Close") - self.closeButton.setCursor(QCursor(QtCore.Qt.PointingHandCursor)) - - self.minimizeButton.clicked.connect(self.showMinimized) - self.minimizeButton.setToolTip("Minimize") - self.minimizeButton.setCursor(QCursor(QtCore.Qt.PointingHandCursor)) - - self.setAcceptDrops(True) - - # DEFAULT VARIABLES - self.backup = True - self.dragPos = QtCore.QPoint() - - self.show() - - def mousePressEvent(self, event): - self.dragPos = event.globalPos() - - def mouseMoveEvent(self, event): - if event.buttons() == QtCore.Qt.LeftButton: - self.move(self.pos() + event.globalPos() - self.dragPos) - self.dragPos = event.globalPos() - event.accept() - - def checked(self): - if self.checkBox.isChecked(): - self.backup = True - else: - self.backup = False - - def browse(self): - folder_path = QtWidgets.QFileDialog.getExistingDirectory( - self, "Select a Folder") - self.comepress_folder(folder_path) - alert_dialog = QMessageBox.information( - self, "All good!", "Successfully comepressed all files/folders") - - def dragEnterEvent(self, event): - if event.mimeData().hasUrls(): - event.accept() - else: - event.ignore() - - def dropEvent(self, event): - allowed_types = ["image/jpeg", "image/jpg", - "image/png", "inode/directory"] - dropped_files_folders = [] - db = QtCore.QMimeDatabase() - - for url in event.mimeData().urls(): - mimetype = db.mimeTypeForUrl(url) - if mimetype.name() in allowed_types: - dropped_files_folders.append( - tuple([url.toLocalFile(), mimetype.name()])) - - for file_folder_path in dropped_files_folders: - if file_folder_path[1] == "inode/directory": - self.comepress_folder(file_folder_path[0]) - - else: - self.comepress_file(file_folder_path[0]) - alert_dialog = QMessageBox.information( - self, "All good!", "Successfully comepressed all files/folders") - - def comepress_folder(self, folder_path): - # Get parent folder path - parent_folder = os.path.abspath( - os.path.join(folder_path, os.pardir)) - # Get folder name - folder_name = os.path.basename(folder_path) - # Destination backup - if os.path.isdir(folder_path + "_COMEPRESS"): - shutil.rmtree(folder_path + "_COMEPRESS") - backup_destination = os.path.abspath( - folder_path + "_COMEPRESS") - # Backup folder - print(f"backup: {self.backup}") - if self.backup == True: - shutil.copytree(folder_path, backup_destination, - ignore=include_patterns("*.png", "*.jpg", "*.jpeg")) - - # Loop through all the files in the folder - for root, dirs, files in os.walk(folder_path): - for file in files: - # If file is an image - if file.endswith(tuple([".jpg", ".jpeg", ".png"])): - # Convert to WebP - try: - img = Image.open(root + "/" + file) - except: - alert_dialog = QMessageBox.information( - self, "Error!", "Please check if " + root + "/" + file + " is not corrupt") - return - img = img.save(root + "/" + file.rsplit(".", 1) - [0] + ".webp", "webp") - # Remove original file - os.remove(root + "/" + file) - - def comepress_file(self, file_path): - # GET DETAILS - parent_folder = os.path.abspath( - os.path.join(file_path, os.pardir)) - file_name = os.path.basename(file_path) - destination_path = parent_folder + "/ORIGINAL_" + file_name - # BACKUP - if self.backup: - shutil.copyfile(file_path, destination_path) - # CONVERT - try: - img = Image.open(parent_folder + "/" + file_name) - except: - alert_dialog = QMessageBox.information( - self, "Error!", "Please check if " + parent_folder + "/" + file_name + " is not corrupt") - return - img = img.save(parent_folder + "/" + file_name.rsplit(".", 1) - [0] + ".webp", "webp") - os.remove(parent_folder + "/" + file_name) - - -def main(): - app = QApplication([]) - window = MyGUI() - app.exec() - - -if __name__ == "__main__": - main() diff --git a/loading.svg b/loading.svg deleted file mode 100644 index 17ec48f..0000000 --- a/loading.svg +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/logo.ico b/logo.ico deleted file mode 100644 index f7d178c..0000000 Binary files a/logo.ico and /dev/null differ diff --git a/main.py b/main.py index c50bddd..07d2d16 100644 --- a/main.py +++ b/main.py @@ -1,23 +1,22 @@ import fnmatch -import glob import os import shutil import sys from os.path import isdir, join -from pathlib import Path from PIL import Image -from pynput.keyboard import Key, Listener from PyQt5 import QtCore, QtGui, QtWidgets, uic from PyQt5.QtGui import QCursor from PyQt5.QtWidgets import * -mode = "folder" # or "folder" -#os.chdir(sys._MEIPASS) + +bundle_dir = getattr( + sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__))) + def restart_program(): python = sys.executable - os.execl(python, python, * sys.argv) + os.execl(python, python, *sys.argv) def include_patterns(*patterns): @@ -39,9 +38,9 @@ def ignore_list(path, files): for fileName in files: fullFileName = os.path.join(os.path.normpath(path), fileName) if (not os.path.isdir(fullFileName) - and not fileName.endswith('jpg') - and not fileName.endswith('jpeg') - and not fileName.endswith('png') + and not fileName.endswith('jpg') + and not fileName.endswith('jpeg') + and not fileName.endswith('png') and not fileName.endswith('mp4')): filesToIgnore.append(fileName) return filesToIgnore @@ -50,7 +49,8 @@ def ignore_list(path, files): class MyGUI(QMainWindow): def __init__(self): super(MyGUI, self).__init__() - uic.loadUi("comepress.ui", self) + uic.loadUi(os.path.abspath( + os.path.join(bundle_dir, "res/comepress.ui")), self) # Remove Titlebar and background self.setWindowFlags(QtCore.Qt.FramelessWindowHint) @@ -59,6 +59,7 @@ def __init__(self): border: none; color: white; }""") + self.setWindowIcon(QtGui.QIcon("res/inbox_tray_3d.ico")) # BUTTONS self.pushButton.clicked.connect(self.browse) @@ -99,6 +100,8 @@ def checked(self): def browse(self): folder_path = QtWidgets.QFileDialog.getExistingDirectory( self, "Select a Folder") + if folder_path == '': + return self.comepress_folder(folder_path) alert_dialog = QMessageBox.information( self, "All good!", "Successfully comepressed all files/folders") @@ -143,7 +146,7 @@ def comepress_folder(self, folder_path): folder_path + "_COMEPRESS") # Backup folder print(f"backup: {self.backup}") - if self.backup == True: + if self.backup: shutil.copytree(folder_path, backup_destination, ignore=include_patterns("*.png", "*.jpg", "*.jpeg")) @@ -155,14 +158,14 @@ def comepress_folder(self, folder_path): # Convert to WebP try: img = Image.open(root + "/" + file) + img.save(root + "/" + file.rsplit(".", 1) + [0] + ".webp", "webp") + # Remove original file + os.remove(root + "/" + file) except: alert_dialog = QMessageBox.information( self, "Error!", "Please check if " + root + "/" + file + " is not corrupt") return - img = img.save(root + "/" + file.rsplit(".", 1) - [0] + ".webp", "webp") - # Remove original file - os.remove(root + "/" + file) def comepress_file(self, file_path): # GET DETAILS @@ -176,17 +179,18 @@ def comepress_file(self, file_path): # CONVERT try: img = Image.open(parent_folder + "/" + file_name) + img.save(parent_folder + "/" + + file_name.rsplit(".", 1)[0] + ".webp", "webp") + os.remove(parent_folder + "/" + file_name) except: alert_dialog = QMessageBox.information( self, "Error!", "Please check if " + parent_folder + "/" + file_name + " is not corrupt") return - img = img.save(parent_folder + "/" + file_name.rsplit(".", 1) - [0] + ".webp", "webp") - os.remove(parent_folder + "/" + file_name) def main(): app = QApplication([]) + app.setWindowIcon(QtGui.QIcon("res/inbox_tray_3d.ico")) window = MyGUI() app.exec() diff --git a/main.spec b/main.spec index 996561f..b991f83 100644 --- a/main.spec +++ b/main.spec @@ -5,10 +5,10 @@ block_cipher = None a = Analysis( - ['comepress_pyinstaller.py'], + ['main.py'], pathex=[], binaries=[], - datas=[("comepress.ui", "."), ("unchecked.svg", "."), ("logo.png", "."), ("loading.svg", "."), ("folder.png", "."), ("checked.svg", "."), ("logo.ico", ".")], + datas=[('./res/*', 'res')], hiddenimports=[], hookspath=[], hooksconfig={}, @@ -28,18 +28,18 @@ exe = EXE( a.zipfiles, a.datas, [], - name='comepress', + name='main', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, - console=True, + console=False, disable_windowed_traceback=False, argv_emulation=False, target_arch=None, codesign_identity=None, entitlements_file=None, - icon='logo.ico', + icon='res/inbox_tray_3d.ico', ) diff --git a/checked.svg b/res/checked.svg similarity index 100% rename from checked.svg rename to res/checked.svg diff --git a/comepress.ui b/res/comepress.ui similarity index 95% rename from comepress.ui rename to res/comepress.ui index 225f68e..8334101 100644 --- a/comepress.ui +++ b/res/comepress.ui @@ -1,6 +1,6 @@ - MainWindow + Comepress @@ -70,7 +70,7 @@ border: 2px solid #323134; - border-image: url(folder.png) 0 0 0 0 stretch stretch; + border-image: url(res/folder.png) 0 0 0 0 stretch stretch; false @@ -164,7 +164,7 @@ color: #ecedec; 1 - <html><head/><body><p align="center">Copyright © 2022 <span style=" font-weight:600;">ComePress</span> <br/> Made by <span style=" font-weight:600;">Nayam Amarshe</span> with ⌨ and 🖱</p></body></html> + <html><head/><body><p align="center">Copyright © 2022 <span style=" font-weight:600;">Comepress</span> <br/> Made by <span style=" font-weight:600;">Nayam Amarshe</span> with ⌨ and 🖱</p></body></html> @@ -195,11 +195,11 @@ QCheckBox::indicator { } QCheckBox::indicator:checked { - image: url("checked.svg") + image: url("res/checked.svg") } QCheckBox::indicator:unchecked { - image: url("unchecked.svg") + image: url("res/unchecked.svg") } @@ -229,7 +229,7 @@ QCheckBox::indicator:unchecked { border: none; border-radius: none; background: none; -border-image: url(logo.png); +border-image: url(res/logo.png); diff --git a/folder.png b/res/folder.png similarity index 100% rename from folder.png rename to res/folder.png diff --git a/res/inbox_tray_3d.ico b/res/inbox_tray_3d.ico new file mode 100644 index 0000000..4072995 Binary files /dev/null and b/res/inbox_tray_3d.ico differ diff --git a/logo.png b/res/logo.png similarity index 100% rename from logo.png rename to res/logo.png diff --git a/unchecked.svg b/res/unchecked.svg similarity index 100% rename from unchecked.svg rename to res/unchecked.svg