273 lines
12 KiB
Python
273 lines
12 KiB
Python
from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel, QLineEdit,
|
|
QPushButton, QTabWidget, QCheckBox, QFrame, QDialog, QDialogButtonBox,
|
|
QFontDialog, QMenuBar, QAction, QMessageBox)
|
|
from PyQt5.QtCore import Qt
|
|
from PyQt5.Qsci import QsciScintilla, QsciLexerPython
|
|
from qfluentwidgets import CalendarPicker
|
|
|
|
class BusinessSettings(QDialog):
|
|
def __init__(self, max_business_count=3, parent=None):
|
|
super().__init__(parent)
|
|
self.max_business_count = max_business_count
|
|
self.business_info = [{} for _ in range(max_business_count)]
|
|
self.market_info = [{} for _ in range(max_business_count)]
|
|
self.other_info = [{} for _ in range(max_business_count)]
|
|
self.selected_markets = {market: True for market in ["쿠팡", "스마트스토어", "ESM", "11번가-국내", "11번가-글로벌", "롯데온", "인터파크", "위메프", "옥션1.0"]}
|
|
self.initUI()
|
|
|
|
def initUI(self):
|
|
self.setLayout(QVBoxLayout())
|
|
|
|
# 상단 버튼 레이아웃
|
|
top_layout = QHBoxLayout()
|
|
top_frame = QFrame(self)
|
|
top_frame.setLayout(top_layout)
|
|
top_frame.setFrameShape(QFrame.StyledPanel)
|
|
top_frame.setFixedHeight(int(self.height() * 0.1))
|
|
|
|
save_button = QPushButton("저장")
|
|
save_button.clicked.connect(lambda: print("저장 버튼 클릭됨"))
|
|
delete_button = QPushButton("삭제")
|
|
delete_button.clicked.connect(lambda: print("삭제 버튼 클릭됨"))
|
|
cancel_button = QPushButton("취소")
|
|
cancel_button.clicked.connect(lambda: print("취소 버튼 클릭됨"))
|
|
setup_market_button = QPushButton("설정마켓")
|
|
setup_market_button.clicked.connect(self.show_market_setup)
|
|
|
|
top_layout.addWidget(save_button)
|
|
top_layout.addWidget(delete_button)
|
|
top_layout.addWidget(cancel_button)
|
|
top_layout.addWidget(setup_market_button)
|
|
self.layout().addWidget(top_frame)
|
|
|
|
# QTabWidget 설정
|
|
self.tab_widget = QTabWidget()
|
|
self.tab_widget.setTabsClosable(False)
|
|
self.layout().addWidget(self.tab_widget)
|
|
|
|
for i in range(self.max_business_count):
|
|
tab = QWidget()
|
|
tab.setLayout(QVBoxLayout())
|
|
tab.layout().addLayout(self.create_business_info_layout(i))
|
|
tab.layout().addWidget(self.create_market_info_widget())
|
|
tab.layout().setStretch(0, 3)
|
|
tab.layout().setStretch(1, 2)
|
|
self.tab_widget.addTab(tab, f"{i + 1}사업자")
|
|
|
|
self.tab_widget.currentChanged.connect(self.update_tab_styles)
|
|
self.update_tab_styles()
|
|
|
|
def create_business_info_layout(self, index):
|
|
layout = QGridLayout()
|
|
|
|
layout.addWidget(QLabel("사업자 별칭"), 0, 0)
|
|
alias_input = QLineEdit()
|
|
alias_input.textChanged.connect(lambda text, idx=index: self.update_tab_title(text, idx))
|
|
layout.addWidget(alias_input, 0, 1)
|
|
|
|
labels = ["사업자 등록번호", "상호명", "등록날짜", "전화번호"]
|
|
for i, label in enumerate(labels):
|
|
layout.addWidget(QLabel(label, alignment=Qt.AlignCenter), 1, i)
|
|
|
|
self.bs_number_edit = QLineEdit()
|
|
self.bs_number_edit.setMinimumWidth(60)
|
|
layout.addWidget(self.bs_number_edit, 2, 0)
|
|
self.bs_name_edit = QLineEdit()
|
|
self.bs_name_edit.setMinimumWidth(60)
|
|
layout.addWidget(self.bs_name_edit, 2, 1)
|
|
|
|
self.datePicker = CalendarPicker(self)
|
|
self.datePicker.setMinimumWidth(60)
|
|
self.datePicker.dateChanged.connect(lambda t: print(t.toString()))
|
|
layout.addWidget(self.datePicker, 2, 2)
|
|
|
|
# set date
|
|
# self.picker.setDate(QDate(2023, 5, 30))
|
|
|
|
# customize date format
|
|
# self.picker.setDateFormat(Qt.TextDate)
|
|
# self.picker.setDateFormat('yyyy-M-d')
|
|
|
|
self.bs_call_edit = QLineEdit()
|
|
self.bs_call_edit.setMinimumWidth(60)
|
|
layout.addWidget(self.bs_call_edit, 2, 3)
|
|
|
|
other_info_labels = ["기타 정보1", "기타 정보2", "기타 정보3", "기타 정보4"]
|
|
for i, label in enumerate(other_info_labels):
|
|
button = QPushButton(label)
|
|
button.clicked.connect(lambda checked, lbl=label, idx=index, btn=button: self.show_other_info_dialog(lbl, idx, btn))
|
|
layout.addWidget(button, 3, i)
|
|
|
|
return layout
|
|
|
|
def create_market_info_widget(self):
|
|
layout = QTabWidget()
|
|
|
|
market_tabs = {
|
|
"쿠팡": [("쿠팡ID", ""), ("업체코드", ""), ("Access Key", ""), ("Secret Key", "")],
|
|
"스마트스토어": [("계정 ID", ""), ("계정 PW", ""), ("애플리케이션 ID", ""), ("애플리케이션 시크릿", "")],
|
|
"ESM": [("옥션ID", ""), ("G마켓 ID", "")],
|
|
"11번가-국내": [("API KEY", "")],
|
|
"11번가-글로벌": [("API KEY", "")],
|
|
"롯데온": [("API KEY", "")],
|
|
"인터파크": [("상품상태재고수정 인증키", ""), ("상품상태재고수정 비밀키", ""),
|
|
("상품재고조회 인증키", ""), ("상품재고조회 비밀키", ""),
|
|
("상품정보조회 인증", ""), ("상품정보조회 비밀키", ""),
|
|
("상품수정 인증키", ""), ("상품수정 비밀키", ""),
|
|
("상품등록 인증키", ""), ("상품등록 비밀키", ""),
|
|
("반품배송지조회 인증키", ""), ("반품배송지조회 비밀키", ""),
|
|
("반품배송지등록 인증키", ""), ("반품배송지등록 비밀키", ""),
|
|
("상품QnA등록 인증키", ""), ("상품QnA등록 비밀키", ""),
|
|
("상품QnA조회 인증키", ""), ("상품QnA조회 비밀키", ""),
|
|
("인터파크 업체번호", ""), ("공급계약 일련번호", "")],
|
|
"위메프": [("API KEY", "")],
|
|
"옥션1.0": [("멤버 ID", "")]
|
|
}
|
|
|
|
for market, fields in market_tabs.items():
|
|
tab = QWidget()
|
|
tab_layout = QGridLayout()
|
|
for i, (label_text, placeholder) in enumerate(fields):
|
|
tab_layout.addWidget(QLabel(label_text), i, 0)
|
|
tab_layout.addWidget(QLineEdit(placeholder), i, 1)
|
|
tab.setLayout(tab_layout)
|
|
if self.selected_markets[market]:
|
|
layout.addTab(tab, market)
|
|
|
|
return layout
|
|
|
|
def show_market_setup(self):
|
|
dialog = QDialog(self)
|
|
dialog.setWindowTitle("설정 마켓")
|
|
dialog.setLayout(QVBoxLayout())
|
|
layout = dialog.layout()
|
|
|
|
all_select_checkbox = QCheckBox("전체선택")
|
|
all_select_checkbox.setChecked(all(self.selected_markets.values()))
|
|
all_select_checkbox.stateChanged.connect(self.toggle_all_markets)
|
|
layout.addWidget(all_select_checkbox)
|
|
market_layout = QGridLayout()
|
|
|
|
markets = list(self.selected_markets.keys())
|
|
self.market_checkboxes = []
|
|
for i, market in enumerate(markets):
|
|
checkbox = QCheckBox(market)
|
|
checkbox.setChecked(self.selected_markets[market])
|
|
self.market_checkboxes.append(checkbox)
|
|
market_layout.addWidget(checkbox, i // 3, i % 3)
|
|
|
|
layout.addLayout(market_layout)
|
|
|
|
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
|
button_box.accepted.connect(dialog.accept)
|
|
button_box.rejected.connect(dialog.reject)
|
|
layout.addWidget(button_box)
|
|
|
|
if dialog.exec() == QDialog.Accepted:
|
|
for i, checkbox in enumerate(self.market_checkboxes):
|
|
self.selected_markets[markets[i]] = checkbox.isChecked()
|
|
self.update_market_tabs()
|
|
|
|
def toggle_all_markets(self, state):
|
|
for checkbox in self.market_checkboxes:
|
|
checkbox.setChecked(state == Qt.Checked)
|
|
|
|
def update_market_tabs(self):
|
|
for i in range(self.tab_widget.count()):
|
|
tab = self.tab_widget.widget(i)
|
|
market_info_widget = tab.layout().itemAt(1).widget()
|
|
for j in range(market_info_widget.count()):
|
|
market_tab = market_info_widget.widget(j)
|
|
market_name = market_info_widget.tabText(j)
|
|
market_info_widget.setTabVisible(j, self.selected_markets[market_name])
|
|
|
|
def show_other_info_dialog(self, label, index, button):
|
|
dialog = QDialog(self)
|
|
dialog.setWindowTitle(label)
|
|
layout = QVBoxLayout(dialog)
|
|
|
|
# 메뉴 바 생성
|
|
menu_bar = QMenuBar()
|
|
layout.setMenuBar(menu_bar)
|
|
|
|
# 폰트 선택 메뉴 추가
|
|
font_menu = menu_bar.addMenu('Font')
|
|
select_font_action = QAction('Select Font', self)
|
|
font_menu.addAction(select_font_action)
|
|
|
|
title_layout = QHBoxLayout()
|
|
title_layout.addWidget(QLabel("제목"))
|
|
title_input = QLineEdit()
|
|
title_layout.addWidget(title_input, 3)
|
|
layout.addLayout(title_layout)
|
|
|
|
content_layout = QVBoxLayout()
|
|
content_layout.addWidget(QLabel("내용"))
|
|
content_editor = QsciScintilla()
|
|
content_lexer = QsciLexerPython()
|
|
content_editor.setLexer(content_lexer)
|
|
content_layout.addWidget(content_editor)
|
|
layout.addLayout(content_layout)
|
|
|
|
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
|
button_box.accepted.connect(lambda: dialog.accept())
|
|
button_box.rejected.connect(lambda: dialog.reject())
|
|
layout.addWidget(button_box)
|
|
|
|
# 폰트 선택 메뉴 동작 연결
|
|
select_font_action.triggered.connect(lambda: self.select_font(content_editor))
|
|
|
|
# 기존 정보가 없으면 초기화
|
|
if label not in self.other_info[index]:
|
|
self.other_info[index][label] = {"title": "", "content": ""}
|
|
|
|
# 기존 정보가 있으면 로드
|
|
title_input.setText(self.other_info[index][label].get("title", ""))
|
|
content_editor.setText(self.other_info[index][label].get("content", ""))
|
|
|
|
if dialog.exec() == QDialog.Accepted:
|
|
new_title = title_input.text()
|
|
new_content = content_editor.text()
|
|
old_title = self.other_info[index][label].get("title", "")
|
|
old_content = self.other_info[index][label].get("content", "")
|
|
|
|
if new_title != old_title or new_content != old_content:
|
|
confirmation = QMessageBox.question(self, "변경 사항 확인", "내용이 변경되었습니다. 저장하시겠습니까?",
|
|
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
|
|
if confirmation == QMessageBox.Yes:
|
|
self.other_info[index][label] = {
|
|
"title": new_title,
|
|
"content": new_content
|
|
}
|
|
button.setText(new_title)
|
|
else:
|
|
self.other_info[index][label] = {
|
|
"title": new_title,
|
|
"content": new_content
|
|
}
|
|
button.setText(new_title)
|
|
|
|
# Print the other_info dictionary for debugging
|
|
print(self.other_info)
|
|
|
|
def select_font(self, content_editor):
|
|
font, ok = QFontDialog.getFont()
|
|
if ok:
|
|
content_editor.setFont(font)
|
|
|
|
def update_tab_title(self, text, index):
|
|
if text:
|
|
self.tab_widget.setTabText(index, text)
|
|
else:
|
|
self.tab_widget.setTabText(index, f"{index + 1}사업자")
|
|
|
|
def update_tab_styles(self):
|
|
for i in range(self.tab_widget.count()):
|
|
tab_bar = self.tab_widget.tabBar()
|
|
if i == self.tab_widget.currentIndex():
|
|
tab_bar.setTabTextColor(i, Qt.black)
|
|
tab_bar.setStyleSheet("QTabBar::tab:selected { background: lightgreen; }")
|
|
else:
|
|
tab_bar.setTabTextColor(i, Qt.black)
|
|
tab_bar.setStyleSheet("QTabBar::tab:!selected { background: transparent; }")
|