210 lines
8.5 KiB
Python
210 lines
8.5 KiB
Python
import sys
|
|
from datetime import datetime
|
|
|
|
#from modules.keyword_management import add_keyword
|
|
#from modules.product_parsing import parse_naver_shopping
|
|
#from modules.matching_operations import save_matching_info
|
|
from modules.pandas_data import PandasModel
|
|
from modules.spinBox import CustomSpinBox
|
|
from modules.webPage import CustomWebEnginePage
|
|
from modules.dbConnect import MongoConnectionWidget
|
|
from modules.login_widget import LoginWidget
|
|
from modules.mongo_config import MongoConfig
|
|
from modules.DBList import DbDialog
|
|
|
|
|
|
from PyQt5 import QtCore, QtWidgets, uic
|
|
from PyQt5.QtWidgets import QApplication
|
|
from PyQt5.QtWidgets import QApplication, QFileDialog, QTableWidgetItem, QLabel, QMainWindow, QTableView, QVBoxLayout, QWidget, QComboBox, QMessageBox, QGraphicsScene, QGraphicsPixmapItem, QDialogButtonBox, QInputDialog, QMessageBox, QTabWidget, QSpinBox
|
|
from PyQt5.QtCore import Qt, QUrl, pyqtSignal, QAbstractTableModel, QTimer, QObject, pyqtSlot, QEvent, QUrl, QTimer
|
|
from PyQt5.QtWebEngineWidgets import QWebEngineProfile
|
|
|
|
from pymongo import MongoClient
|
|
|
|
class MainWindow(QtWidgets.QMainWindow):
|
|
def __init__(self, mongo_config, email, user_info):
|
|
super(MainWindow, self).__init__()
|
|
# UI 파일 로드
|
|
uic.loadUi('MainTao.ui', self)
|
|
self.mongo_config = mongo_config
|
|
self.client = self.mongo_config.client
|
|
|
|
|
|
self.currentUserEmail = email
|
|
self.currentUserInfo = user_info
|
|
|
|
if self.currentUserEmail:
|
|
# 사용자 이메일 기반 데이터베이스 설정
|
|
user_id = self.currentUserEmail.split('@')[0]
|
|
Listup_user_id = 'Listup_id_' + user_id
|
|
self.mydb = self.client[Listup_user_id]
|
|
|
|
|
|
|
|
# # 데이터베이스 선택
|
|
# self.logindb = self.client['taobao_project']
|
|
now = datetime.now()
|
|
|
|
# 컬렉션(테이블) 선택, 없으면 생성
|
|
#collection = self.db['컬렉션명']
|
|
self.loginUser.setText("로그인 되지 않음")
|
|
#self.login_widget = LoginWidget() # login_widget 인스턴스 저장
|
|
self.currentUserEmail = None # 사용자 이메일 주소를 저장할 멤버 변수 초기화
|
|
self.currentUserInfo = None # 사용자 정보를 저장할 멤버 변수 초기화
|
|
self.mydb = None
|
|
|
|
self.login_widget = LoginWidget(mongo_config, self) # LoginWidget 인스턴스 생성 및 저장
|
|
|
|
self.count_test1 = 0
|
|
self.count_test2 = 0
|
|
self.papago_client_id =""
|
|
self.papago_client_secret = ""
|
|
self.tao_id = "id_input"
|
|
self.tao_pw = "password_input"
|
|
|
|
# DB 목록 선택 Dialog 객체 생성
|
|
self.db_dialog = DbDialog(self.mydb)
|
|
|
|
#self.img_searchbtn.clicked.connect(self.img_search)
|
|
#self.Excel_btn.clicked.connect(self.openxls)
|
|
#self.matchbtn.clicked.connect(self.matchbtn_clicked)
|
|
#self.webEngineView.urlChanged.connect(self.update_url)
|
|
#self.dbviewer1.clicked.connect(self.on_table_clicked)
|
|
#self.sc_button.clicked.connect(self.on_button_clicked)
|
|
#self.papagoApi.clicked.connect(self.manage_papago_api_keys)
|
|
|
|
# 프로그램 초기화 부분에 API 키 관리 함수 호출
|
|
#self.manage_papago_api_keys()
|
|
# 초기 탭 설정
|
|
self.tabWidget.setCurrentIndex(0) # 첫 번째 탭을 활성화
|
|
|
|
# 페이지 설정
|
|
profile = QWebEngineProfile.defaultProfile()
|
|
|
|
# webEngineView에는 모바일 에이전트 설정
|
|
self.webEngineView.setPage(CustomWebEnginePage(profile, self.webEngineView, use_mobile=True))
|
|
print("webEngineView 페이지 설정 완료")
|
|
# webEngineView_2에는 PC 에이전트 설정
|
|
self.webEngineView_2.setPage(CustomWebEnginePage(profile, self.webEngineView_2, use_mobile=False))
|
|
print("webEngineView_2 페이지 설정 완료")
|
|
|
|
# 스위치 UI 요소 (예: 버튼)에 이벤트 연결
|
|
#self.switchBtn.clicked.connect(self.toggleUserAgent)
|
|
|
|
default_url = "https://main.m.taobao.com"
|
|
default_url2 = "https://world.taobao.com/wow/tmg-fc/tmw/search_image?"
|
|
self.webEngineView.load(QUrl(default_url))
|
|
self.webEngineView_2.load(QUrl(default_url2))
|
|
|
|
# 기존DB불러오기 버튼 클릭이벤트
|
|
self.db_btn.clicked.connect(self.show_db_dialog)
|
|
|
|
# db를 엑셀로 저장 버튼
|
|
#self.export_btn.clicked.connect(self.export_data)
|
|
|
|
# 불러와진 DB에서 테이블을 읽어서 콤보박스에 표시하기
|
|
#self.comboBox.currentIndexChanged.connect(self.loadTable)
|
|
|
|
#self.loadTableNames()
|
|
|
|
# QGraphicsScene 초기화
|
|
self.scene = QGraphicsScene(self)
|
|
self.scene_current_img = QGraphicsScene(self)
|
|
|
|
#self.current_img
|
|
self.graphicsView_multi.setScene(self.scene)
|
|
# QGraphicsView의 정렬을 상단 및 좌측에 맞추기
|
|
self.graphicsView_multi.setAlignment(Qt.AlignTop)
|
|
# 새로운 QGraphicsView 및 QGraphicsScene 초기화
|
|
self.current_img.setScene(self.scene_current_img)
|
|
|
|
# searchbtn 버튼 클릭 이벤트 연결
|
|
#self.searchbtn_2.clicked.connect(self.search_chinese)
|
|
#self.search_keyword_box.returnPressed.connect(self.search_chinese)
|
|
|
|
# urlbox와 urlgobtn 이벤트 연결
|
|
#self.urlbox.returnPressed.connect(self.load_url_from_urlbox)
|
|
#self.urlgobtn.clicked.connect(self.load_url_from_urlbox)
|
|
|
|
# 타이머 설정
|
|
self.timer = QTimer(self)
|
|
#self.timer.timeout.connect(self.updateTimer)
|
|
|
|
# 시작, 정지, 설정 버튼
|
|
#self.timerStart.clicked.connect(self.startTimer)
|
|
#self.timerStop.clicked.connect(self.stopTimer)
|
|
# self.timerSet.clicked.connect(self.setTimer)
|
|
#self.startTimer()
|
|
|
|
# 타이머 시간
|
|
self.remainingTime = 3600 # 초 단위 (60분)
|
|
|
|
# 기존 QSpinBox 객체를 CustomSpinBox 객체로 변환
|
|
self.delivfee_spbox = self.findChild(QSpinBox, 'delivfee_spbox')
|
|
self.addpackingfee_spbox = self.findChild(QSpinBox, 'addpackingfee_spbox')
|
|
self.addmargin_spbox = self.findChild(QSpinBox, 'addmargin_spbox')
|
|
|
|
# QSpinBox 객체를 CustomSpinBox로 설정
|
|
#self.updateSpinBox(self.delivfee_spbox, 1000)
|
|
#self.updateSpinBox(self.addpackingfee_spbox, 1000)
|
|
#self.updateSpinBox(self.addmargin_spbox, 1000)
|
|
#기타 코드
|
|
|
|
def show_db_dialog(self):
|
|
# DB 목록 선택 Dialog 실행
|
|
self.db_dialog.exec_()
|
|
|
|
# 선택된 filename 값 처리
|
|
selected_filename = self.db_dialog.get_selected_filename()
|
|
if selected_filename:
|
|
print(f"선택된 DB : {selected_filename}")
|
|
# ...
|
|
|
|
|
|
|
|
def set_user_email(self, email):
|
|
# 로그인된 사용자 이메일 설정
|
|
self.loginUser.setText(f"로그인된 사용자: {email}")
|
|
self.currentUserEmail = email
|
|
|
|
# 로그인된 사용자 이메일로 DATABASE 설정
|
|
user_id = email.split('@')[0]
|
|
Listup_user_id = 'Listup_id_' + user_id
|
|
self.mydb = self.client[Listup_user_id]
|
|
|
|
|
|
def set_User_Info(self, userInfo):
|
|
self.loginUser.setText(f"로그인된 사용자: {self.currentUserEmail}")
|
|
self.loginUserInfo.setText(f"{userInfo}")
|
|
self.currentUserInfo = userInfo
|
|
print(self.currentUserInfo)
|
|
|
|
|
|
def closeEvent(self, event):
|
|
"""메인 윈도우가 닫힐 때 호출되는 이벤트 핸들러."""
|
|
if hasattr(self, 'login_widget'):
|
|
self.login_widget.logout(self.currentUserEmail) # 로그아웃 처리
|
|
super().closeEvent(event) # 기본 closeEvent 처리 호출
|
|
|
|
# 사용자에게 메시지 표시 등의 추가적인 처리를 할 수 있습니다.
|
|
print("메인 윈도우가 닫히고 있습니다.")
|
|
|
|
def main():
|
|
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts)
|
|
app = QtWidgets.QApplication(sys.argv)
|
|
mongo_config = MongoConfig() # MongoDB 설정 관리 인스턴스 생성
|
|
mongo_config.try_connect(*mongo_config.load_config()) # MongoDB에 연결 시도
|
|
# main_window = MainWindow(mongo_config) # 메인 윈도우 인스턴스 생성
|
|
|
|
login_widget = LoginWidget(mongo_config) # 로그인 위젯 생성, 메인 윈도우 인스턴스 전달
|
|
login_widget.show() # 로그인 위젯 표시
|
|
|
|
|
|
sys.exit(app.exec_())
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
app = QApplication(sys.argv)
|
|
|
|
|