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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
try:
    from .agent.chat_history import *
    from .agent.assistant import *
    from .llm import *
    from .llm_settings import llm_settings
    from .agent.agent import *
    from .agent.background import *

    from .gui.signal import *
    from .gui.button import *
    from .gui.settings import settings_popup
    from .gui.llmsettings import llmsettings_popup
    from .utils.db import *
    from .utils.telemetry import my_tracer, os_name

    from .audio.wake_word import wake_word
    from .audio.tts import text_to_speech
    from .character import name, developer

except ImportError:
    # This is for running the script directly
    # in order to test the GUI without rebuilding the package
    from agent.chat_history import *
    from agent.assistant import *
    from llm import *
    from llm_settings import llm_settings
    from agent.agent import *
    from agent.background import *
    from utils.db import *
    from gui.signal import *
    from gui.button import *
    from gui.settings import settings_popup
    from gui.llmsettings import llmsettings_popup
    from utils.telemetry import my_tracer, os_name
    from audio.wake_word import wake_word
    from audio.tts import text_to_speech
import platform
import threading
import time
import random
import math

from PyQt5.QtWidgets import QMainWindow, QVBoxLayout, QWidget
from PyQt5.QtGui import QMouseEvent, QPainter, QPen, QBrush, QIcon, QColor
from PyQt5.QtCore import Qt, QTimer, QRect, pyqtSignal
from PyQt5.QtGui import QKeySequence
from PyQt5.QtWidgets import QShortcut
from PyQt5.QtWidgets import QSpacerItem, QSizePolicy
from PyQt5.QtWidgets import QDesktopWidget


from PyQt5.QtWidgets import (
    QPushButton,
    QLabel,
    QHBoxLayout,
)
from PyQt5.QtCore import QPoint

from PyQt5.QtWidgets import QTextEdit
from PyQt5 import QtGui
from PyQt5.QtCore import QThread
import pygame


print("Imported all libraries")


from PyQt5 import QtCore


try:
    import ctypes

    myappid = "khulnasoft.gpt_computer_agent.gui.1"
    ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
except:
    pass

the_input_box = None
the_input_text = None


the_input_box_pre = None


the_main_window = None


user_id = load_user_id()
os_name_ = os_name()


from PyQt5.QtCore import QRegExp
from PyQt5.QtGui import QSyntaxHighlighter, QTextCharFormat, QFont


class PythonSyntaxHighlighter(QSyntaxHighlighter):
    def __init__(self, parent):
        super().__init__(parent)
        self.highlighting_rules = []

        # Define different text formats with appropriate colors
        keyword_format = QTextCharFormat()
        keyword_format.setForeground(QColor(127, 0, 85))  # Dark purple for keywords

        built_in_formats = QTextCharFormat()
        built_in_formats.setForeground(
            QColor(42, 0, 255)
        )  # Dark blue for built-ins and constants

        string_format = QTextCharFormat()
        string_format.setForeground(QColor(0, 128, 0))  # Green for strings

        function_format = QTextCharFormat()
        function_format.setForeground(QColor(0, 0, 255))  # Blue for function names

        comment_format = QTextCharFormat()
        comment_format.setForeground(QColor(128, 128, 128))  # Gray for comments
        comment_format.setFontItalic(True)

        number_format = QTextCharFormat()
        number_format.setForeground(QColor(255, 0, 0))  # Red for numbers

        decorator_format = QTextCharFormat()
        decorator_format.setForeground(QColor(0, 0, 128))  # Navy blue for decorators

        # Markdown formatting
        header_format = QTextCharFormat()
        header_format.setForeground(QColor(0, 128, 128))  # Teal for headers
        header_format.setFontWeight(QFont.Bold)

        bold_format = QTextCharFormat()
        bold_format.setFontWeight(QFont.Bold)

        italic_format = QTextCharFormat()
        italic_format.setFontItalic(True)

        code_format = QTextCharFormat()
        code_format.setForeground(QColor(255, 140, 0))  # Dark orange for inline code
        code_format.setFontFamily("Courier New")
        code_format.setBackground(
            QColor(245, 245, 245)
        )  # Light gray background for inline code

        block_code_format = QTextCharFormat()
        block_code_format.setForeground(
            QColor(255, 140, 0)
        )  # Dark orange for code blocks
        block_code_format.setFontFamily("Courier New")
        block_code_format.setBackground(
            QColor(245, 245, 245)
        )  # Light gray background for code blocks

        # Define the regular expressions
        keywords = [
            "def",
            "class",
            "if",
            "else",
            "elif",
            "return",
            "import",
            "from",
            "as",
            "for",
            "while",
            "try",
            "except",
            "finally",
            "with",
            "async",
            "await",
            "yield",
            "lambda",
            "global",
            "nonlocal",
            "assert",
            "del",
            "pass",
            "break",
            "continue",
            "and",
            "or",
            "not",
            "is",
            "in",
        ]
        self.highlighting_rules += [
            (QRegExp(r"\b" + word + r"\b"), keyword_format) for word in keywords
        ]

        built_ins = [
            "True",
            "False",
            "None",
            "__init__",
            "self",
            "print",
            "len",
            "range",
            "str",
            "int",
            "float",
            "list",
            "dict",
            "set",
            "tuple",
        ]
        self.highlighting_rules += [
            (QRegExp(r"\b" + word + r"\b"), built_in_formats) for word in built_ins
        ]

        self.highlighting_rules.append(
            (QRegExp(r'"[^"\\]*(\\.[^"\\]*)*"'), string_format)
        )
        self.highlighting_rules.append(
            (QRegExp(r"'[^'\\]*(\\.[^'\\]*)*'"), string_format)
        )

        self.highlighting_rules.append((QRegExp(r"\bdef\b\s*(\w+)"), function_format))
        self.highlighting_rules.append((QRegExp(r"\bclass\b\s*(\w+)"), function_format))

        self.highlighting_rules.append((QRegExp(r"#.*"), comment_format))

        self.highlighting_rules.append((QRegExp(r"\b[0-9]+[lL]?\b"), number_format))
        self.highlighting_rules.append(
            (QRegExp(r"\b0[xX][0-9A-Fa-f]+[lL]?\b"), number_format)
        )
        self.highlighting_rules.append(
            (QRegExp(r"\b0[oO]?[0-7]+[lL]?\b"), number_format)
        )
        self.highlighting_rules.append((QRegExp(r"\b0[bB][01]+[lL]?\b"), number_format))

        self.highlighting_rules.append((QRegExp(r"@[^\s]+"), decorator_format))

        # Markdown rules
        self.highlighting_rules.append(
            (QRegExp(r"^#{1,6} .+"), header_format)
        )  # Headers
        self.highlighting_rules.append(
            (QRegExp(r"\*\*[^*]+\*\*"), bold_format)
        )  # **bold**
        self.highlighting_rules.append((QRegExp(r"__[^_]+__"), bold_format))  # __bold__
        self.highlighting_rules.append(
            (QRegExp(r"\*[^*]+\*"), italic_format)
        )  # *italic*
        self.highlighting_rules.append((QRegExp(r"_[^_]+_"), italic_format))  # _italic_
        self.highlighting_rules.append(
            (QRegExp(r"`[^`]+`"), code_format)
        )  # Inline code

    def highlightBlock(self, text):
        # Handle code blocks separately
        if text.strip().startswith("```"):
            self.setFormat(0, len(text), self.highlighting_rules[-1][1])
            return

        for pattern, format in self.highlighting_rules:
            expression = QRegExp(pattern)
            index = expression.indexIn(text)
            while index >= 0:
                length = expression.matchedLength()
                self.setFormat(index, length, format)
                index = expression.indexIn(text, index + length)


