refactor: introduces consts and optimizes the code

This commit is contained in:
Mr. Finch 2025-02-11 18:51:23 +00:00 committed by Mr Finchum
parent dc132bffc9
commit fcd7aa97b6
3 changed files with 34 additions and 40 deletions

View file

@ -1,7 +1,4 @@
from OptimaLab35 import gui, __version__
def main():
gui.main()
from .gui import main
if __name__ == "__main__":
main()

2
src/OptimaLab35/const.py Normal file
View file

@ -0,0 +1,2 @@
APPLICATION_NAME = "OptimaLab35"
CONFIG_BASE_PATH = "~/.config/OptimaLab35"

View file

@ -1,40 +1,41 @@
import sys
import os
from datetime import datetime
import importlib.resources as pkg_resources
try:
from OptimaLab35.ui import resources_rc
# keep the try for now
except Exception as e:
print(e)
from .ui import resources_rc
from PyPiUpdater import PyPiUpdater
from optima35.core import OptimaManager
from OptimaLab35.utils.utility import Utilities
from OptimaLab35.ui.main_window import Ui_MainWindow
from OptimaLab35.ui.preview_window import Ui_Preview_Window
from OptimaLab35.ui.settings_window import Ui_Settings_Window
from OptimaLab35.ui.exif_handler_window import ExifEditor
from OptimaLab35.ui.simple_dialog import SimpleDialog # Import the SimpleDialog class
from OptimaLab35 import __version__
from PySide6.QtCore import QRunnable, QThreadPool, Signal, QObject, QRegularExpression, Qt, QTimer, Slot, QDir
from .utils.utility import Utilities
from .ui.main_window import Ui_MainWindow
from .ui.preview_window import Ui_Preview_Window
from .ui.settings_window import Ui_Settings_Window
from .ui.exif_handler_window import ExifEditor
from .ui.simple_dialog import SimpleDialog # Import the SimpleDialog class
from OptimaLab35 import __version__
from .const import (
APPLICATION_NAME,
CONFIG_BASE_PATH
)
from PySide6 import QtWidgets, QtCore
from PySide6.QtCore import (
QRunnable,
QThreadPool,
Signal,
QObject,
QRegularExpression,
Qt,
QTimer,
Slot
)
from PySide6.QtWidgets import (
QMessageBox,
QApplication,
QMainWindow,
QWidget,
QVBoxLayout,
QLabel,
QLineEdit,
QPushButton,
QCheckBox,
QFileDialog,
QHBoxLayout,
QSpinBox,
#QProgressBar,
QFileDialog
)
from PySide6.QtGui import QPixmap, QRegularExpressionValidator, QIcon
@ -42,14 +43,14 @@ from PySide6.QtGui import QPixmap, QRegularExpressionValidator, QIcon
class OptimaLab35(QMainWindow, Ui_MainWindow):
def __init__(self):
super(OptimaLab35, self).__init__()
self.name = "OptimaLab35"
self.name = APPLICATION_NAME
self.version = __version__
self.o = OptimaManager()
self.u = Utilities(os.path.expanduser("~/.config/OptimaLab35"))
self.u = Utilities(os.path.expanduser(CONFIG_BASE_PATH))
self.app_settings = self.u.load_settings()
self.thread_pool = QThreadPool() # multi thread ChatGPT
# Initiate internal object
self.exif_file = os.path.expanduser("~/.config/OptimaLab35/exif.yaml")
self.exif_file = os.path.expanduser(f"{CONFIG_BASE_PATH}/exif.yaml")
self.available_exif_data = None
self.settings = {}
# UI elements
@ -62,13 +63,7 @@ class OptimaLab35(QMainWindow, Ui_MainWindow):
self.set_title()
self.default_ui_layout()
self.define_gui_interaction()
try:
self.setWindowIcon(QIcon(":app-icon.png"))
# keep the try for now
except Exception as e:
print(e)
self.setWindowIcon(QIcon(":app-icon.png"))
# Init function
def default_ui_layout(self):
@ -910,7 +905,7 @@ class ImageProcessorRunnable(QRunnable):
self.signals = WorkerSignals()
self.signals.progress.connect(progress_callback)
self.o = OptimaManager()
self.u = Utilities(os.path.expanduser("~/.config/OptimaLab35/"))
self.u = Utilities(os.path.expanduser(CONFIG_BASE_PATH))
def run(self):
input_folder = self.settings["input_folder"]
@ -980,7 +975,7 @@ class ImageProcessorWorker(QRunnable):
self.callback(None)
def main():
u = Utilities(os.path.expanduser("~/.config/OptimaLab35"))
u = Utilities(os.path.expanduser(CONFIG_BASE_PATH))
app_settings = u.load_settings()
app = QtWidgets.QApplication(sys.argv)