53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QHBoxLayout
|
|
import pyperclip
|
|
|
|
class ApiKeyWidget(QWidget):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setWindowTitle("API Keys")
|
|
self.setGeometry(100, 100, 400, 400)
|
|
|
|
self.layout = QVBoxLayout()
|
|
self.setLayout(self.layout)
|
|
|
|
# 초기화된 UI 구성 요소를 저장할 리스트
|
|
self.key_widgets = []
|
|
|
|
# 확인 버튼 추가 및 초기화
|
|
self.confirm_button = QPushButton("확인")
|
|
self.confirm_button.clicked.connect(self.close)
|
|
self.layout.addWidget(self.confirm_button)
|
|
|
|
def call_UI(self, api_keys):
|
|
# 기존 위젯 제거
|
|
self.clear_layout()
|
|
|
|
if api_keys:
|
|
for key, value in api_keys.items():
|
|
h_layout = QHBoxLayout()
|
|
|
|
key_label = QLabel(f"키 이름: {key}")
|
|
value_label = QLabel(f"키 값: {value}")
|
|
copy_button = QPushButton("키 복사")
|
|
|
|
copy_button.clicked.connect(lambda checked, v=value: self.copy_to_clipboard(v))
|
|
|
|
h_layout.addWidget(key_label)
|
|
h_layout.addWidget(value_label)
|
|
h_layout.addWidget(copy_button)
|
|
|
|
self.layout.insertLayout(self.layout.count() - 1, h_layout)
|
|
self.key_widgets.append((key_label, value_label, copy_button))
|
|
|
|
self.show()
|
|
|
|
def clear_layout(self):
|
|
for widgets in self.key_widgets:
|
|
for widget in widgets:
|
|
widget.deleteLater()
|
|
self.key_widgets.clear()
|
|
|
|
def copy_to_clipboard(self, value):
|
|
pyperclip.copy(value)
|
|
print(f"Copied to clipboard: {value}")
|