readed_sentences = []

import re


def split_with_multiple_delimiters(text, delimiters):
    """
    Splits the text by any of the given delimiters while keeping the delimiters in the resulting parts.

    :param text: The input text to be split.
    :param delimiters: A string of delimiters to split the text on.
    :return: A list of parts including the delimiters.
    """
    # Create a regular expression pattern that matches any of the delimiters
    pattern = re.compile(f"(.*?[{re.escape(delimiters)}])")
    parts = pattern.findall(text)

    # Check if the last part is not complete and remove it if necessary
    if (
        parts
        and text
        and not any(text.endswith(d) for d in delimiters)
        and parts
        and not any(parts[-1].endswith(d) for d in delimiters)
    ):
        parts.pop()

    return parts


def click_sound():
    pygame.mixer.init()

    retro = pygame.mixer.Sound(click_sound_path)
    retro.set_volume(0.1)
    retro.play()


class Worker(QThread):
    text_to_set = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.the_input_text = None
        self.make_animation = True
        self.commited_text = []

    def run(self):
        while True:
            self.msleep(500)  # Simulate a time-consuming task

            if self.the_input_text:
                last_text = (
                    self.commited_text[-1] if len(self.commited_text) > 0 else ""
                )
                if self.the_input_text != last_text:
                    self.commited_text.append(self.the_input_text)

                    if len(self.the_input_text) > 90 or not self.make_animation:
                        self.text_to_set.emit(self.the_input_text)
                    else:
                        for i in range(len(self.the_input_text)):
                            self.text_to_set.emit(self.the_input_text[: i + 1])
                            self.msleep(10)


return_key_event = None


class CustomTextEdit(QTextEdit):
    def __init__(self, parent=None):
        super(CustomTextEdit, self).__init__(parent)

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter:
            global return_key_event
            return_key_event()
        super(CustomTextEdit, self).keyPressEvent(
            event
        )  # Process other key events normally


class Worker_2(QThread):
    text_to_set = pyqtSignal(str)
    text_to_set_title_bar = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.the_input_text = None
        self.title_bar_text = None
        self.prev = None
        self.commited_text = []

    def run(self):
        while True:
            self.msleep(500)  # Simulate a time-consuming task

            if self.the_input_text and (
                self.prev is None or self.prev != self.the_input_text
            ):
                self.prev = self.the_input_text
                self.text_to_set.emit("True")
                for i in range(len(self.title_bar_text)):
                    self.text_to_set_title_bar.emit(self.title_bar_text[: i + 1])
                    self.msleep(10)

            if not self.the_input_text and self.prev != self.the_input_text:
                self.prev = self.the_input_text
                self.text_to_set.emit("False")

                the_text = "  " + name()

                for i in range(len(the_text)):
                    self.text_to_set_title_bar.emit(the_text[: i + 1])
                    self.msleep(10)


class Worker_3(QThread):
    text_to_set = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.the_input_text = None

    def run(self):
        while True:
            self.msleep(500)  # Simulate a time-consuming task

            if self.the_input_text:
                self.text_to_set.emit("True")
                self.the_input_text = None


class Worker_collapse(QThread):
    text_to_set = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.the_input_text = None

    def run(self):
        while True:
            self.msleep(500)  # Simulate a time-consuming task

            if self.the_input_text:
                self.text_to_set.emit("True")
                self.the_input_text = None


class Worker_uncollapse(QThread):
    text_to_set = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.the_input_text = None

    def run(self):
        while True:
            self.msleep(500)  # Simulate a time-consuming task

            if self.the_input_text:
                self.text_to_set.emit("True")
                self.the_input_text = None


