-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypeSelector.py
More file actions
98 lines (74 loc) · 3.22 KB
/
Copy pathtypeSelector.py
File metadata and controls
98 lines (74 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import sys
import json
import constant
from PyQt6.QtWidgets import *
from PyQt6 import uic, QtCore
###############################################################
# UI파일 연결
# 단, UI파일은 Python 코드 파일과 같은 디렉토리에 위치해야한다.
def resource_path(relativePath):
# Get absolute path to resource, works for dev and for PyInstaller
basePath = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(basePath, relativePath)
form = resource_path("typeSelector.ui")
form_typeSelector = uic.loadUiType(form)[0]
###############################################################
global data
class typeSelector(QDialog, QWidget, form_typeSelector):
def __init__(self) :
super().__init__()
self.setupUi(self)
# 초기화
self.value = 0
# QPushButton 기능 연결
self.select.clicked.connect(self.confirm)
self.cancel.clicked.connect(self.exit)
# 두 번째 창 실행
self.show()
# 메인 창으로부터 메시지 수신
@QtCore.pyqtSlot(list)
def on_signal_from_main(self, value):
global data
# 왜 파이썬에는 switch문이 없지? (진짜 모름)
if value[0] == constant.BODY :
with open(constant.FILE_PATH_BODY, "r", encoding = "UTF-8") as file :
data = json.load(file)
elif value[0] == constant.WEAPON :
with open(constant.FILE_PATH_WEAPON, "r", encoding = "UTF-8") as file :
data = json.load(file)
self.comboBox_Type.clear()
self.comboBox_Parts.clear()
self.comboBox_Type.addItem("없음")
self.comboBox_Type.addItem("탑형")
self.comboBox_Type.addItem("팔형")
self.comboBox_Type.addItem("어깨형")
self.comboBox_Type.setCurrentIndex(data[value[1]]["Type"])
# 일치하는 형태의 부품만 QComboBox에 추가
for i in range(len(data)):
if data[i]["Type"] == self.comboBox_Type.currentIndex():
self.comboBox_Parts.addItem(data[i]["Name"])
# 현재 인덱스를 기존에 선택했던 부품으로 변경
for i in range(self.comboBox_Parts.count()):
if data[value[1]]["Name"] == self.comboBox_Parts.itemText(i):
self.comboBox_Parts.setCurrentIndex(i)
# QComboBox 기능 연결
self.comboBox_Type.currentIndexChanged.connect(self.onChangeType)
# 기존에 선택했던 부품 기록
self.value = value[1]
def onChangeType(self):
self.comboBox_Parts.clear()
global data
for i in range(len(data)):
if data[i]["Type"] == self.comboBox_Type.currentIndex():
self.comboBox_Parts.addItem(data[i]["Name"])
def confirm(self):
value = 0
for i in range(len(data)):
if data[i]["Name"] == self.comboBox_Parts.currentText():
value = i
# 원래 창에 값 전달
self.value = value
self.close()
def exit(self):
self.close()