Skip to content

Commit b818a75

Browse files
committed
Add load complete QMessageBox
Add load complete QMessageBox
1 parent ac020e5 commit b818a75

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

je_editor/pyside_ui/dialog/ai_dialog/set_ai_dialog.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from PySide6.QtWidgets import QWidget, QBoxLayout, QLineEdit, QHBoxLayout, QPushButton, QMessageBox
1+
from PySide6.QtWidgets import QWidget, QBoxLayout, QLineEdit, QHBoxLayout, QPushButton, QMessageBox, QGridLayout, QLabel
22

33
from je_editor.pyside_ui.main_ui.ai_widget.ai_config import ai_config
44
from je_editor.utils.logging.loggin_instance import jeditor_logger
@@ -10,21 +10,25 @@ class SetAIDialog(QWidget):
1010
def __init__(self):
1111
jeditor_logger.info("Init SetAIDialog")
1212
super().__init__()
13-
self.box_layout = QBoxLayout(QBoxLayout.Direction.TopToBottom)
13+
self.base_url_label = QLabel(language_wrapper.language_word_dict.get("base_url_label"))
1414
self.base_url_input = QLineEdit()
15+
self.api_key_label = QLabel(language_wrapper.language_word_dict.get("api_key_label"))
1516
self.api_key_input = QLineEdit()
17+
self.chat_model_label = QLabel(language_wrapper.language_word_dict.get("ai_model_label"))
1618
self.chat_model_input = QLineEdit()
1719
self.add_ai_info_button = QPushButton()
1820
self.add_ai_info_button.setText(language_wrapper.language_word_dict.get("add_ai_model_pushbutton"))
1921
self.add_ai_info_button.clicked.connect(self.update_ai_config)
20-
self.box_h_layout = QHBoxLayout()
21-
self.box_h_layout.addWidget(self.add_ai_info_button)
22-
self.box_layout.addWidget(self.base_url_input)
23-
self.box_layout.addWidget(self.api_key_input)
24-
self.box_layout.addWidget(self.chat_model_input)
25-
self.box_layout.addLayout(self.box_h_layout)
22+
self.grid_layout = QGridLayout()
23+
self.grid_layout.addWidget(self.base_url_label, 0, 0)
24+
self.grid_layout.addWidget(self.base_url_input, 0, 1)
25+
self.grid_layout.addWidget(self.api_key_label, 1, 0)
26+
self.grid_layout.addWidget(self.api_key_input, 1, 1)
27+
self.grid_layout.addWidget(self.chat_model_label, 2, 0)
28+
self.grid_layout.addWidget(self.chat_model_input, 2, 1)
29+
self.grid_layout.addWidget(self.add_ai_info_button, 3, 1)
2630
self.setWindowTitle(language_wrapper.language_word_dict.get("add_ai_model_title"))
27-
self.setLayout(self.box_layout)
31+
self.setLayout(self.grid_layout)
2832

2933
def update_ai_config(self):
3034
base_url = self.base_url_input.text().strip()

je_editor/pyside_ui/main_ui/ai_widget/chat_ui.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
from je_editor.pyside_ui.main_ui.main_editor import EditorMain
2020

2121

22-
def set_ai_config():
23-
# Set and output AI a config file
24-
set_ai_config_dialog = SetAIDialog()
25-
set_ai_config_dialog.show()
26-
27-
2822
class ChatUI(QWidget):
2923

3024
def __init__(self, main_window: EditorMain):
@@ -53,9 +47,9 @@ def __init__(self, main_window: EditorMain):
5347
self.font_size_combobox.currentTextChanged.connect(self.update_panel_text_size)
5448
# Buttons
5549
self.set_ai_config_button = QPushButton(language_wrapper.language_word_dict.get("chat_ui_set_ai_button"))
56-
self.set_ai_config_button.clicked.connect(set_ai_config)
50+
self.set_ai_config_button.clicked.connect(self.set_ai_config)
5751
self.load_ai_config_button = QPushButton(language_wrapper.language_word_dict.get("chat_ui_load_ai_button"))
58-
self.load_ai_config_button.clicked.connect(self.load_ai_config)
52+
self.load_ai_config_button.clicked.connect(lambda: self.load_ai_config(show_load_complete=True))
5953
self.call_ai_model_button = QPushButton(language_wrapper.language_word_dict.get("chat_ui_call_ai_model_button"))
6054
self.call_ai_model_button.clicked.connect(self.call_ai_model)
6155
# Add to layout
@@ -70,6 +64,8 @@ def __init__(self, main_window: EditorMain):
7064
# Variable
7165
self.ai_config: AIConfig = ai_config
7266
self.lang_chain_interface: Union[LangChainInterface, None] = None
67+
self.set_ai_config_dialog = None
68+
# Timer to pop queue
7369
self.pull_message_timer = QTimer(self)
7470
self.pull_message_timer.setInterval(1000)
7571
self.pull_message_timer.timeout.connect(self.pull_message)
@@ -84,7 +80,7 @@ def update_panel_text_size(self):
8480
self.chat_panel.setFont(
8581
QFontDatabase.font(self.font().family(), "", int(self.font_size_combobox.currentText())))
8682

87-
def load_ai_config(self):
83+
def load_ai_config(self, show_load_complete: bool = False):
8884
ai_config_file = Path(str(Path.cwd()) + "/" + ".jeditor/ai_config.json")
8985
if ai_config_file.exists():
9086
with open(ai_config_file, "r", encoding="utf-8"):
@@ -101,6 +97,12 @@ def load_ai_config(self):
10197
chat_model=ai_info.get("chat_model"),
10298
prompt_template=ai_info.get("prompt_template"),
10399
)
100+
if show_load_complete:
101+
load_complete = QMessageBox(self)
102+
load_complete.setWindowTitle(language_wrapper.language_word_dict.get("load_ai_messagebox_title"))
103+
load_complete.setText(language_wrapper.language_word_dict.get("load_ai_messagebox_text"))
104+
load_complete.exec()
105+
104106

105107
def call_ai_model(self):
106108
if isinstance(self.lang_chain_interface, LangChainInterface):
@@ -121,3 +123,8 @@ def pull_message(self):
121123
ai_response = ai_config.message_queue.get_nowait()
122124
self.chat_panel.appendPlainText(ai_response)
123125
self.chat_panel.appendPlainText("\n")
126+
127+
def set_ai_config(self):
128+
# Set and output AI a config file
129+
self.set_ai_config_dialog = SetAIDialog()
130+
self.set_ai_config_dialog.show()

je_editor/utils/multi_language/english.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,9 @@
136136
"chat_ui_set_ai_button": "Set AI setting",
137137
"chat_ui_load_ai_button": "Load AI setting",
138138
"chat_ui_call_ai_model_button": "Send prompt",
139+
"base_url_label": "AI server URL",
140+
"api_key_label": "AI server API Key",
141+
"ai_model_label": "AI Model",
142+
"load_ai_messagebox_title": "Load complete",
143+
"load_ai_messagebox_text": "Load complete",
139144
}

je_editor/utils/multi_language/traditional_chinese.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,9 @@
134134
"chat_ui_set_ai_button": "設定 AI 設定",
135135
"chat_ui_load_ai_button": "載入 AI 設定",
136136
"chat_ui_call_ai_model_button": "傳送 prompt",
137+
"base_url_label":"AI 伺服器 URL",
138+
"api_key_label": "AI 伺服器 API Key",
139+
"ai_model_label": "AI Model",
140+
"load_ai_messagebox_title": "載入成功",
141+
"load_ai_messagebox_text": "載入成功",
137142
}

0 commit comments

Comments
 (0)