class Worker_show_logo(QThread):
    text_to_set = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.the_input_text = None

    def run(self):
        while True:
            self.msleep(500)  # Simulate a time-consuming task

            if self.the_input_text:
                self.text_to_set.emit("True")
                self.the_input_text = None


class Worker_hide_logo(QThread):
    text_to_set = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.the_input_text = None

    def run(self):
        while True:
            self.msleep(500)  # Simulate a time-consuming task

            if self.the_input_text:
                self.text_to_set.emit("True")
                self.the_input_text = None


class Worker_activate_long_gca(QThread):
    text_to_set = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.the_input_text = None

    def run(self):
        while True:
            self.msleep(500)  # Simulate a time-consuming task

            if self.the_input_text:
                self.text_to_set.emit("True")
                self.the_input_text = None


class Worker_deactivate_long_gca(QThread):
    text_to_set = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.the_input_text = None

    def run(self):
        while True:
            self.msleep(500)  # Simulate a time-consuming task

            if self.the_input_text:
                self.text_to_set.emit("True")
                self.the_input_text = None


class Worker_tray_and_task_bar_logo(QThread):
    text_to_set = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.the_input_text = None

    def run(self):
        while True:
            self.msleep(500)  # Simulate a time-consuming task

            if self.the_input_text:
                self.text_to_set.emit("True")
                self.the_input_text = None


