Skip to content

Commit 8f6232e

Browse files
committed
Improved new ctx to tab append
1 parent 3ffc4f7 commit 8f6232e

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/pygpt_net/controller/ui/tabs.py

100644100755
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(self, window=None):
2525
self.active_idx = 0
2626
self.prev_idx = 0
2727
self.initialized = False
28+
self.appended = False
2829
self.current = 0
2930

3031
def setup(self):
@@ -52,14 +53,9 @@ def append(self, type: int, idx: int):
5253
:param type: Tab type
5354
:param idx: Tab index
5455
"""
55-
meta = None
56+
self.appended = True # lock reload in previous tab
5657
self.window.core.tabs.append(type, idx)
57-
if type == Tab.TAB_CHAT:
58-
meta = self.window.controller.ctx.new() # new context
5958
self.switch_tab_by_idx(idx + 1) # switch to new tab
60-
if type == Tab.TAB_CHAT:
61-
if meta is not None:
62-
self.window.controller.ctx.load(meta.id) # reload
6359

6460
def reload_titles(self):
6561
"""Reload tab titles"""
@@ -77,7 +73,6 @@ def reload_after(self):
7773
self.switch_tab(Tab.TAB_CHAT)
7874
self.window.controller.ctx.load_first()
7975

80-
8176
def on_tab_changed(self, idx: int):
8277
"""
8378
Output tab changed
@@ -86,8 +81,16 @@ def on_tab_changed(self, idx: int):
8681
"""
8782
tab = self.window.core.tabs.get_tab_by_index(idx)
8883
if tab is None:
84+
self.appended = False
8985
return
9086

87+
if self.appended:
88+
self.appended = False
89+
if tab.type == Tab.TAB_CHAT:
90+
meta = self.window.controller.ctx.new() # new context
91+
if meta is not None:
92+
self.window.controller.ctx.load(meta.id) # reload
93+
9194
prev_tab = self.current
9295
self.current = idx
9396
self.window.controller.ui.mode.update()
@@ -96,23 +99,15 @@ def on_tab_changed(self, idx: int):
9699
# check type
97100
if tab.type == Tab.TAB_NOTEPAD:
98101
self.window.controller.notepad.opened_once = True
99-
if tab.type == Tab.TAB_CHAT:
100-
ctx_meta = self.window.core.ctx.current
102+
elif tab.type == Tab.TAB_CHAT:
101103
pid_meta = self.window.core.ctx.output.get_meta(tab.pid)
102-
if ctx_meta != pid_meta and pid_meta is not None:
103-
if self.get_type_by_idx(prev_tab) == Tab.TAB_CHAT:
104-
self.window.controller.ctx.load(pid_meta) # only if switching between chat tabs
105-
else:
106-
curr_pid = tab.pid
107-
meta = self.window.core.ctx.get_meta_by_id(ctx_meta)
108-
if meta is not None:
109-
render_pid = self.window.controller.chat.render.get_pid(meta) # get PID from renderer
110-
self.window.controller.ctx.load(pid_meta) # reload renderer
111-
112-
# self.window.controller.notepad.opened_once = True
104+
meta = self.window.core.ctx.get_meta_by_id(pid_meta)
105+
if meta is not None:
106+
self.window.controller.ctx.load(pid_meta) # reload renderer
113107
elif tab.type == Tab.TAB_TOOL_DRAW:
114108
if self.window.core.config.get('vision.capture.enabled'):
115109
self.window.controller.camera.enable_capture()
110+
116111
if prev_tab != idx:
117112
self.window.core.dispatcher.dispatch(AppEvent(AppEvent.TAB_SELECTED)) # app event
118113

@@ -256,6 +251,14 @@ def get_current_tab_name(self) -> str:
256251
"""
257252
return self.window.ui.tabs['output'].tabText(self.current)
258253

254+
def update_tooltip(self, tooltip: str):
255+
"""
256+
Update tab tooltip
257+
258+
:param tooltip: tooltip
259+
"""
260+
self.window.ui.tabs['output'].setTabToolTip(self.current, tooltip)
261+
259262
def rename(self, idx: int):
260263
"""
261264
Rename tab

0 commit comments

Comments
 (0)