1111from PySide6 .QtGui import *
1212from PySide6 .QtWidgets import *
1313
14+ from ...models import DistributedCallable
1415from ...network .client import Conversation
1516from ...network .client import Message
1617from ...utils import init_layouts
@@ -29,6 +30,7 @@ def __init__(self, conversation: Conversation | None = None, *args, **kwargs) ->
2930 super ().__init__ (* args , ** kwargs )
3031 self .conversation = conversation if conversation is not None else Conversation ()
3132
33+ self .is_waiting : bool = False
3234 self ._init_ui ()
3335
3436 def _init_ui (self ) -> None :
@@ -111,6 +113,10 @@ def toggle_multiline():
111113 self .output .setPlaceholderText (tr ('gui.output_text.placeholder' ))
112114
113115 app ().client .receivedMessage .connect (self .receive_message )
116+ app ().client .receivedError .connect (DistributedCallable ((
117+ lambda _ : setattr (self , 'is_waiting' , False ),
118+ lambda _ : self .send_button .setDisabled (False )
119+ )))
114120
115121 def append_to_view (self , text : str ) -> None :
116122 """Append some new text to the output.
@@ -128,13 +134,15 @@ def send_message(self) -> None:
128134
129135 Clears the input and disables after sending.
130136 """
131- message : str = self .input_line .text () or self .input_multi .toPlainText ()
132- self .input_line .clear ()
133- self .input_multi .clear ()
134- self .send_button .setDisabled (True )
135- self .append_to_view (tr ('gui.output_text.you_prompt' , message , key_eval = False )) # type: ignore
137+ if not self .is_waiting :
138+ message : str = self .input_line .text () or self .input_multi .toPlainText ()
139+ self .input_line .clear ()
140+ self .input_multi .clear ()
141+ self .is_waiting = True
142+ self .send_button .setDisabled (True )
143+ self .append_to_view (tr ('gui.output_text.you_prompt' , message , key_eval = False )) # type: ignore
136144
137- app ().client .send_message (message , self .conversation ) # type: ignore
145+ app ().client .send_message (message , self .conversation ) # type: ignore
138146
139147 def receive_message (self , message : Message , conversation : Conversation ) -> None :
140148 """Receive a response from the client.
@@ -143,5 +151,6 @@ def receive_message(self, message: Message, conversation: Conversation) -> None:
143151 :param conversation: Conversation received in.
144152 """
145153 if conversation is self .conversation :
154+ self .is_waiting = False
146155 self .send_button .setDisabled (False )
147156 self .append_to_view (tr ('gui.output_text.ai_prompt' , message .text , key_eval = False ))
0 commit comments