class DrawingWidget(QWidget):
    def __init__(self, parent=None):
        super(DrawingWidget, self).__init__(parent)
        # Set widget properties if needed, e.g., size

        self.main_ = parent
        self.active_button = ""

    def paintEvent(self, event):
        if llm_settings[load_model_settings()]["vision"] is True:
            self.main_.screen_available = True
        else:
            self.main_.screen_available = False

        self.main_.setAutoFillBackground(True)
        painter = QPainter(self)
        painter = painter

        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(QPen(QColor("#000"), 1))
        painter.setBrush(QBrush(Qt.black, Qt.SolidPattern))

        center_x = 95
        center_y = 40

        if "talking" in self.main_.state:
            # Draw a pulsating circle with smooth easing animation
            radius_variation = 5 * (
                1 + math.sin(self.main_.pulse_frame * math.pi / 100)
            )
            radius = 70 + radius_variation
            painter.drawEllipse(
                int(center_x - radius / 2),
                int(center_y - radius / 2),
                int(radius),
                int(radius),
            )
        elif self.main_.state == "thinking":
            # more slow pulsating circle with smooth easing animation
            radius_variation = 5 * (
                1 + math.sin(self.main_.pulse_frame * math.pi / 100)
            )
            radius = 70 + radius_variation
            painter.drawEllipse(
                int(center_x - radius / 2),
                int(center_y - radius / 2),
                int(radius),
                int(radius),
            )

        else:
            radius = 70
            if self.main_.screen_available:
                painter.drawEllipse(  # Main Button
                    int(center_x - radius / 2),
                    int(center_y - radius / 2),
                    int(radius),
                    int(radius),
                )

        self.main_.circle_rect = QRect(
            int(center_x - radius / 2),
            int(center_y - radius / 2),
            int(radius),
            int(radius),
        )

        if not self.main_.state == "thinking":
            painter.setPen(QPen(QColor("#01EE8A"), 1))
            if self.main_.screen_available:
                painter.drawEllipse(  # Main BUtton Green Border
                    int(center_x - radius / 2),
                    int(center_y - radius / 2),
                    int(radius),
                    int(radius),
                )
        else:
            painter.setPen(QPen(QColor("#23538F"), 1))

            painter.drawEllipse(
                int(center_x - radius / 2),
                int(center_y - radius / 2),
                int(radius),
                int(radius),
            )

        painter.setPen(QPen(QColor("#000"), 1))

        small_center_x = 165
        small_center_y = 25
        small_radius = 30

        painter.drawEllipse(  # Microphone bacground black
            int(small_center_x - small_radius / 2),
            int(small_center_y - small_radius / 2),
            int(small_radius),
            int(small_radius),
        )

        self.main_.small_circle_rect = QRect(
            int(small_center_x - small_radius / 2),
            int(small_center_y - small_radius / 2),
            int(small_radius),
            int(small_radius),
        )

        # Draw the icon inside the circle
        icon_size = small_radius * 2 // 3  # Adjust the icon size relative to the circle
        icon_rect = QRect(
            small_center_x - icon_size // 2,
            small_center_y - icon_size // 2,
            icon_size,
            icon_size,
        )
        self.main_.small_circle_recticon = QIcon(microphone_icon_path)
        self.main_.small_circle_recticon.paint(painter, icon_rect)

        small_center_x = 30
        small_center_y = 60
        small_radius = 30
        painter.drawEllipse(
            int(small_center_x - small_radius / 2),
            int(small_center_y - small_radius / 2),
            int(small_radius),
            int(small_radius),
        )

        self.main_.small_circle_left = QRect(
            int(small_center_x - small_radius / 2),
            int(small_center_y - small_radius / 2),
            int(small_radius),
            int(small_radius),
        )

        # Draw the icon inside the circle
        icon_size = small_radius * 2 // 3  # Adjust the icon size relative to the circle
        icon_rect = QRect(
            small_center_x - icon_size // 2,
            small_center_y - icon_size // 2,
            icon_size,
            icon_size,
        )
        self.main_.small_circle_lefticon = QIcon(audio_icon_path)
        self.main_.small_circle_lefticon.paint(painter, icon_rect)

        small_center_x = 30
        small_center_y = 25
        small_radius = 30
        if self.main_.screen_available:
            painter.drawEllipse(  # ScreenShot BUtton
                int(small_center_x - small_radius / 2),
                int(small_center_y - small_radius / 2),
                int(small_radius),
                int(small_radius),
            )

        self.main_.small_circle_left_top = QRect(
            int(small_center_x - small_radius / 2),
            int(small_center_y - small_radius / 2),
            int(small_radius),
            int(small_radius),
        )

        self.main_.screenshot_button_coordinates_size = [
            int(small_center_x - small_radius / 2),
            int(small_center_y - small_radius / 2),
            int(small_radius),
            int(small_radius),
        ]

        if self.active_button == "screenshot":
            self.screenshot_button_border_activate(painter)
            self.active_button = ""

        if self.main_.screen_available:
            # Draw the icon inside the circle
            icon_size = (
                small_radius * 2 // 3
            )  # Adjust the icon size relative to the circle
            icon_rect = QRect(
                small_center_x - icon_size // 2,
                small_center_y - icon_size // 2,
                icon_size,
                icon_size,
            )
            self.main_.small_circle_left_topticon = QIcon(screenshot_icon_path)
            self.main_.small_circle_left_topticon.paint(painter, icon_rect)

        small_center_x = 165
        small_center_y = 60
        small_radius = 30
        painter.drawEllipse(
            int(small_center_x - small_radius / 2),
            int(small_center_y - small_radius / 2),
            int(small_radius),
            int(small_radius),
        )

        self.main_.small_circle_collapse = QRect(
            int(small_center_x - small_radius / 2),
            int(small_center_y - small_radius / 2),
            int(small_radius),
            int(small_radius),
        )

        # Draw the icon inside the circle
        icon_size = small_radius * 2 // 3  # Adjust the icon size relative to the circle
        icon_rect = QRect(
            small_center_x - icon_size // 2,
            small_center_y - icon_size // 2,
            icon_size,
            icon_size,
        )

        if is_collapse_setting_active():
            self.main_.small_circle_collapse_icon = QIcon(down_icon_path)

        if not is_collapse_setting_active() and is_long_gca_setting_active():
            self.main_.small_circle_collapse_icon = QIcon(up_icon_path)

        if not is_collapse_setting_active() and not is_long_gca_setting_active():
            self.main_.small_circle_collapse_icon = QIcon(down_icon_path)

        self.main_.small_circle_collapse_icon.paint(painter, icon_rect)

    def screenshot_button_border_activate(self, painter):
        # Add an white border to the circle
        painter.setPen(QPen(QColor("#FFF"), 1))
        # Draw the ellipse with the specified green border
        self.main_.screenshot_button_border = painter.drawEllipse(
            self.main_.screenshot_button_coordinates_size[0],
            self.main_.screenshot_button_coordinates_size[1],
            self.main_.screenshot_button_coordinates_size[2],
            self.main_.screenshot_button_coordinates_size[3],
        )
        painter.setPen(QPen(QColor("#000"), 1))

    def mousePressEvent(self, event: QMouseEvent):
        self.main_.old_position = event.globalPos()

        with my_tracer.start_span("mouse_press_event") as span:
            span.set_attribute("user_id", user_id)
            span.set_attribute("os_name", os_name_)
            if self.main_.state == "idle" or "talking" in self.main_.state:
                try:
                    if self.main_.circle_rect.contains(event.pos()):
                        if self.main_.state == "aitalking":
                            self.main_.stop_ai_talking()

                        else:
                            self.main_.screenshot_and_microphone_button_action()
                except:
                    traceback.print_exc()

                try:
                    if self.main_.small_circle_rect.contains(event.pos()):
                        if self.main_.state == "aitalking":
                            self.main_.stop_ai_talking()

                        else:
                            click_sound()
                            self.main_.button_handler.toggle_recording(
                                no_screenshot=True
                            )
                except:
                    traceback.print_exc()

                try:
                    if self.main_.small_circle_left.contains(event.pos()):
                        if self.main_.state == "aitalking":
                            self.main_.stop_ai_talking()

                        else:
                            click_sound()
                            self.main_.button_handler.toggle_recording(
                                take_system_audio=True
                            )
                except:
                    traceback.print_exc()

                try:
                    if self.main_.small_circle_left_top.contains(event.pos()):
                        if self.main_.state == "aitalking":
                            self.main_.stop_ai_talking()

                        else:
                            click_sound()
                            self.active_button = "screenshot"
                            self.update()
                            self.main_.button_handler.just_screenshot()
                except:
                    traceback.print_exc()

            try:
                if self.main_.small_circle_collapse.contains(event.pos()):
                    if not is_collapse_setting_active():
                        if is_long_gca_setting_active():
                            self.main_.deactivate_long_gca()
                            self.main_.collapse_gca()
                        else:
                            self.main_.activate_long_gca()

                    else:
                        self.main_.uncollapse_gca()

                    self.main_.update()
            except:
                pass


from PyQt5.QtCore import QVariantAnimation


