버전 업그레이드

This commit is contained in:
2026-06-18 13:38:27 +09:00
parent a48a4b5fe5
commit ba33a78fec
37 changed files with 3355 additions and 1165 deletions

View File

@@ -2,13 +2,15 @@
import cv2
import numpy as np
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtGui import QImage, QPixmap, QColor
from PyQt5.QtWidgets import (
QWidget, QHBoxLayout, QVBoxLayout, QGroupBox,
QPushButton, QListWidget, QListWidgetItem, QLabel,
QMessageBox, QScrollArea, QFrame,
)
from db.sql_client import SQLClient
_GRP_STYLE = (
"QGroupBox {"
@@ -20,11 +22,13 @@ _GRP_STYLE = (
class RegisterPage(QWidget):
def __init__(self, insight_cam, matcher=None, db_client=None, parent=None):
def __init__(self, insight_cam, matcher=None, db_client=None, config=None, parent=None):
super().__init__(parent)
self._insight = insight_cam
self._db_client = db_client
self._config = config or {}
self._db_items = []
self._wk_map = {}
self._selected = None
self._captured_img = None
@@ -49,12 +53,8 @@ class RegisterPage(QWidget):
layout.setSpacing(10)
self._btn_mes = QPushButton("MES 불러오기")
self._btn_mes.setVisible(False)
self._btn_mes.setEnabled(False)
self._btn_mes.setFixedHeight(56)
self._btn_mes.setToolTip("DB 연결 후 사용 가능")
self._btn_mes.setStyleSheet(
"background:#444444; color:#777777; border:none; border-radius:4px; font-size:15px;"
)
self._btn_mes.clicked.connect(self._on_load_from_db)
layout.addWidget(self._btn_mes)
@@ -69,10 +69,8 @@ class RegisterPage(QWidget):
border-radius:4px; outline:none; font-size:15px;
}
QListWidget::item {
padding:0px 14px; border-bottom:1px solid #2a2a2a; color:#dddddd;
padding:0px 14px; border-bottom:1px solid #2a2a2a;
}
QListWidget::item:selected { background:#185FA5; color:#ffffff; }
QListWidget::item:hover:!selected { background:#2d2d2d; }
""")
self._list.currentRowChanged.connect(self._on_select)
layout.addWidget(self._list, stretch=1)
@@ -109,9 +107,19 @@ class RegisterPage(QWidget):
self._lbl_name = _info_value("")
self._lbl_model = _info_value("")
self._lbl_type = _info_value("")
self._lbl_wk = _info_value("")
self._lbl_machine_id = _info_value("")
self._lbl_machine = _info_value("")
self._lbl_work_date = _info_value("")
self._lbl_work_time = _info_value("")
layout.addLayout(_info_row("카테고리", self._lbl_name))
layout.addLayout(_info_row("모델명", self._lbl_model))
layout.addLayout(_info_row("Type", self._lbl_type))
layout.addLayout(_info_row("작업상태", self._lbl_wk))
layout.addLayout(_info_row("설비 ID", self._lbl_machine_id))
layout.addLayout(_info_row("설비명", self._lbl_machine))
layout.addLayout(_info_row("작업시작일", self._lbl_work_date))
layout.addLayout(_info_row("작업시작", self._lbl_work_time))
self._arrow_lbl = QLabel("")
self._arrow_lbl.setAlignment(Qt.AlignCenter)
@@ -157,21 +165,28 @@ class RegisterPage(QWidget):
if row < 0:
return
item = self._list.item(row)
if item is None:
if item is None or not (item.flags() & Qt.ItemIsSelectable):
return
article_id = item.data(Qt.UserRole)
if article_id is None:
return
self._refresh_list_styles(row)
db_item = next(
(x for x in self._db_items if x["article_id"] == article_id), None
(x for x in self._db_items
if SQLClient._norm_id(x["article_id"]) == SQLClient._norm_id(article_id)),
None,
)
name = item.data(Qt.UserRole + 1) or item.text()
in_wk = bool(item.data(Qt.UserRole + 2))
r = {
"id": article_id,
"name": item.text(),
"name": name,
"model": db_item.get("buyer_article_no", "") if db_item else "",
"type": "",
"in_wk": in_wk,
}
self._selected = r
@@ -181,6 +196,20 @@ class RegisterPage(QWidget):
self._lbl_model.setText(r["model"])
t = r.get("type", "")
self._lbl_type.setText(t if t else "")
if in_wk:
self._lbl_wk.setText("작업 대상")
self._lbl_wk.setStyleSheet("color:#cccccc; font-size:16px; font-weight:bold;")
wk = self._wk_map.get(SQLClient._norm_id(article_id), {})
self._lbl_machine_id.setText(SQLClient.format_db_value(wk.get("machine_id")))
self._lbl_machine.setText(SQLClient.format_db_value(wk.get("machine")))
self._lbl_work_date.setText(SQLClient.format_db_value(wk.get("work_start_date")))
self._lbl_work_time.setText(SQLClient.format_db_value(wk.get("work_start_time")))
else:
self._lbl_wk.setText("작업 대외")
self._lbl_wk.setStyleSheet("color:#888888; font-size:16px; font-weight:bold;")
for lbl in (self._lbl_machine_id, self._lbl_machine,
self._lbl_work_date, self._lbl_work_time):
lbl.setText("")
if t == "RH":
self._arrow_lbl.setText("")
@@ -219,35 +248,111 @@ class RegisterPage(QWidget):
def update_db(self, db_client):
"""MainWindow에서 DB 연결/해제 시 호출."""
self._db_client = db_client
enabled = db_client is not None and db_client.is_connected()
self._btn_mes.setEnabled(enabled)
self._btn_mes.setStyleSheet(
"background:#1a3a5c; color:#ffffff; border:none; border-radius:4px; font-size:15px;"
if enabled else
"background:#444444; color:#777777; border:none; border-radius:4px; font-size:15px;"
self.load_products()
def load_products(self):
"""관리자 설정에서 선택한 MES 제품 목록을 자동으로 불러온다."""
self._list.clear()
self._db_items = []
self._wk_map = {}
self._selected = None
self._lbl_name.setText("")
self._lbl_model.setText("")
self._lbl_type.setText("")
self._lbl_wk.setText("")
self._lbl_wk.setStyleSheet("color:#ffffff; font-size:16px; font-weight:bold;")
for lbl in (self._lbl_machine_id, self._lbl_machine,
self._lbl_work_date, self._lbl_work_time):
lbl.setText("")
self._arrow_lbl.setText("")
self._reset_preview()
if not self._db_client or not self._db_client.is_connected():
return
selected_ids = self._config.get("mes", {}).get("selected_article_ids")
if selected_ids is not None and len(selected_ids) == 0:
return
all_items = self._db_client.get_reflector_list(
article_ids=selected_ids if selected_ids is not None else None
)
if not all_items:
return
self._wk_map = self._db_client.get_wk_result_map()
active, inactive = self._db_client.split_articles_by_wk(selected_ids)
self._db_items = all_items
if active:
self._add_section_header(f"작업 대상 — WK_Result ({len(active)})")
for item in active:
self._add_product_item(item, in_wk=True)
if inactive:
self._add_section_header(f"기타 ({len(inactive)})")
for item in inactive:
self._add_product_item(item, in_wk=False)
self._refresh_list_styles()
def _on_load_from_db(self):
if not self._db_client or not self._db_client.is_connected():
QMessageBox.warning(self, "경고", "DB를 먼저 연결해주세요.")
return
pass
items = self._db_client.get_reflector_list()
if not items:
QMessageBox.warning(self, "경고", "조회된 제품이 없습니다.")
return
def _add_section_header(self, text: str):
hi = QListWidgetItem(text)
hi.setFlags(Qt.NoItemFlags)
hi.setForeground(QColor("#aaaaaa"))
hi.setBackground(QColor("#2a2a2a"))
hi.setSizeHint(QSize(0, 40))
self._list.addItem(hi)
self._list.clear()
self._db_items = items
for item in items:
li = QListWidgetItem(item['article'])
li.setSizeHint(QSize(0, 52))
li.setData(Qt.UserRole, item["article_id"])
self._list.addItem(li)
def _add_product_item(self, item: dict, in_wk: bool):
li = QListWidgetItem(item["article"])
li.setSizeHint(QSize(0, 52))
li.setData(Qt.UserRole, item["article_id"])
li.setData(Qt.UserRole + 1, item["article"])
li.setData(Qt.UserRole + 2, in_wk)
if in_wk:
wk = self._wk_map.get(SQLClient._norm_id(item["article_id"]), {})
tips = []
if wk.get("machine_id") is not None:
tips.append(f"설비 ID: {SQLClient.format_db_value(wk.get('machine_id'))}")
if wk.get("machine") is not None:
tips.append(f"설비: {SQLClient.format_db_value(wk.get('machine'))}")
if wk.get("work_start_date") is not None:
tips.append(f"시작일: {SQLClient.format_db_value(wk.get('work_start_date'))}")
if wk.get("work_start_time") is not None:
tips.append(f"시작: {SQLClient.format_db_value(wk.get('work_start_time'))}")
if tips:
li.setToolTip("\n".join(tips))
self._list.addItem(li)
self._style_product_item(li, in_wk, selected=False)
QMessageBox.information(
self, "완료", f"{len(items)}개 제품을 불러왔습니다."
)
@staticmethod
def _style_product_item(item: QListWidgetItem, in_wk: bool, selected: bool):
if in_wk:
if selected:
bg, fg = "#777777", "#ffffff"
else:
bg, fg = "#555555", "#eeeeee"
elif selected:
bg, fg = "#3a3a3a", "#aaaaaa"
else:
bg, fg = "#1e1e1e", "#666666"
item.setBackground(QColor(bg))
item.setForeground(QColor(fg))
def _refresh_list_styles(self, selected_row: int = -1):
if selected_row < 0:
selected_row = self._list.currentRow()
for i in range(self._list.count()):
item = self._list.item(i)
if not (item.flags() & Qt.ItemIsSelectable):
continue
in_wk = bool(item.data(Qt.UserRole + 2))
self._style_product_item(item, in_wk, selected=(i == selected_row))
# ================================================================== #
# 헬퍼