0% found this document useful (0 votes)
10 views

Main.py

This document is a Python script that utilizes PyQt5 to create a GUI application with a splash screen and a main window. It includes functionality for refreshing data in a separate thread, handling user interactions through buttons, and performing cleanup checks before launching the application. The script sets up various components such as search editing and revision status management within the main window.

Uploaded by

HQHome
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Main.py

This document is a Python script that utilizes PyQt5 to create a GUI application with a splash screen and a main window. It includes functionality for refreshing data in a separate thread, handling user interactions through buttons, and performing cleanup checks before launching the application. The script sets up various components such as search editing and revision status management within the main window.

Uploaded by

HQHome
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import sys

from PyQt5 import QtWidgets, QtGui, QtCore


from PyQt5.QtCore import Qt, QTimer, QThread, pyqtSignal
from Edit import SearchEditing
from ui_mainwindow import Ui_MainWindow
from constants import *
from cleanup import check_date_and_cleanup
from button_functions import ButtonFunctions
from RevStatus import SearchRevStatus
from Refresh_Data import refresh_excel

class SplashScreen(QtWidgets.QSplashScreen):
def __init__(self, pixmap):
super().__init__(pixmap)
self.elapsed_time = 0 # Time in milliseconds
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_time)
self.timer.start(100) # Update every 100 milliseconds

def update_time(self):
self.elapsed_time += 100 # Increment by 100 milliseconds
self.show_message()

def show_message(self):
self.showMessage(f"<font color='black' style='background-color: rgba(169,
169, 169, 0.7);'>Loading... "
f"Time elapsed: {self.elapsed_time/1000 :.2f}
seconds</font>",
QtCore.Qt.AlignBottom | QtCore.Qt.AlignCenter,
QtCore.Qt.white
)

class RefreshThread(QThread):
finished = pyqtSignal()

def run(self):
refresh_excel() # Call the refresh function
self.finished.emit() # Emit signal when done

if __name__ == "__main__":
# Perform cleanup check first
if check_date_and_cleanup():
sys.exit(0)

# Enable high-DPI scaling


if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling,
True)
if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)

app = QtWidgets.QApplication(sys.argv)

# Create splash screen


splash = SplashScreen(QtGui.QPixmap(SPLASH_IMAGE_PATH))
splash.show()
app.processEvents() # Process events to show the splash screen immediately

# Start the refresh in a separate thread


refresh_thread = RefreshThread()
refresh_thread.finished.connect(lambda: splash.finish(MainWindow)) # Finish
splash when done
refresh_thread.start() # Start the thread

# Initialize main window


MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupui(MainWindow)

button_funcs = ButtonFunctions(main_window=MainWindow, ui=ui)


search_editing = SearchEditing(main_window=MainWindow, ui=ui)
search_rev_status = SearchRevStatus(main_window=MainWindow, ui=ui)

ui.CreateBtm.clicked.connect(button_funcs.save_to_WIRLog)
ui.SearchBtm2.clicked.connect(search_editing.Search_WIRLog)
ui.SaveBtm.clicked.connect(search_editing.Save_WIRLog)
ui.CancelBtm2.clicked.connect(search_editing.Cancel_SearchWIR)
ui.SearchBtm1.clicked.connect(search_rev_status.Search_WIRLog)
ui.RevisedBtm.clicked.connect(search_rev_status.create_revision)
ui.UpdateBtm.clicked.connect(search_rev_status.update_wir_status_and_comment)

# Set window flags


MainWindow.setWindowFlags(MainWindow.windowFlags() | Qt.WindowStaysOnTopHint)

# Show main window after refresh is done


refresh_thread.finished.connect(MainWindow.show) # Show main window when
refresh is done

sys.exit(app.exec_())

You might also like