class MainWindow(QMainWindow):
    api_enabled = False
    tts_available = True

    def screenshot_and_microphone_button_action(self):
        click_sound()
        if llm_settings[load_model_settings()]["vision"] is True:
            self.button_handler.toggle_recording(dont_save_image=True)
        else:
            self.button_handler.toggle_recording(no_screenshot=True)

    def stop_ai_talking(self):
        self.manuel_stop = True
        self.stop_talking = True

    def __init__(self):
        super().__init__()

        self.background_color = "45, 45, 45"
        self.opacity = 250
        self.border_radius = 10

        print("API Enabled:", MainWindow.api_enabled)
        if MainWindow.api_enabled:
            try:
                from .api import start_api

                start_api()
            except:
                raise Exception(
                    "API could not be started, please install gpt-computer-agent[api]"
                )
        self.stop_talking = False
        self.setWindowFlags(
            Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
        )  # Remove the default title bar

        # Load the San Francisco font
        print("Loading font")
        print(font_dir)
        try:
            font_id = QtGui.QFontDatabase.addApplicationFont(font_dir)

            font_family = QtGui.QFontDatabase.applicationFontFamilies(font_id)[0]
            self.setFont(QtGui.QFont(font_family))
        except:
            print("Error loading font")

        self.state = "idle"
        self.pulse_timer = None

        self.button_handler = ButtonHandler(self)
        self.initUI()
        self.old_position = self.pos()

        self.collapse = is_collapse_setting_active()
        if self.collapse:
            self.collapse_window()

        global the_main_window
        the_main_window = self

        self.general_styling()

        if is_dark_mode_active():
            self.dark_mode()
        else:
            self.light_mode()

        self.wake_word_thread = None

        self.wake_word_active = False

        if load_pvporcupine_api_key() != "CHANGE_ME" and is_wake_word_active():
            self.wake_word_active = True
            self.wake_word_trigger()

        self.manuel_stop = False

        self.border_animation = None

        self.complated_answer = False

        self.reading_thread = False
        self.reading_thread_2 = False

        image_layout = QHBoxLayout()
        self.the_image = QLabel(self)
        self.the_image.setPixmap(QtGui.QPixmap(load_logo_file_path()).scaled(25, 25))

        image_layout.addWidget(self.the_image)
        self.layout.addLayout(image_layout)
        self.the_image.setAlignment(Qt.AlignCenter)
        self.the_image.setFixedHeight(35)

        # Logo Adding
        if not is_logo_active_setting_active():
            self.the_image.hide()

        self.update_screen()

    def put_location(self):
        if load_location_setting() == "right":
            self.put_window_to_right_side_of_screen()

    def init_border_animation(self):
        # Create a QVariantAnimation to handle color change
        border_animation = QVariantAnimation(
            self,
            valueChanged=self.update_border_color,
            startValue=QColor("#303030"),
            endValue=QColor("#23538F"),
            duration=2000,  # Duration for one loop in milliseconds
        )
        border_animation.setLoopCount(-1)  # Loop indefinitely
        return border_animation

    def start_border_animation(self, status):
        print("FUNCTION TRİGGERED")
        if self.border_animation is None:
            self.border_animation = self.init_border_animation()

        status = status.lower() == "true"
        if status:
            self.border_animation.start()
        else:
            self.border_animation.stop()
            self.title_bar.setStyleSheet(
                "background-color: #2E2E2E; color: white; border-style: solid; border-radius: 15px; border-width: 0px; color: #fff;"
            )

    def update_border_color(self, color):
        self.title_bar.setStyleSheet(
            f"background-color: #2E2E2E; color: white; border-style: solid; border-radius: 15px; border-width: 2px; border-color: {color.name()}; color: #fff;"
        )
        self.title_bar.setStyleSheet(
            f"background-color: #2E2E2E; color: white; border-style: solid; border-radius: 15px; border-width: 1px; border-color: {color.name()}; color: #fff;"
        )

    # Existing methods...

    def general_styling(self, a=None):
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setStyleSheet(
            f"border-radius: {self.border_radius}px; background-color: rgba({self.background_color}, {self.opacity});"
        )
        self.central_widget.setStyleSheet(
            "border-style: solid; border-width: 1px; border-color: rgb(0,0,0,0);"
        )

        self.input_box_style = "border-radius: 10px; border-bottom: 1px solid #01EE8A;"

        self.settingsButton_style = (
            "border-radius: 5px; height: 25px; border-style: solid;"
        )
        self.llmsettingsButton_style = (
            "border-radius: 5px; height: 25px; border-style: solid;"
        )

        self.btn_minimize.setStyleSheet(
            "background-color: #2E2E2E; color: white; border-style: none;"
        )
        self.btn_close.setStyleSheet(
            "background-color: #2E2E2E; color: white; border-style: none;"
        )

    def set_background_color(self, color):
        self.background_color = color
        self.worker_3.the_input_text = "True"

    def set_opacity(self, opacity):
        self.opacity = opacity
        self.worker_3.the_input_text = "True"

    def set_border_radius(self, radius):
        self.border_radius = radius
        self.worker_3.the_input_text = "True"

    def wake_word_trigger(self):
        self.wake_word_thread = threading.Thread(target=self.wake_word)
        self.wake_word_thread.start()

    def wake_word(self):
        from .agent.process import tts_if_you_can

        while True and is_wake_word_active() and self.wake_word_active:
            if wake_word(self):

                def random_accept_words():
                    return random.choice(["Yes", "Sir", "Boss", "Master"])

                tts_if_you_can(random_accept_words(), not_threaded=True)

                def trigger_wake_word():
                    if (
                        is_wake_word_screen_setting_active()
                        and llm_settings[load_model_settings()]["vision"]
                    ):
                        self.button_handler.toggle_recording(dont_save_image=True)
                    else:
                        self.button_handler.toggle_recording(no_screenshot=True)

                if self.state == "aitalking":
                    self.manuel_stop = True
                    self.stop_talking = True
                    time.sleep(1)
                    trigger_wake_word()
                    print("Stop talking")
                else:
                    trigger_wake_word()

    def dark_mode(self):
        self.setAutoFillBackground(True)
        p = self.palette()
        p.setColor(
            self.backgroundRole(), QColor("#171717")
        )  # Set background color to white
        self.setPalette(p)
        self.input_box.setStyleSheet(
            self.input_box_style + "background-color: #2E2E2E; color: white;"
        )

        self.settingsButton.setStyleSheet(
            self.settingsButton_style + "background-color: #2E2E2E; color: white;"
        )
        self.llmsettingsButton.setStyleSheet(
            self.llmsettingsButton_style + "background-color: #2E2E2E; color: white;"
        )

    def light_mode(self):
        self.setAutoFillBackground(True)
        p = self.palette()
        p.setColor(self.backgroundRole(), QColor("#F0F0F0"))
        self.setPalette(p)
        self.input_box.setStyleSheet(
            self.input_box_style + "background-color: #FFFFFF; color: black;"
        )

        self.settingsButton.setStyleSheet(
            self.settingsButton_style + "background-color: #FFFFFF; color: black; "
        )
        self.llmsettingsButton.setStyleSheet(
            self.llmsettingsButton_style + "background-color: #FFFFFF; color: black; "
        )

    def collapse_window(self):
        the_input_box.hide()

        self.settingsButton.hide()
        self.llmsettingsButton.hide()

        self.update_screen()

    def initUI(self):
        self.setWindowTitle("GPT")
        self.setGeometry(100, 100, 200, 200)
        width = 210
        height = 300

        # setting the minimum size
        self.setMinimumSize(width, height)

        self.first_height = self.height()
        self.first_width = self.width()

        self.central_widget = QWidget(self)
        self.setCentralWidget(self.central_widget)
        layout = QVBoxLayout(self.central_widget)

        # Custom title bar
        self.title_bar = QWidget(self)
        self.title_bar.setFixedHeight(30)  # Set a fixed height for the title bar
        self.title_bar.setStyleSheet(
            "background-color: #2E2E2E; color: #fff; border-radius: 15px; border-style: solid; border-width: 1px; border-color: #303030;"
        )

        self.title_bar_layout = QHBoxLayout(self.title_bar)
        self.title_bar_layout.setContentsMargins(5, 5, 0, 5)
        self.title_bar_layout.setSpacing(0)

        self.btn_minimize = QPushButton("-", self.title_bar)
        self.btn_minimize.setFixedSize(20, 20)
        self.btn_minimize.clicked.connect(self.showMinimized)

        def stop_app():
            self.stop_talking = True
            self.wake_word_active = False
            if MainWindow.api_enabled:
                from .api import stop_api

                stop_api()
            self.close()

        self.btn_close = QPushButton("×", self.title_bar)
        self.btn_close.setFixedSize(20, 20)
        self.btn_close.clicked.connect(stop_app)

        self.title_label = QLabel("  " + name(), self.title_bar)

        # Change font size
        font = QtGui.QFont()
        font.setPointSize(11)
        self.title_label.setFont(font)

        self.title_label.setStyleSheet("border: 0px solid blue;")

        self.title_bar_layout.addWidget(self.title_label)
        self.title_bar_layout.addStretch()
        self.title_bar_layout.addWidget(self.btn_minimize)

        self.title_bar_layout.addWidget(self.btn_close)

        # Create a spacer item with expanding policy
        spacer = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.title_bar_layout.addSpacerItem(spacer)  # Add spacer to the layout

        layout.addWidget(self.title_bar)

        self.drawing_widget = DrawingWidget(self)
        layout.addWidget(self.drawing_widget)

        self.layout = layout

        self.setLayout(layout)

        # Add keyboard shortcuts
        self.shortcut_screenshot = QShortcut(QKeySequence("Ctrl+1"), self)
        self.shortcut_screenshot.activated.connect(
            lambda: self.button_handler.just_screenshot()
        )
        self.shortcut_screenshot = QShortcut(QKeySequence("Ctrl+2"), self)
        self.shortcut_screenshot.activated.connect(
            lambda: self.button_handler.toggle_recording(take_system_audio=True)
        )

        self.shortcut_no_screenshot = QShortcut(QKeySequence("Ctrl+e"), self)
        self.shortcut_no_screenshot.activated.connect(
            lambda: self.button_handler.toggle_recording(take_system_audio=True)
        )

        self.shortcut_no_screenshot = QShortcut(QKeySequence("Ctrl+3"), self)
        self.shortcut_no_screenshot.activated.connect(
            lambda: self.button_handler.toggle_recording(no_screenshot=True)
        )

        # I want to create an input box to bottom left and a send button to bottom right

        input_box = CustomTextEdit(self)
        self.input_box = input_box

        input_box.setFixedHeight(80)

        # Set text wrapping. I dont wat to cut the text
        input_box.setWordWrapMode(QtGui.QTextOption.NoWrap)

        # Change the font size
        font = QtGui.QFont()
        font.setPointSize(12)
        input_box.setFont(font)

        self.highlighter = PythonSyntaxHighlighter(self.input_box.document())

        if load_api_key() == "CHANGE_ME":
            input_box.setPlaceholderText("Save your API Key, go to settings")
        else:
            if platform.system() == "Darwin":
                if llm_settings[load_model_settings()]["vision"] is False:
                    input_box.setPlaceholderText("Type here \nsand ↵ ")
                else:
                    input_box.setPlaceholderText(
                        "Type here \nand ↵ \nor ⌘ + ↵ (+screenshot)"
                    )
            else:
                if llm_settings[load_model_settings()]["vision"] is False:
                    input_box.setPlaceholderText("Type here \nand ↵ ")
                else:
                    input_box.setPlaceholderText(
                        "Type here \nand ↵ \nor Ctrl + ↵ (+screenshot)"
                    )
            # Add an information and use enter icon to the input box for mac
        input_box.setGeometry(30, self.height() - 60, 200, 80)
        global the_input_box
        the_input_box = input_box

        def input_box_send():
            if input_box.toPlainText() != "":
                click_sound()
                self.button_handler.input_text(input_box.toPlainText())

        def input_box_send_screenshot():
            if input_box.toPlainText() != "":
                click_sound()
                self.button_handler.input_text_screenshot(input_box.toPlainText())

        self.layout.addWidget(input_box)

        self.shortcut_enter = QShortcut(QKeySequence("Ctrl+Return"), self)
        self.shortcut_enter.activated.connect(input_box_send_screenshot)

        global return_key_event
        return_key_event = input_box_send

        button_layout_ = QHBoxLayout()

        self.settingsButton = QPushButton("Chat Settings", self)
        self.settingsButton.clicked.connect(settings_popup)

        self.llmsettingsButton = QPushButton("LLM Settings", self)
        self.llmsettingsButton.clicked.connect(llmsettings_popup)

        button_layout_.addWidget(self.settingsButton)
        button_layout_.addWidget(self.llmsettingsButton)
        self.layout.addLayout(button_layout_)

        self.worker = Worker()
        self.worker.text_to_set.connect(self.set_text)
        self.worker.start()

        self.worker_2 = Worker_2()
        self.worker_2.text_to_set.connect(self.start_border_animation)
        self.worker_2.text_to_set_title_bar.connect(self.set_title_bar_text)
        self.worker_2.start()

        self.worker_3 = Worker_3()
        self.worker_3.text_to_set.connect(self.general_styling)
        self.worker_3.start()

        self.worker_collapse = Worker_collapse()
        self.worker_collapse.text_to_set.connect(self.collapse_gca)
        self.worker_collapse.start()

        self.worker_uncollapse = Worker_uncollapse()
        self.worker_uncollapse.text_to_set.connect(self.uncollapse_gca)
        self.worker_uncollapse.start()

        self.worker_show_logo = Worker_show_logo()
        self.worker_show_logo.text_to_set.connect(self.show_logo)
        self.worker_show_logo.start()

        self.worker_hide_logo = Worker_hide_logo()
        self.worker_hide_logo.text_to_set.connect(self.hide_logo)
        self.worker_hide_logo.start()

        self.worker_activate_long_gca = Worker_activate_long_gca()
        self.worker_activate_long_gca.text_to_set.connect(self.activate_long_gca)
        self.worker_activate_long_gca.start()

        self.worker_deactivate_long_gca = Worker_deactivate_long_gca()
        self.worker_deactivate_long_gca.text_to_set.connect(self.deactivate_long_gca)
        self.worker_deactivate_long_gca.start()

        self.worker_tray_and_task_bar_logo = Worker_tray_and_task_bar_logo()
        self.worker_tray_and_task_bar_logo.text_to_set.connect(
            self.tray_and_task_bar_logo
        )
        self.worker_tray_and_task_bar_logo.start()

        # print height and width
        print(self.height(), self.width())

        self.show()

    def set_text(self, text):
        global the_input_box

        vertical_scrollbar = the_input_box.verticalScrollBar()
        scroll_value = vertical_scrollbar.value()

        the_input_box.setPlainText(text)

        vertical_scrollbar.setValue(scroll_value)

    def set_title_bar_text(self, text):
        self.title_label.setText(text)

    def update_from_thread(self, text, system=True):
        self.worker.make_animation = True
        if system:
            text = "System: " + text
        print("Updating from thread", text)
        self.worker.the_input_text = text

    def read_part_task_generate_only(self):
        if not is_just_text_model_active() and the_main_window.tts_available:
            threads = {}

            the_okey_parts = split_with_multiple_delimiters(
                self.worker.the_input_text, ".?!:"
            )

            for each in the_okey_parts:
                if the_main_window.stop_talking:
                    break

                the_thread = threading.Thread(target=text_to_speech, args=(each,))

                threads[each] = the_thread
                the_thread.start()

            for each in threads.values():
                each.join()

        self.reading_thread_2 = False

    def read_part_task(self):
        if not is_just_text_model_active() and the_main_window.tts_available:
            threads = {}

            the_okey_parts = split_with_multiple_delimiters(
                self.worker.the_input_text, ".?!:"
            )

            will_read_parts = []

            for each in the_okey_parts:
                if the_main_window.stop_talking:
                    break
                if each not in readed_sentences:
                    will_read_parts.append(each)
                    readed_sentences.append(each)

                    the_thread = threading.Thread(target=text_to_speech, args=(each,))

                    threads[each] = the_thread
                    the_thread.start()

            for each in will_read_parts:
                if the_main_window.stop_talking:
                    break
                threads[each].join()

                tts_if_you_can(each, not_threaded=True, bypass_other_settings=True)

        self.reading_thread = False

    def set_text_to_input_box(self, text):
        global readed_sentences
        self.worker.make_animation = False
        if self.worker.the_input_text.startswith("System:") or self.complated_answer:
            self.worker.the_input_text = ""
            self.complated_answer = False
            readed_sentences = []
        if text not in (">", "<>", ">\n", "<", "<\n"):
            self.worker.the_input_text += text

            if self.reading_thread is not True and len(self.worker.the_input_text) > 40:
                self.reading_thread = True
                threading.Thread(target=self.read_part_task).start()

            if (
                self.reading_thread_2 is not True
                and len(self.worker.the_input_text) > 250
            ):
                self.reading_thread_2 = True
                threading.Thread(target=self.read_part_task_generate_only).start()

        else:
            print("Problem on text chars")

    def set_text_from_api(self, text):
        self.worker.make_animation = True
        self.worker.the_input_text = text

    def active_border_animation(self, title_bar_text=None):
        if self.worker_2.title_bar_text is not None:
            if self.worker_2.title_bar_text != title_bar_text:
                return

        self.worker_2.the_input_text = True
        if title_bar_text is None:
            title_bar_text = "  " + name()
        else:
            title_bar_text = f"  {title_bar_text}"
            if len(title_bar_text) > 33:
                title_bar_text = title_bar_text[:30] + "..."
        self.worker_2.title_bar_text = title_bar_text

        self.btn_minimize.hide()
        self.btn_close.hide()

    def deactive_border_animation(self, title_bar_text=None):
        if title_bar_text is None:
            title_bar_text = "  " + name()
        else:
            title_bar_text = f"  {title_bar_text}"
            if len(title_bar_text) > 33:
                title_bar_text = title_bar_text[:30] + "..."

        if self.worker_2.title_bar_text is not None:
            if self.worker_2.title_bar_text != title_bar_text:
                return

        self.worker_2.the_input_text = False
        self.worker_2.title_bar_text = None
        time.sleep(1)
        self.btn_minimize.show()
        self.btn_close.show()

    def mouseMoveEvent(self, event: QMouseEvent):
        delta = QPoint(event.globalPos() - self.old_position)
        if event.buttons() == Qt.LeftButton and self.title_bar.underMouse():
            self.move(self.x() + delta.x(), self.y() + delta.y())
            self.old_position = event.globalPos()

    def mousePressEvent(self, event: QMouseEvent):
        self.old_position = event.globalPos()

    def remove_screenshot_button(self):
        self.update()

    def add_screenshot_button(self):
        self.update()

    def update_state(self, new_state):
        assistant_stopped = False
        if self.state == "aitalking" and new_state == "idle":
            assistant_stopped = True

        if self.manuel_stop:
            assistant_stopped = False
            self.manuel_stop = False

        self.state = new_state
        print(f"State updated: {new_state}")
        if "talking" in new_state:
            self.tray.setIcon(self.tray_active_icon)
            self.pulse_frame = 0
            if self.pulse_timer:
                self.pulse_timer.stop()
                self.pulse_timer = None
            self.pulse_timer = QTimer(self)
            self.pulse_timer.timeout.connect(self.pulse_circle)
            self.pulse_timer.start(5)
        elif new_state == "thinking":
            the_main_window.update_from_thread("Thinking...")
            self.pulse_frame = 0
            if self.pulse_timer:
                self.pulse_timer.stop()
                self.pulse_timer = None
            self.pulse_timer = QTimer(self)
            self.pulse_timer.timeout.connect(self.pulse_circle)
            self.pulse_timer.start(20)
        elif self.pulse_timer:
            self.tray.setIcon(self.tray_icon)
            self.pulse_timer.stop()
            self.pulse_timer = None
        self.update()  # Trigger a repaint

        if assistant_stopped:
            global the_input_box
            if (
                the_input_box.toPlainText().endswith("?")
                and is_continuously_conversations_setting_active()
            ):
                self.button_handler.toggle_recording(
                    no_screenshot=True, new_record=True
                )

        if new_state == "idle":
            click_sound()

    def pulse_circle(self):
        self.pulse_frame = (self.pulse_frame + 1) % 100
        self.update()

    def collapse_gca(self):
        self.collapse = True
        self.collapse_window()
        activate_collapse_setting()

        self.update_screen()

    def collapse_gca_api(self):
        self.worker_collapse.the_input_text = "True"

    def uncollapse_gca(self):
        self.collapse = False
        print()
        # hide all buttons and input box
        the_input_box.show()

        self.settingsButton.show()
        self.llmsettingsButton.show()

        deactivate_collapse_setting()

        self.update_screen()

    def uncollapse_gca_api(self):
        self.worker_uncollapse.the_input_text = "True"

    def show_logo(self):
        self.the_image.setPixmap(QtGui.QPixmap(load_logo_file_path()).scaled(25, 25))
        self.the_image.show()

        self.update_screen()

    def tray_and_task_bar_logo(self):
        app_icon = QtGui.QIcon()

        app_icon.addFile(load_logo_file_path(), QtCore.QSize(48, 48))

        self.the_app.setWindowIcon(app_icon)

        self.tray.setIcon(app_icon)

        self.tray_icon = app_icon
        self.tray_active_icon = app_icon

        print("ICON Set", load_logo_file_path())

    def tray_and_task_bar_logo_api(self):
        self.worker_tray_and_task_bar_logo.the_input_text = "True"

    def show_logo_api(self):
        self.worker_show_logo.the_input_text = "True"

    def hide_logo(self):
        self.the_image.hide()
        self.update_screen()

    def hide_logo_api(self):
        self.worker_hide_logo.the_input_text = "True"

    def activate_long_gca(self):
        activate_long_gca_setting()

        self.update_screen()

    def activate_long_gca_api(self):
        self.worker_activate_long_gca.the_input_text = "True"

    def deactivate_long_gca(self):
        deactivate_long_gca_setting()

        self.update_screen()

    def deactivate_long_gca_api(self):
        self.worker_deactivate_long_gca.the_input_text = "True"

    def update_screen(self):
        width = 210
        height = 320

        if is_logo_active_setting_active():
            height += 35

        if is_collapse_setting_active():
            height = 150
            if is_logo_active_setting_active():
                height += 35

        if is_long_gca_setting_active():
            if not is_collapse_setting_active():
                height += 500
                self.input_box.setFixedHeight(580)

        else:
            self.input_box.setFixedHeight(80)

        self.setFixedSize(width, height)
        self.put_location()

    def put_window_to_right_side_of_screen(self):
        screen = QDesktopWidget().screenGeometry()
        window = self.frameGeometry()

        # Calculate x position for the right side of the screen and center vertically
        x = screen.width() - window.width()  # To right side
        y = (screen.height() - window.height()) // 2  # Center vertically

        # Add a small offset to the right side
        x -= 10

        self.move(x, y)