import sys import sqlite3 import os from PyQt5.QtWidgets import ( QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout, QMessageBox, QStackedWidget, QTableWidget, QHeaderView, QTableWidgetItem, QTextEdit, QAbstractScrollArea, QScrollArea, QSizePolicy,QFormLayout ) from PyQt5.QtGui import QFont, QColor, QPalette, QPixmap, QBrush from PyQt5.QtCore import Qt from PyQt5.QtCore import QEvent from db_setup import init_db, get_connection # Initialize DB once (creates tables if missing) init_db() # Global references global_stacked_widget = None global_main_screen = None keyboard_window = None def insert_text(widget, text): if isinstance(widget, (QLineEdit, QTextEdit)): widget.insert(text) def backspace_text(widget): if isinstance(widget, QLineEdit): current_text = widget.text() widget.setText(current_text[:-1]) elif isinstance(widget, QTextEdit): cursor = widget.textCursor() cursor.deletePreviousChar() widget.setTextCursor(cursor) def clear_text(widget): if isinstance(widget, QLineEdit): widget.clear() elif isinstance(widget, QTextEdit): widget.clear() def show_keyboard(): global keyboard_window # Close any existing keyboard window if keyboard_window is not None: keyboard_window.close() keyboard_window = QWidget() keyboard_window.setWindowTitle("Numeric Keyboard") keyboard_window.setFixedSize(270, 360) layout = QVBoxLayout() # Button layout buttons = [ ["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["0"], ["Back", "Clear"] ] for row in buttons: row_layout = QHBoxLayout() for key in row: btn = QPushButton(key) btn.setFixedSize(80, 60) btn.setFont(QFont("Arial", 14)) # Connect button actions if key == "Back": btn.clicked.connect(lambda _, w=QApplication.focusWidget(): backspace_text(w)) elif key == "Clear": btn.clicked.connect(lambda _, w=QApplication.focusWidget(): clear_text(w)) else: btn.clicked.connect(lambda _, k=key, w=QApplication.focusWidget(): insert_text(w, k)) row_layout.addWidget(btn) layout.addLayout(row_layout) keyboard_window.setLayout(layout) keyboard_window.setWindowModality(Qt.NonModal) keyboard_window.setWindowFlag(Qt.WindowStaysOnTopHint) keyboard_window.show() # Navigation functions def go_home(): if global_stacked_widget and global_stacked_widget.currentIndex() != 1: global_stacked_widget.setCurrentIndex(1) def refresh_screen(): if global_stacked_widget: current_index = global_stacked_widget.currentIndex() current_widget = global_stacked_widget.currentWidget() current_class = type(current_widget) new_widget = current_class() # Recreate the same screen global_stacked_widget.removeWidget(current_widget) global_stacked_widget.insertWidget(current_index, new_widget) global_stacked_widget.setCurrentIndex(current_index) # Optional: delete the old widget to free memory current_widget.deleteLater() def go_login(): if global_stacked_widget: global_stacked_widget.setCurrentIndex(0) def open_operator_identity(): global global_stacked_widget operator_screen = OperatorIdentityScreen() global_stacked_widget.addWidget(operator_screen) global_stacked_widget.setCurrentWidget(operator_screen) def open_checklist_screen(self): global global_stacked_widget checklist_screen = ChecklistScreen() global_stacked_widget.addWidget(checklist_screen) global_stacked_widget.setCurrentWidget(checklist_screen) def go_first_off(): global global_stacked_widget first_off_screen = FirstOff() global_stacked_widget.addWidget(first_off_screen) global_stacked_widget.setCurrentWidget(first_off_screen) def go_final_validation(): global global_stacked_widget final_validation_screen = FinalValidation() global_stacked_widget.addWidget(final_validation_screen) global_stacked_widget.setCurrentWidget(final_validation_screen) # ---------------- Login Screen ---------------- # class LoginScreen(QWidget): def __init__(self, stacked_widget): super().__init__() self.stacked_widget = stacked_widget self.init_ui() def init_ui(self): self.setWindowTitle("Login Screen") palette = QPalette() palette.setColor(QPalette.Window, QColor("#E6F7FF")) self.setAutoFillBackground(True) self.setPalette(palette) title = QLabel("WELCOME TO CRI PUMPS") title.setFont(QFont("Times New Roman", 28, QFont.Bold)) title.setStyleSheet("color: darkblue;") title.setAlignment(Qt.AlignCenter) logo = QLabel() logo.setAlignment(Qt.AlignCenter) logo_path = "/home/cri/myproject/venv/cri_logo_red.png" if os.path.exists(logo_path): pixmap = QPixmap(logo_path) if not pixmap.isNull(): logo.setPixmap(pixmap.scaledToWidth(150, Qt.SmoothTransformation)) else: logo.setText("Failed to load image.") else: logo.setText("Logo not found.") self.username_label = QLabel("Username:") self.username_label.setFont(QFont("Times New Roman", 14, QFont.Bold)) self.username_edit = QLineEdit() self.username_edit.setFont(QFont("Times New Roman", 12)) self.username_edit.setFixedHeight(40) self.username_edit.setFixedWidth(300) self.username_edit.setPlaceholderText("Enter username") self.username_edit.returnPressed.connect(self.focus_password) user_row = QHBoxLayout() user_row.addStretch() user_row.addWidget(self.username_label) user_row.addWidget(self.username_edit) user_row.addStretch() self.password_label = QLabel("Password:") self.password_label.setFont(QFont("Times New Roman", 14, QFont.Bold)) self.password_edit = QLineEdit() self.password_edit.setFont(QFont("Times New Roman", 12)) self.password_edit.setFixedHeight(40) self.password_edit.setFixedWidth(300) self.password_edit.setEchoMode(QLineEdit.Password) self.password_edit.setPlaceholderText("Enter password") self.password_edit.returnPressed.connect(self.login) self.toggle_button = QPushButton("👁") self.toggle_button.setFixedWidth(40) self.toggle_button.setCheckable(True) self.toggle_button.toggled.connect(self.toggle_password) pass_row = QHBoxLayout() pass_row.addStretch() pass_row.addWidget(self.password_label) pass_layout = QHBoxLayout() pass_layout.addWidget(self.password_edit) pass_layout.addWidget(self.toggle_button) pass_row.addLayout(pass_layout) pass_row.addStretch() self.login_button = QPushButton("LOGIN") self.login_button.setFont(QFont("Times New Roman", 12, QFont.Bold)) self.login_button.setFixedWidth(200) self.login_button.setStyleSheet(""" QPushButton { background-color: darkblue; color: white; padding: 10px; border-radius: 6px; } """) self.login_button.clicked.connect(self.login) login_btn_row = QHBoxLayout() login_btn_row.addStretch() login_btn_row.addWidget(self.login_button) login_btn_row.addStretch() # Second logo below login button footer_logo = QLabel() footer_logo.setAlignment(Qt.AlignCenter) footer_logo_path = "/home/cri/myproject/venv/cri_farm_banner.jpg" if os.path.exists(footer_logo_path): pixmap2 = QPixmap(footer_logo_path) if not pixmap2.isNull(): footer_logo.setPixmap(pixmap2.scaledToWidth(500, Qt.SmoothTransformation)) else: footer_logo.setText("Failed to load image.") else: footer_logo.setText("Footer logo not found.") # Main layout layout = QVBoxLayout() layout.addSpacing(50) layout.addWidget(title) layout.addSpacing(30) layout.addWidget(logo) # Top logo layout.addSpacing(40) layout.addLayout(user_row) layout.addSpacing(20) layout.addLayout(pass_row) layout.addSpacing(40) layout.addLayout(login_btn_row) layout.addSpacing(30) layout.addWidget(footer_logo) # New footer logo layout.addStretch() self.setLayout(layout) def toggle_password(self, checked): self.password_edit.setEchoMode(QLineEdit.Normal if checked else QLineEdit.Password) def focus_password(self): self.password_edit.setFocus() def login(self): username = self.username_edit.text() password = self.password_edit.text() if not username or not password: QMessageBox.warning(self, "Error", "Enter both username and password.") return # ✅ Use the same connection from db_setup.py conn = get_connection() cursor = conn.cursor() cursor.execute( "SELECT * FROM user_details WHERE user_name=? AND user_pass=?", (username, password) ) result = cursor.fetchone() conn.close() if result: self.stacked_widget.setCurrentIndex(1) else: QMessageBox.warning(self, "Error", "Invalid credentials.") # ---------------- Main Screen ---------------- # class MainScreen(QWidget): def __init__(self): super().__init__() self.setWindowTitle("Production Display") self.showFullScreen() # Set entire background to light blue palette = self.palette() palette.setColor(QPalette.Window, QColor("#ADD8E6")) self.setAutoFillBackground(True) self.setPalette(palette) # Initialize widgets self.table = QTableWidget(5, 3) # Example table self.operator_identity_btn = QPushButton("Operator Identity") self.btn_serial_print = QPushButton("Serial Print") self.btn_part_validation = QPushButton("Part Validation") self.btn_checklist = QPushButton("Checklist") self.btn_couth_marking = QPushButton("Couth Marking") self.prod_order_input = QLineEdit() self.serial_input = QLineEdit() self.init_ui() # Helper for focusing next input def make_focus_function(self, index): def focus_next(): if index < len(self.input_fields): self.input_fields[index].setFocus() return focus_next def init_ui(self): palette = self.palette() palette.setColor(QPalette.Window, QColor("#E6F7FF")) self.setPalette(palette) # Title label self.title_label = QLabel("WORK ORDER VALIDATION") self.title_label.setFont(QFont("Times New Roman", 20, QFont.Bold)) self.title_label.setStyleSheet("color: white;") self.title_label.setAlignment(Qt.AlignCenter) # Logo logo_label = QLabel() pixmap = QPixmap("/home/cri/myproject/cri_logo_red.png") pixmap = pixmap.scaled(60, 60, Qt.KeepAspectRatio, Qt.SmoothTransformation) logo_label.setPixmap(pixmap) logo_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) # Title layout (logo + title text) title_layout = QHBoxLayout() title_layout.setContentsMargins(10, 5, 10, 5) title_layout.addWidget(logo_label) title_layout.addSpacing(20) title_layout.addWidget(self.title_label, stretch=1) title_layout.addStretch() # Header container with background color header_widget = QWidget() header_widget.setLayout(title_layout) header_widget.setStyleSheet("background-color: #003366;") # Dark blue background # Disable widgets that should start inactive self.table.setDisabled(True) self.operator_identity_btn.setDisabled(True) self.other_buttons = [ self.btn_serial_print, self.btn_part_validation, self.btn_checklist, self.btn_couth_marking ] for btn in self.other_buttons: btn.setDisabled(True) self.prod_order_input.setEnabled(True) self.serial_input.setEnabled(True) self.prod_order_input.editingFinished.connect(lambda: print("Work order details fetch")) self.serial_input.editingFinished.connect(lambda: print("Serial details fetch")) # Input Fields label_names = [ "Production Order Number", "Item Description", "Current Serial Number", "Operator Number", "Completed Quantity", "Sub Assembly Serial Number", "Sub Assembly Item Description", "Previous Serial Number", "Total Quantity", "Remaining Quantity" ] font_label = QFont("Times New Roman", 14, QFont.Bold) font_input = QFont("Times New Roman", 12) #field_width, field_height = 350, 50 self.input_fields = [] left_layout, right_layout = QVBoxLayout(), QVBoxLayout() for i, name in enumerate(label_names): sub_layout = left_layout if i < 5 else right_layout field_box = QVBoxLayout() label = QLabel(name) label.setFont(font_label) input_box = QLineEdit() input_box.setFont(font_input) input_box.setMinimumHeight(45) input_box.setStyleSheet(""" QLineEdit { background-color: #ADD8E6; padding: 6px; border-radius: 6px; } """) # ✅ Auto expand horizontally with screen input_box.setSizePolicy(QPushButton().sizePolicy().Expanding, QPushButton().sizePolicy().Fixed) if i == 0: toggle_button = QPushButton("Serial OFF") toggle_button.setCheckable(True) toggle_button.setFont(QFont("Times New Roman", 10, QFont.Bold)) toggle_button.setStyleSheet(""" QPushButton { background-color: #00008B; color: white; padding: 6px; border-radius: 6px; } QPushButton:checked { background-color: #FF6347; color: white; } """) toggle_button.clicked.connect(self.handle_serial_toggle) self.serial_toggle_button = toggle_button toggle_layout = QHBoxLayout() toggle_layout.addWidget(input_box, stretch=3) toggle_layout.addWidget(toggle_button, stretch=1) field_box.addWidget(label) field_box.addLayout(toggle_layout) else: if i < 9: input_box.returnPressed.connect(self.make_focus_function(i + 1)) field_box.addWidget(label) field_box.addWidget(input_box) sub_layout.addLayout(field_box) # ✅ Add spacing between each field block sub_layout.addSpacing(15) self.input_fields.append(input_box) input_layout = QHBoxLayout() input_layout.addStretch() input_layout.addLayout(left_layout, stretch=1) input_layout.addSpacing(60) input_layout.addLayout(right_layout, stretch=1) input_layout.addStretch() # Right navigation buttons right_buttons = QVBoxLayout() button_actions = { "Operator Mapping": open_operator_identity, "Product Check List": open_checklist_screen, "Process Check List": go_first_off, "Part Validation": go_final_validation } for name, handler in button_actions.items(): btn = QPushButton(name) btn.setFont(QFont("Times New Roman", 11, QFont.Bold)) btn.setFixedSize(180, 45) btn.setStyleSheet(""" QPushButton { background-color: #00008B; color: white; padding: 6px; border-radius: 6px; } QPushButton:hover { background-color: #0000CD; } QPushButton:pressed { background-color: #000066; } """) btn.clicked.connect(handler) right_buttons.addWidget(btn) right_buttons.addSpacing(15) right_buttons.addStretch() # ✅ Extra OK / NOT OK buttons below right buttons ok_btn = QPushButton("OK") ok_btn.setStyleSheet(""" QPushButton { background-color: darkgreen; color: white; border-radius: 8px; padding: 5px 10px; } QPushButton:pressed { background-color: green; } """) ok_btn.setFont(QFont("Times New Roman", 9)) ok_btn.setFixedWidth(100) not_ok_btn = QPushButton("NOT OK") not_ok_btn.setStyleSheet(""" QPushButton { background-color: darkred; color: white; border-radius: 8px; padding: 5px 10px; } QPushButton:pressed { background-color: red; } """) not_ok_btn.setFont(QFont("Times New Roman", 9)) not_ok_btn.setFixedWidth(100) # Place them in a horizontal layout ok_notok_row = QHBoxLayout() ok_notok_row.addStretch() ok_notok_row.addWidget(ok_btn) ok_notok_row.addSpacing(10) ok_notok_row.addWidget(not_ok_btn) ok_notok_row.addStretch() # Add to right side buttons layout right_buttons.addSpacing(20) right_buttons.addLayout(ok_notok_row) # Bottom navigation bottom_buttons = QHBoxLayout() btn_data = [ ("REFRESH", refresh_screen), ("LOGIN", go_login) ] for txt, handler in btn_data: btn = QPushButton(txt) btn.setFont(QFont("Times New Roman", 11, QFont.Bold)) btn.setFixedSize(150, 45) btn.setStyleSheet(""" QPushButton { background-color: #00008B; color: white; font-weight: bold; border-radius: 6px; } QPushButton:pressed { background-color: #000066; } """) btn.clicked.connect(handler) bottom_buttons.addStretch() bottom_buttons.addWidget(btn) bottom_buttons.addStretch() # Final layout content = QHBoxLayout() content.addLayout(input_layout, stretch=3) content.addLayout(right_buttons, stretch=1) main_layout = QVBoxLayout() main_layout.addWidget(header_widget) main_layout.addSpacing(30) main_layout.addLayout(content) main_layout.addStretch() main_layout.addLayout(bottom_buttons) self.setLayout(main_layout) def handle_serial_toggle(self): if self.serial_toggle_button.isChecked(): self.serial_toggle_button.setText("Serial ON") self.title_label.setText("SERIAL NUMBER VALIDATION") else: self.serial_toggle_button.setText("Serial OFF") self.title_label.setText("WORK ORDER VALIDATION") # ------------------------------ Operator Identity Screen ------------------# class OperatorIdentityScreen(QWidget): def __init__(self): super().__init__() self.setWindowTitle("Operator Identity") self.showFullScreen() self.inputs = [] # Set entire background to light blue palette = self.palette() palette.setColor(QPalette.Window, QColor("#ADD8E6")) # Light Blue self.setAutoFillBackground(True) self.setPalette(palette) self.init_ui() def init_ui(self): palette = self.palette() palette.setColor(QPalette.Window, QColor("#E6F7FF")) self.setPalette(palette) # Header: Logo + Title logo_label = QLabel() pixmap = QPixmap("/home/cri/myproject/cri_logo_red.png") pixmap = pixmap.scaled(60, 60, Qt.KeepAspectRatio, Qt.SmoothTransformation) logo_label.setPixmap(pixmap) logo_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) title_label = QLabel("OPERATOR IDENTITY") title_label.setFont(QFont("Times New Roman", 20, QFont.Bold)) title_label.setStyleSheet("color: white;") title_label.setAlignment(Qt.AlignCenter) # ✅ Centered title header_layout = QHBoxLayout() header_layout.setContentsMargins(10, 10, 10, 10) header_layout.addWidget(logo_label) header_layout.addStretch() header_layout.addWidget(title_label) header_layout.addStretch() header_widget = QWidget() header_widget.setLayout(header_layout) header_widget.setStyleSheet("background-color: #003366;") # Dark Blue background # Input Fields left_layout = QVBoxLayout() right_layout = QVBoxLayout() for i in range(10): label = QLabel(f"Operator ID {i + 1}") label.setFont(QFont("Times New Roman", 12, QFont.Bold)) label.setStyleSheet("color: black;") line_edit = QLineEdit() line_edit.setFont(QFont("Times New Roman", 11)) line_edit.setFixedHeight(50) line_edit.setFixedWidth(800) line_edit.setStyleSheet("background-color: #ADD8E6;") line_edit.textChanged.connect(self.check_fields) if i < 9: line_edit.returnPressed.connect(self.make_focus_function(i + 1)) self.inputs.append(line_edit) clear_btn = QPushButton("CLEAR") clear_btn.setFixedSize(70, 25) clear_btn.setStyleSheet(""" QPushButton { background-color: red; color: white; border: 1px solid black; } QPushButton:pressed { background-color: darkred; } """) clear_btn.setAutoFillBackground(True) clear_btn.clicked.connect(line_edit.clear) entry_layout = QVBoxLayout() entry_layout.addWidget(label) entry_layout.addWidget(line_edit) entry_layout.addWidget(clear_btn) # Add space below each operator entry entry_layout.addSpacing(20) # 👈 Equal space between entries if i < 5: left_layout.addLayout(entry_layout) else: right_layout.addLayout(entry_layout) input_area = QHBoxLayout() input_area.addLayout(left_layout) input_area.addSpacing(40) input_area.addLayout(right_layout) # Submit Button self.submit_btn = QPushButton("SUBMIT") self.submit_btn.setFont(QFont("Times New Roman", 10, QFont.Bold)) self.submit_btn.setStyleSheet(""" QPushButton { background-color: #008000; /* Dark green hex code */ color: white; border: 1px solid black; font-weight: bold; padding: 8px; } QPushButton:pressed { background-color: #006400; /* Darker green on press */ } """) self.submit_btn.setAutoFillBackground(True) self.submit_btn.setEnabled(False) self.submit_btn.clicked.connect(self.submit_operator_ids) # Bottom Navigation Buttons bottom_buttons = QHBoxLayout() button_data = [ ("HOME", "lightblue", go_home), ("REFRESH", "lightblue", refresh_screen) ] for text, color, handler in button_data: btn = QPushButton(text) btn.setFont(QFont("Times New Roman", 12, QFont.Bold)) btn.setFixedSize(150, 50) btn.setStyleSheet(""" QPushButton { background-color: #00008B; /* Dark Blue hex code */ color: white; border: 1px solid black; font-weight: bold; } QPushButton:pressed { background-color: #000066; /* Darker blue on press */ } """) btn.setAutoFillBackground(True) btn.clicked.connect(handler) bottom_buttons.addWidget(btn) self.submit_btn.setFixedSize(150, 50) bottom_buttons.addWidget(self.submit_btn) layout = QVBoxLayout() layout.addWidget(header_widget) layout.addSpacing(20) layout.addLayout(input_area) layout.addStretch() layout.addSpacing(20) layout.addLayout(bottom_buttons) self.setLayout(layout) def make_focus_function(self, index): def focus_next(): if index < len(self.inputs): self.inputs[index].setFocus() return focus_next def check_fields(self): """Enable submit button if any field has text""" self.submit_btn.setEnabled(any(inp.text().strip() for inp in self.inputs)) def submit_operator_ids(self): operator_ids = [inp.text().strip() if inp.text().strip() else None for inp in self.inputs] if not any(operator_ids): QMessageBox.warning(self, "Input Error", "Please fill at least one Operator ID before submitting.") return try: conn = sqlite3.connect("sfg printing.db") cursor = conn.cursor() cursor.execute(''' INSERT INTO operator_details ( operator1_id, operator2_id, operator3_id, operator4_id, operator5_id, operator6_id, operator7_id, operator8_id, operator9_id, operator10_id ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ''', operator_ids) conn.commit() conn.close() QMessageBox.information(self, "Success", "Operator IDs saved successfully.") for inp in self.inputs: inp.clear() self.submit_btn.setEnabled(False) except Exception as e: QMessageBox.critical(self, "Database Error", f"Failed to insert data:\n{e}") # -----------------------------------Check List Screen---------------------------# class ChecklistScreen(QWidget): def __init__(self): super().__init__() self.setWindowTitle("Checklist Screen") self.resize(1000, 700) # Set background palette = self.palette() palette.setColor(QPalette.Window, QColor("#ADD8E6")) self.setAutoFillBackground(True) self.setPalette(palette) layout = QVBoxLayout(self) # ---------------- Header ---------------- header_widget = QWidget() header_widget.setStyleSheet("background-color: #003366;") header_layout = QHBoxLayout(header_widget) header_layout.setContentsMargins(10, 10, 10, 10) logo_label = QLabel() pixmap = QPixmap("/home/cri/myproject/cri_logo_red.png") pixmap = pixmap.scaled(60, 60, Qt.KeepAspectRatio, Qt.SmoothTransformation) logo_label.setPixmap(pixmap) logo_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) title_label = QLabel("PRODUCT CHECK LIST") title_label.setFont(QFont("Times New Roman", 24, QFont.Bold)) title_label.setStyleSheet("color: white;") title_label.setAlignment(Qt.AlignCenter) header_layout.addWidget(logo_label) header_layout.addSpacing(20) header_layout.addWidget(title_label, stretch=1) header_layout.addStretch() layout.addWidget(header_widget) # ---------------- Inputs ---------------- input_layout = QHBoxLayout() self.work_order = self.create_labeled_input("Workorder Number") self.serial_number = self.create_labeled_input("Serial Number") self.operator_plant = self.create_labeled_input("Operator Number") input_layout.addLayout(self.work_order['layout']) input_layout.addLayout(self.serial_number['layout']) input_layout.addLayout(self.operator_plant['layout']) layout.addLayout(input_layout) # ---------------- Table ---------------- self.table = QTableWidget(1, 3) self.table.setHorizontalHeaderLabels(["Dimension Name", "Dimension Value", "Entered Value"]) self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.table.verticalHeader().setVisible(False) self.table.installEventFilter(self) # Header style self.table.setStyleSheet(""" QHeaderView::section { background-color: #003366; color: white; font-weight: bold; padding: 6px; border: 1px solid #CCCCCC; } """) self.apply_row_colors() layout.addWidget(self.table) # ---------------- Buttons ---------------- button_layout = QHBoxLayout() button_layout.setSpacing(40) button_layout.addStretch() button_style = """ QPushButton { background-color: #00008B; /* Dark Blue */ color: white; /* White text */ font-weight: bold; border: 1px solid black; } QPushButton:pressed { background-color: #000066; /* Darker blue on press */ } """ submit_button = QPushButton("SUBMIT") submit_button.setFont(QFont("Times New Roman", 12, QFont.Bold)) submit_button.setFixedSize(150, 50) submit_button.setStyleSheet(button_style) submit_button.clicked.connect(self.submit_data) button_layout.addWidget(submit_button) back_button = QPushButton("BACK") back_button.setFont(QFont("Times New Roman", 12, QFont.Bold)) back_button.setFixedSize(150, 50) back_button.setStyleSheet(button_style) back_button.clicked.connect(go_home) button_layout.addWidget(back_button) button_layout.addStretch() layout.addLayout(button_layout) # ---------------- Helpers ---------------- def create_labeled_input(self, label_text): layout = QVBoxLayout() label = QLabel(label_text) label.setFont(QFont("Times New Roman", 12)) line_edit = QLineEdit() line_edit.setFixedWidth(200) layout.addWidget(label) layout.addWidget(line_edit) return {"layout": layout, "edit": line_edit} def add_row(self): row = self.table.rowCount() self.table.insertRow(row) for col in range(self.table.columnCount()): item = QTableWidgetItem("") item.setForeground(QBrush(QColor("black"))) color = QColor("#d8f3dc") if row % 2 == 0 else QColor("#d0f0ff") item.setBackground(QBrush(color)) self.table.setItem(row, col, item) def apply_row_colors(self): for row in range(self.table.rowCount()): for col in range(self.table.columnCount()): item = self.table.item(row, col) if item: color = QColor("#d8f3dc") if row % 2 == 0 else QColor("#d0f0ff") item.setBackground(QBrush(color)) def eventFilter(self, source, event): if source == self.table and event.type() == QEvent.KeyPress: row = self.table.currentRow() col = self.table.currentColumn() if event.key() in (Qt.Key_Return, Qt.Key_Enter): # Move to next column or add new row if col < self.table.columnCount() - 1: self.table.setCurrentCell(row, col + 1) else: self.add_row() self.table.setCurrentCell(self.table.rowCount() - 1, 0) return True elif event.key() == Qt.Key_Right: # Move right in same row if col < self.table.columnCount() - 1: self.table.setCurrentCell(row, col + 1) return True return super().eventFilter(source, event) def submit_data(self): data_rows = [] for row in range(self.table.rowCount()): row_data = [] for col in range(self.table.columnCount()): item = self.table.item(row, col) row_data.append(item.text().strip() if item else "") if any(row_data): data_rows.append(row_data) if not data_rows: QMessageBox.warning(self, "Empty Table", "Please enter at least one row of dimension data.") return try: with sqlite3.connect("/home/cri/myproject/sfgprinting.db") as conn: cursor = conn.cursor() for row in data_rows: name = row[0] if len(row) > 0 else "" value = row[1] if len(row) > 1 else "" entervalue = row[2] if len(row) > 2 else "" cursor.execute(""" INSERT INTO check_list_details ( Dimension_Name, Dimension_Value, Entered_Value ) VALUES (?, ?, ?) """, (name, value, entervalue)) conn.commit() QMessageBox.information(self, "Success", "Checklist data saved successfully.") self.clear_fields() except sqlite3.Error as e: QMessageBox.critical(self, "Database Error", f"SQLite error occurred:\n{e}") except Exception as e: QMessageBox.critical(self, "Error", f"Unexpected error occurred:\n{e}") def clear_fields(self): self.work_order['edit'].clear() self.serial_number['edit'].clear() self.operator_plant['edit'].clear() self.table.setRowCount(0) # Clear all rows def go_back(self): self.stacked_widget.setCurrentIndex(3) # -------------------------first off screen---------------------------------------# class FirstOff(QWidget): def __init__(self): super().__init__() self.setWindowTitle("First Off") self.resize(1400, 750) palette = self.palette() palette.setColor(QPalette.Window, QColor("#ADD8E6")) self.setAutoFillBackground(True) self.setPalette(palette) main_layout = QVBoxLayout(self) # Header header_widget = QWidget() header_widget.setStyleSheet("background-color: #003366;") header_layout = QHBoxLayout(header_widget) header_layout.setContentsMargins(10, 10, 10, 10) logo_label = QLabel() pixmap = QPixmap("/home/cri/myproject/cri_logo_red.png") pixmap = pixmap.scaled(60, 60, Qt.KeepAspectRatio, Qt.SmoothTransformation) logo_label.setPixmap(pixmap) logo_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) title_label = QLabel("PROCESS CHECK LIST") title_label.setFont(QFont("Times New Roman", 24, QFont.Bold)) title_label.setStyleSheet("color: white;") title_label.setAlignment(Qt.AlignCenter) header_layout.addWidget(logo_label) header_layout.addSpacing(20) header_layout.addWidget(title_label, stretch=1) header_layout.addStretch() main_layout.addWidget(header_widget) # Table self.table = QTableWidget(0, 3) self.table.setHorizontalHeaderLabels(["Dimension Name", "Dimension Value", "Enter Value"]) self.table.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents) self.table.setStyleSheet(""" QTableWidget { background-color: white; gridline-color: black; } QHeaderView::section { background-color: #00008B; color: white; font-weight: bold; padding: 4px; border: 1px solid black; } """) header = self.table.horizontalHeader() header.setSectionResizeMode(QHeaderView.Stretch) header.setHighlightSections(False) main_layout.addWidget(self.table, stretch=1) # Add first row self.add_row() # Install event filter to capture Enter key self.table.installEventFilter(self) # Back Button back_btn = QPushButton("BACK") back_btn.setFont(QFont("Times New Roman", 12, QFont.Bold)) back_btn.setStyleSheet(""" QPushButton { background-color: #00008B; /* Dark Blue */ color: white; border: 1px solid black; padding: 10px 20px; font-weight: bold; } QPushButton:pressed { background-color: #000066; /* Darker blue on press */ } """) back_btn.clicked.connect(go_home) main_layout.addWidget(back_btn, alignment=Qt.AlignCenter) def add_row(self): row = self.table.rowCount() self.table.insertRow(row) for col in range(self.table.columnCount()): item = QTableWidgetItem() bg_color = "white" if row % 2 == 0 else "#E6F0FF" item.setBackground(QBrush(QColor(bg_color))) self.table.setItem(row, col, item) def eventFilter(self, obj, event): if obj == self.table and event.type() == QEvent.KeyPress: if event.key() in (Qt.Key_Return, Qt.Key_Enter): row = self.table.currentRow() col = self.table.currentColumn() # Move to next column if col < self.table.columnCount() - 1: self.table.setCurrentCell(row, col + 1) else: # Last column, move to next row if row == self.table.rowCount() - 1: self.add_row() self.table.setCurrentCell(row + 1, 0) return True return super().eventFilter(obj, event) def go_back(self): self.stacked_widget.setCurrentIndex(4) # -------------------------final validation screen----------------------------------# class FinalValidation(QWidget): def __init__(self): super().__init__() self.setWindowTitle("Final Validation") self.resize(1400, 750) # Background palette = self.palette() palette.setColor(QPalette.Window, QColor("#ADD8E6")) self.setAutoFillBackground(True) self.setPalette(palette) main_layout = QVBoxLayout(self) # ================= Header ================= header_widget = QWidget() header_widget.setStyleSheet("background-color: #003366;") header_layout = QHBoxLayout(header_widget) header_layout.setContentsMargins(10, 10, 10, 10) logo_label = QLabel() pixmap = QPixmap("/home/cri/myproject/cri_logo_red.png") pixmap = pixmap.scaled(60, 60, Qt.KeepAspectRatio, Qt.SmoothTransformation) logo_label.setPixmap(pixmap) logo_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) title_label = QLabel("PART VALIDATION") title_label.setFont(QFont("Times New Roman", 24, QFont.Bold)) title_label.setStyleSheet("color: white;") title_label.setAlignment(Qt.AlignCenter) header_layout.addWidget(logo_label) header_layout.addSpacing(20) header_layout.addWidget(title_label, stretch=1) header_layout.addStretch() main_layout.addWidget(header_widget) # Top Info Layout info_layout = QHBoxLayout() self.work_order_input = QLineEdit() self.serial_input = QLineEdit() self.operator_input = QLineEdit() light_blue_style = "background-color: #E6F0FF;" self.work_order_input.setStyleSheet(light_blue_style) self.serial_input.setStyleSheet(light_blue_style) self.operator_input.setStyleSheet(light_blue_style) info_layout.addWidget(self._labeled_field("Work Order Number:", self.work_order_input)) info_layout.addWidget(self._labeled_field("Serial Number:", self.serial_input)) info_layout.addWidget(self._labeled_field("Operator Plant:", self.operator_input)) main_layout.addLayout(info_layout) # ================= Table ================= self.table = QTableWidget(0, 3) self.table.setHorizontalHeaderLabels(["Dimension Name", "Dimension Value", "Enter Value"]) self.table.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents) self.table.setStyleSheet(""" QTableWidget { background-color: white; gridline-color: black; } QHeaderView::section { background-color: #00008B; color: white; font-weight: bold; padding: 4px; border: 1px solid black; } """) header = self.table.horizontalHeader() header.setSectionResizeMode(QHeaderView.Stretch) header.setHighlightSections(False) main_layout.addWidget(self.table, stretch=1) # Add first row self.add_row() # Install event filter for Enter key self.table.installEventFilter(self) # ================= Back Button ================= back_btn = QPushButton("BACK") back_btn.setFont(QFont("Times New Roman", 12, QFont.Bold)) back_btn.setStyleSheet(""" QPushButton { background-color: #00008B; color: white; border: 1px solid black; padding: 10px 20px; font-weight: bold; } QPushButton:pressed { background-color: #000066; } """) back_btn.clicked.connect(go_home) main_layout.addWidget(back_btn, alignment=Qt.AlignCenter) def _labeled_field(self, label_text, line_edit): container = QWidget() layout = QHBoxLayout(container) layout.setContentsMargins(0, 0, 0, 0) label = QLabel(label_text) label.setFont(QFont("Times New Roman", 11)) label.setFixedWidth(160) line_edit.setFixedWidth(300) line_edit.setFixedHeight(30) line_edit.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) layout.addWidget(label) layout.addWidget(line_edit) return container def add_row(self): row = self.table.rowCount() self.table.insertRow(row) for col in range(self.table.columnCount()): item = QTableWidgetItem() bg_color = "white" if row % 2 == 0 else "#E6F0FF" item.setBackground(QBrush(QColor(bg_color))) self.table.setItem(row, col, item) def eventFilter(self, obj, event): if obj == self.table and event.type() == QEvent.KeyPress: if event.key() in (Qt.Key_Return, Qt.Key_Enter): row = self.table.currentRow() col = self.table.currentColumn() # Move to next column if col < self.table.columnCount() - 1: self.table.setCurrentCell(row, col + 1) else: # Last column → move to next row if row == self.table.rowCount() - 1: self.add_row() self.table.setCurrentCell(row + 1, 0) return True return super().eventFilter(obj, event) def go_back(self): self.stacked_widget.setCurrentIndex(5) # ---------------- Application Entry ---------------- # if __name__ == "__main__": app = QApplication(sys.argv) stacked_widget = QStackedWidget() login_screen = LoginScreen(stacked_widget) main_screen = MainScreen() stacked_widget.addWidget(login_screen) stacked_widget.addWidget(main_screen) stacked_widget.setCurrentIndex(0) global_stacked_widget = stacked_widget global_main_screen = main_screen stacked_widget.show() sys.exit(app.exec_())