44import webbrowser
55import tempfile
66import os
7+ # from code_editor_ui import update_preview
78from core .ai_engine import generate_code_from_prompt , ai_status
89from exporters .exporter import export_code
910from core import prompt_history
@@ -703,19 +704,26 @@ def start_update(self, prompt):
703704 def update_in_background ():
704705 try :
705706 api_key = self .get_api_key ()
706- model_source = self .get_model_source ()
707- code = generate_code_from_prompt (prompt , api_key , model_source )
707+ code = generate_code_from_prompt (prompt , api_key )
708708 prompt_history .push_code (code )
709709 prompt_history .push_prompt (
710- "Describe what you'd like to change...\n \n Example: Make the header purple, add a contact form, or change the font to something more modern" )
710+ "Describe what you'd like to change...\n \n Example: Make the header purple, add a contact form, or change the font to something more modern"
711+ )
711712 prompt_history .push_code (code )
712- self .set_code (code )
713+
714+ # This must be done in the main thread
715+ self .after (0 , lambda : self .set_code (code ))
716+
717+ from code_editor_ui import update_preview
713718 update_preview (code )
714719
715- self .after (0 , lambda : self .update_complete () )
720+ self .after (0 , self .update_complete )
716721
722+ # except Exception as e:
723+ # self.after(0, lambda: self.update_error(str(e)))
717724 except Exception as e :
718- self .after (0 , lambda exc = e : self .update_error (str (exc )))
725+ error_message = str (e )
726+ self .after (0 , lambda : self .update_error (error_message ))
719727
720728 threading .Thread (target = update_in_background , daemon = True ).start ()
721729
@@ -727,7 +735,6 @@ def update_complete(self):
727735 state = 'normal' ,
728736 bg = '#1f6feb'
729737 )
730-
731738 self .update_status ("Changes applied successfully!" , "✅" )
732739 self .preview_status .configure (text = "● Live" , fg = '#3fb950' )
733740
@@ -757,12 +764,13 @@ def update_error(self, error_msg):
757764 state = 'normal' ,
758765 bg = '#1f6feb'
759766 )
760-
761767 self .update_status ("Update failed" , "❌" )
762768 self .preview_status .configure (text = "● Error" , fg = '#f85149' )
763-
769+
764770 status = ai_status .get ("state" , "unknown" )
765771 message = ai_status .get ("message" , "" )
772+ # print(f"status is :{status}, msg: {message}")
773+
766774 if status == "offline" :
767775 self .show_error (
768776 "AI service is currently unavailable. Please check your internet connection or try again later." )
0 commit comments