129 lines
4.4 KiB
Python
129 lines
4.4 KiB
Python
# ui/layouts.py
|
|
from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QLabel, QCheckBox, QLineEdit, QTableWidget, QPlainTextEdit, QTableWidgetItem, QHeaderView
|
|
import sqlite3
|
|
import pandas as pd
|
|
from logger import default_logger
|
|
from ui.toggleSwitch import ToggleSwitch
|
|
|
|
class QHLayout(QHBoxLayout):
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
class QVLayout(QVBoxLayout):
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
class ToggleLayout(QHBoxLayout):
|
|
def __init__(self, label_text, initial_state=False):
|
|
super().__init__()
|
|
self.label = QLabel(label_text)
|
|
self.toggle_switch = ToggleSwitch()
|
|
self.toggle_switch.setState(initial_state)
|
|
|
|
if label_text == "전체":
|
|
self.label.setStyleSheet("font-weight: bold; font-size: 14px;")
|
|
self.toggle_switch.setStyleSheet("font-weight: bold; font-size: 14px;")
|
|
|
|
self.addWidget(self.label)
|
|
self.addWidget(self.toggle_switch)
|
|
|
|
self.toggle_switch.clicked.connect(self.on_toggle)
|
|
|
|
def is_toggled(self):
|
|
return self.toggle_switch.isChecked()
|
|
|
|
def on_toggle(self, checked):
|
|
state = "on" if checked else "off"
|
|
default_logger.info(f"Toggle {self.label.text()} turned {state}.")
|
|
|
|
class SearchTextLayout(QHBoxLayout):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.label = QLabel('검색')
|
|
self.addWidget(self.label)
|
|
self.search_field = QLineEdit()
|
|
self.addWidget(self.search_field)
|
|
|
|
self.search_history = []
|
|
|
|
self.search_field.textChanged.connect(self.search)
|
|
|
|
def search(self):
|
|
search_text = self.search_field.text()
|
|
default_logger.info(f"Searching for: {search_text}")
|
|
if search_text and search_text not in self.search_history:
|
|
self.search_history.append(search_text)
|
|
self.async_search(search_text)
|
|
|
|
def async_search(self, text):
|
|
pass
|
|
|
|
class LogLayout(QVBoxLayout):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.label = QLabel('로그')
|
|
self.addWidget(self.label)
|
|
self.log_area = QPlainTextEdit()
|
|
self.log_area.setReadOnly(True)
|
|
self.addWidget(self.log_area)
|
|
|
|
def log_message(self, message):
|
|
self.log_area.appendPlainText(message)
|
|
|
|
class TableLayout(QVBoxLayout):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.table = QTableWidget()
|
|
self.addWidget(self.table)
|
|
self.init_table()
|
|
|
|
def init_table(self):
|
|
try:
|
|
self.table.setColumnCount(6)
|
|
self.table.setHorizontalHeaderLabels(['순서', '기호', '원어', '명칭', '기능설명', '비고'])
|
|
self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
|
self.table.setSelectionBehavior(QTableWidget.SelectRows)
|
|
self.update_table()
|
|
except Exception as e:
|
|
default_logger.error(f"Error initializing table: {e}")
|
|
|
|
def update_table(self):
|
|
try:
|
|
conn = sqlite3.connect('datas.db')
|
|
query = "SELECT * FROM CircuitBreakers"
|
|
result = pd.read_sql_query(query, conn)
|
|
conn.close()
|
|
|
|
self.table.setRowCount(len(result))
|
|
for i, row in result.iterrows():
|
|
for j, value in enumerate(row):
|
|
item = QTableWidgetItem(str(value))
|
|
item.setFlags(item.flags() ^ Qt.ItemIsEditable)
|
|
self.table.setItem(i, j, item)
|
|
|
|
self.table.cellClicked.connect(self.on_cell_click)
|
|
self.table.cellDoubleClicked.connect(self.on_cell_double_click)
|
|
except Exception as e:
|
|
default_logger.error(f"Error updating table: {e}")
|
|
|
|
def on_cell_click(self, row, column):
|
|
try:
|
|
default_logger.info(f"Cell clicked: ({row}, {column})")
|
|
for col in range(self.table.columnCount()):
|
|
self.table.item(row, col).setBackground(Qt.yellow)
|
|
except Exception as e:
|
|
default_logger.error(f"Error on cell click: {e}")
|
|
|
|
def on_cell_double_click(self, row, column):
|
|
try:
|
|
default_logger.info(f"Cell double clicked: ({row}, {column})")
|
|
except Exception as e:
|
|
default_logger.error(f"Error on cell double click: {e}")
|
|
|
|
def clear_table(self):
|
|
try:
|
|
self.table.setRowCount(0)
|
|
default_logger.info("Table cleared.")
|
|
except Exception as e:
|
|
default_logger.error(f"Error clearing table: {e}")
|