150 lines
5.3 KiB
Python
150 lines
5.3 KiB
Python
from PySide6.QtWidgets import (
|
|
QWidget, QApplication, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QProgressBar, QCheckBox, QTextEdit, QSpinBox
|
|
)
|
|
from PySide6.QtCore import Qt, Signal
|
|
|
|
class MainWindow(QWidget):
|
|
start_signal = Signal()
|
|
show_results_signal = Signal()
|
|
toggle_auto_select_signal = Signal(bool)
|
|
toggle_show_results_signal = Signal(bool)
|
|
closing_signal = Signal() # 메인 윈도우 닫힘 시 emit
|
|
export_to_xls_signal = Signal()
|
|
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
self.setWindowTitle("SellFree 소서러")
|
|
|
|
# 레이아웃 설정
|
|
main_layout = QVBoxLayout()
|
|
|
|
# 버튼 추가
|
|
self.start_button = QPushButton("시작")
|
|
self.start_button.setFixedSize(120, 40)
|
|
self.start_button.clicked.connect(self.on_start_clicked)
|
|
|
|
self.results_button = QPushButton("결과보기")
|
|
self.results_button.setFixedSize(120, 40)
|
|
self.results_button.setEnabled(False) # 기본적으로 비활성화
|
|
self.results_button.clicked.connect(self.on_show_results_clicked)
|
|
|
|
self.export_button = QPushButton("엑셀추출") # 엑셀추출 버튼 추가
|
|
self.export_button.setFixedSize(120, 40)
|
|
self.export_button.setEnabled(False) # 기본적으로 비활성화
|
|
self.export_button.clicked.connect(self.on_export_to_xls_clicked)
|
|
|
|
button_layout = QHBoxLayout()
|
|
button_layout.addWidget(self.start_button)
|
|
button_layout.addWidget(self.results_button)
|
|
button_layout.addWidget(self.export_button) # 엑셀추출 버튼 추가
|
|
main_layout.addLayout(button_layout)
|
|
|
|
# 가격 필터링 CurrencySpinBox 추가
|
|
spinbox_layout = QHBoxLayout()
|
|
spinbox_label = QLabel("수집가격:")
|
|
self.price_spinbox = CurrencySpinBox() # 커스텀 CurrencySpinBox 사용
|
|
spinbox_layout.addWidget(spinbox_label)
|
|
spinbox_layout.addWidget(self.price_spinbox)
|
|
main_layout.addLayout(spinbox_layout)
|
|
|
|
|
|
# 토글 버튼 추가
|
|
self.auto_select_checkbox = QCheckBox("자동선택")
|
|
self.auto_select_checkbox.setChecked(False)
|
|
self.auto_select_checkbox.stateChanged.connect(self.on_auto_select_toggled)
|
|
|
|
self.show_results_checkbox = QCheckBox("결과보기")
|
|
self.show_results_checkbox.setChecked(False)
|
|
self.show_results_checkbox.stateChanged.connect(self.on_show_results_toggled)
|
|
|
|
toggle_layout = QHBoxLayout()
|
|
toggle_layout.addWidget(self.auto_select_checkbox)
|
|
toggle_layout.addWidget(self.show_results_checkbox)
|
|
main_layout.addLayout(toggle_layout)
|
|
|
|
# 진행 상태 표시
|
|
self.progress_bar = QProgressBar()
|
|
self.progress_bar.setAlignment(Qt.AlignCenter)
|
|
self.progress_bar.setValue(0)
|
|
main_layout.addWidget(self.progress_bar)
|
|
|
|
# 로그 표시기
|
|
self.log_viewer = QTextEdit()
|
|
self.log_viewer.setReadOnly(True)
|
|
self.log_viewer.setFixedHeight(100)
|
|
main_layout.addWidget(self.log_viewer)
|
|
|
|
self.setLayout(main_layout)
|
|
|
|
def on_start_clicked(self):
|
|
self.start_signal.emit()
|
|
|
|
def on_show_results_clicked(self):
|
|
print(f"on_show_results_clicked")
|
|
self.show_results_signal.emit()
|
|
|
|
def on_auto_select_toggled(self, state):
|
|
self.toggle_auto_select_signal.emit(bool(state))
|
|
|
|
def on_show_results_toggled(self, state):
|
|
self.toggle_show_results_signal.emit(bool(state))
|
|
|
|
def update_progress(self, value):
|
|
self.progress_bar.setValue(value)
|
|
|
|
def log_message(self, message):
|
|
self.log_viewer.append(message)
|
|
|
|
def enable_results_button(self):
|
|
self.results_button.setEnabled(True)
|
|
|
|
def disable_start_button(self):
|
|
self.start_button.setEnabled(False)
|
|
|
|
def enable_export_button(self): # 엑셀추출 버튼 활성화
|
|
self.export_button.setEnabled(True)
|
|
|
|
def on_export_to_xls_clicked(self): # 엑셀추출 버튼 클릭 이벤트
|
|
self.export_to_xls_signal.emit()
|
|
|
|
def closeEvent(self, event):
|
|
"""메인 윈도우가 닫힐 때 closing_signal을 emit"""
|
|
self.closing_signal.emit()
|
|
super().closeEvent(event)
|
|
|
|
|
|
|
|
|
|
|
|
class CurrencySpinBox(QSpinBox):
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
self.setRange(0, 999_999_999) # 최소값 0, 최대값 999,999,999
|
|
self.setValue(30_000) # 기본값 설정
|
|
self.setPrefix("₩") # 앞에 '₩' 추가
|
|
self.setToolTip("0원이면 가격 필터링 해제") # 툴팁 추가
|
|
self.setAlignment(Qt.AlignRight) # 텍스트 정렬
|
|
|
|
def textFromValue(self, value):
|
|
# 3자리마다 콤마 추가
|
|
return f"{value:,}"
|
|
|
|
def valueFromText(self, text):
|
|
# '₩'와 ',' 제거 후 숫자로 변환
|
|
return int(text.replace("₩", "").replace(",", ""))
|
|
|
|
def wheelEvent(self, event):
|
|
steps = event.angleDelta().y() // 120 # 휠 회전 단계
|
|
modifier = QApplication.keyboardModifiers()
|
|
|
|
if modifier == Qt.ControlModifier: # Ctrl 키가 눌려 있는 경우
|
|
increment = 10_000
|
|
else: # 기본 증가/감소 값
|
|
increment = 1_000
|
|
|
|
self.setValue(self.value() + steps * increment)
|
|
event.accept()
|