-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonico.py
More file actions
executable file
·7989 lines (6635 loc) · 340 KB
/
Copy pathpythonico.py
File metadata and controls
executable file
·7989 lines (6635 loc) · 340 KB
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
#!/usr/bin/env python3
import anthropic
import speech_recognition as sr
import os, sys, traceback, markdown, pyaudio, keyword, re, webbrowser, json, pkgutil, tempfile, signal, pdb
from PyQt6 import QtCore, QtGui, QtWidgets
from pyqtconsole.console import PythonConsole
class SettingsManager:
def __init__(self):
self.config_dir = os.path.expanduser("~/.pythonico")
self.config_file = os.path.join(self.config_dir, "settings.json")
self.observers = []
self.settings = self.load_settings()
def load_settings(self):
defaults = {
"general": {
"theme": "Tokyo Night Day",
"auto_save": True,
"auto_save_interval": 30,
"restore_tabs": True,
"confirm_exit": True,
"startup_behavior": "restore_session"
},
"editor": {
"font_family": "Monospace",
"font_size": 11,
"theme": "Tokyo Night Day",
"line_numbers": True,
"word_wrap": False,
"indent_size": 4,
"auto_indent": True,
"highlight_current_line": True,
"show_whitespace": False,
"bracket_matching": True,
"auto_completion": True,
"minimap": False
},
"assistant": {
"font_family": "Monospace",
"font_size": 11,
"theme": "Solarized Light",
"api_key": "YOUR-CLAUDE-API",
"model": "claude-sonnet-4-5-20250929",
"temperature": 0.7,
"max_tokens": 4096,
"default_language": "English (en-US)",
"auto_scroll": True,
"markdown_rendering": True
},
"terminal": {
"font_family": "Monospace",
"font_size": 11,
"theme": "Dark",
"startup_command": "",
"history_size": 1000,
"auto_complete": True
},
"interface": {
"show_project_explorer": True,
"show_assistant": True,
"show_terminal": True,
"toolbar_visible": True,
"status_bar_visible": True,
"panel_layout": "vertical",
"window_geometry": None,
"window_state": None
},
"shortcuts": {
"new_file": "Ctrl+N",
"open_file": "Ctrl+O",
"save_file": "Ctrl+S",
"save_as": "Ctrl+Shift+S",
"close_tab": "Ctrl+W",
"quit": "Ctrl+Q",
"toggle_project_explorer": "Ctrl+E",
"toggle_assistant": "Ctrl+I",
"toggle_terminal": "Ctrl+T",
"run_program": "Ctrl+R",
"debug_program": "Ctrl+D",
"find": "Ctrl+F",
"replace": "Ctrl+H",
"goto_line": "Ctrl+G"
},
"advanced": {
"debug_mode": False,
"performance_mode": False,
"memory_limit": 512,
"plugin_directory": "",
"backup_directory": "",
"backup_count": 10,
"check_updates": True,
"telemetry": False
}
}
if os.path.exists(self.config_file):
try:
with open(self.config_file, 'r') as f:
loaded_settings = json.load(f)
defaults.update(loaded_settings)
except Exception as e:
print(f"Error loading settings: {e}")
return defaults
def save_settings(self):
try:
os.makedirs(self.config_dir, exist_ok=True)
with open(self.config_file, 'w') as f:
json.dump(self.settings, f, indent=2)
self.notify_observers()
except Exception as e:
print(f"Error saving settings: {e}")
def get(self, category, key, default=None):
return self.settings.get(category, {}).get(key, default)
def set(self, category, key, value):
if category not in self.settings:
self.settings[category] = {}
self.settings[category][key] = value
self.save_settings()
def get_category(self, category):
return self.settings.get(category, {})
def set_category(self, category, values):
self.settings[category] = values
self.save_settings()
def add_observer(self, callback):
self.observers.append(callback)
def remove_observer(self, callback):
if callback in self.observers:
self.observers.remove(callback)
def notify_observers(self):
for callback in self.observers:
callback(self.settings)
class SettingsDialog(QtWidgets.QDialog):
def __init__(self, settings_manager, parent=None):
super().__init__(parent)
self.settings_manager = settings_manager
self.temp_settings = json.loads(json.dumps(settings_manager.settings))
self.setup_ui()
def setup_ui(self):
self.setWindowTitle("Settings")
self.setModal(True)
self.resize(800, 600)
layout = QtWidgets.QVBoxLayout(self)
# Create tab widget
self.tab_widget = QtWidgets.QTabWidget()
layout.addWidget(self.tab_widget)
# Create tabs
self.create_general_tab()
self.create_editor_tab()
self.create_assistant_tab()
self.create_terminal_tab()
self.create_interface_tab()
self.create_shortcuts_tab()
self.create_advanced_tab()
# Button box
button_box = QtWidgets.QDialogButtonBox(
QtWidgets.QDialogButtonBox.StandardButton.Ok |
QtWidgets.QDialogButtonBox.StandardButton.Cancel |
QtWidgets.QDialogButtonBox.StandardButton.Apply |
QtWidgets.QDialogButtonBox.StandardButton.RestoreDefaults
)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
button_box.button(QtWidgets.QDialogButtonBox.StandardButton.Apply).clicked.connect(self.apply_settings)
button_box.button(QtWidgets.QDialogButtonBox.StandardButton.RestoreDefaults).clicked.connect(self.restore_defaults)
layout.addWidget(button_box)
def create_general_tab(self):
tab = QtWidgets.QWidget()
layout = QtWidgets.QFormLayout(tab)
# Theme selection
self.general_theme = QtWidgets.QComboBox()
self.general_theme.addItems(["Tokyo Night Day", "Tokyo Night Storm", "Solarized Light", "Solarized Dark", "Dark", "Light"])
self.general_theme.setCurrentText(self.temp_settings["general"]["theme"])
layout.addRow("Application Theme:", self.general_theme)
# Auto-save
self.auto_save = QtWidgets.QCheckBox("Enable auto-save")
self.auto_save.setChecked(self.temp_settings["general"]["auto_save"])
layout.addRow(self.auto_save)
# Auto-save interval
self.auto_save_interval = QtWidgets.QSpinBox()
self.auto_save_interval.setRange(5, 300)
self.auto_save_interval.setSuffix(" seconds")
self.auto_save_interval.setValue(self.temp_settings["general"]["auto_save_interval"])
layout.addRow("Auto-save interval:", self.auto_save_interval)
# Restore tabs
self.restore_tabs = QtWidgets.QCheckBox("Restore tabs on startup")
self.restore_tabs.setChecked(self.temp_settings["general"]["restore_tabs"])
layout.addRow(self.restore_tabs)
# Confirm exit
self.confirm_exit = QtWidgets.QCheckBox("Confirm before exit")
self.confirm_exit.setChecked(self.temp_settings["general"]["confirm_exit"])
layout.addRow(self.confirm_exit)
# Startup behavior
self.startup_behavior = QtWidgets.QComboBox()
self.startup_behavior.addItems(["new_file", "restore_session", "open_dialog"])
self.startup_behavior.setCurrentText(self.temp_settings["general"]["startup_behavior"])
layout.addRow("Startup behavior:", self.startup_behavior)
self.tab_widget.addTab(tab, "General")
def create_editor_tab(self):
tab = QtWidgets.QWidget()
layout = QtWidgets.QFormLayout(tab)
# Font settings
font_layout = QtWidgets.QHBoxLayout()
self.editor_font_family = QtWidgets.QFontComboBox()
self.editor_font_family.setCurrentText(self.temp_settings["editor"]["font_family"])
self.editor_font_size = QtWidgets.QSpinBox()
self.editor_font_size.setRange(8, 72)
self.editor_font_size.setValue(self.temp_settings["editor"]["font_size"])
font_layout.addWidget(self.editor_font_family)
font_layout.addWidget(self.editor_font_size)
layout.addRow("Font:", font_layout)
# Theme
self.editor_theme = QtWidgets.QComboBox()
self.editor_theme.addItems(["Tokyo Night Day", "Tokyo Night Storm", "Solarized Light", "Solarized Dark", "Dark", "Light"])
self.editor_theme.setCurrentText(self.temp_settings["editor"]["theme"])
layout.addRow("Editor Theme:", self.editor_theme)
# Line numbers
self.line_numbers = QtWidgets.QCheckBox("Show line numbers")
self.line_numbers.setChecked(self.temp_settings["editor"]["line_numbers"])
layout.addRow(self.line_numbers)
# Word wrap
self.word_wrap = QtWidgets.QCheckBox("Enable word wrap")
self.word_wrap.setChecked(self.temp_settings["editor"]["word_wrap"])
layout.addRow(self.word_wrap)
# Indent size
self.indent_size = QtWidgets.QSpinBox()
self.indent_size.setRange(1, 8)
self.indent_size.setValue(self.temp_settings["editor"]["indent_size"])
layout.addRow("Indent size:", self.indent_size)
# Auto indent
self.auto_indent = QtWidgets.QCheckBox("Auto indent")
self.auto_indent.setChecked(self.temp_settings["editor"]["auto_indent"])
layout.addRow(self.auto_indent)
# Highlight current line
self.highlight_current_line = QtWidgets.QCheckBox("Highlight current line")
self.highlight_current_line.setChecked(self.temp_settings["editor"]["highlight_current_line"])
layout.addRow(self.highlight_current_line)
# Show whitespace
self.show_whitespace = QtWidgets.QCheckBox("Show whitespace characters")
self.show_whitespace.setChecked(self.temp_settings["editor"]["show_whitespace"])
layout.addRow(self.show_whitespace)
# Bracket matching
self.bracket_matching = QtWidgets.QCheckBox("Enable bracket matching")
self.bracket_matching.setChecked(self.temp_settings["editor"]["bracket_matching"])
layout.addRow(self.bracket_matching)
# Auto completion
self.auto_completion = QtWidgets.QCheckBox("Enable auto completion")
self.auto_completion.setChecked(self.temp_settings["editor"]["auto_completion"])
layout.addRow(self.auto_completion)
# Minimap
self.minimap = QtWidgets.QCheckBox("Show minimap")
self.minimap.setChecked(self.temp_settings["editor"]["minimap"])
layout.addRow(self.minimap)
self.tab_widget.addTab(tab, "Editor")
def create_assistant_tab(self):
tab = QtWidgets.QWidget()
layout = QtWidgets.QFormLayout(tab)
# Font settings
font_layout = QtWidgets.QHBoxLayout()
self.assistant_font_family = QtWidgets.QFontComboBox()
self.assistant_font_family.setCurrentText(self.temp_settings["assistant"]["font_family"])
self.assistant_font_size = QtWidgets.QSpinBox()
self.assistant_font_size.setRange(8, 72)
self.assistant_font_size.setValue(self.temp_settings["assistant"]["font_size"])
font_layout.addWidget(self.assistant_font_family)
font_layout.addWidget(self.assistant_font_size)
layout.addRow("Font:", font_layout)
# Theme
self.assistant_theme = QtWidgets.QComboBox()
self.assistant_theme.addItems(["Tokyo Night Day", "Tokyo Night Storm", "Solarized Light", "Solarized Dark", "Dark", "Light"])
self.assistant_theme.setCurrentText(self.temp_settings["assistant"]["theme"])
layout.addRow("Assistant Theme:", self.assistant_theme)
# API Key
self.api_key = QtWidgets.QLineEdit()
self.api_key.setText(self.temp_settings["assistant"]["api_key"])
self.api_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
layout.addRow("API Key:", self.api_key)
# Model
self.model = QtWidgets.QComboBox()
self.model.addItems(["claude-sonnet-4-5-20250929"])
self.model.setCurrentText(self.temp_settings["assistant"]["model"])
layout.addRow("Model:", self.model)
# Temperature
self.temperature = QtWidgets.QDoubleSpinBox()
self.temperature.setRange(0.0, 2.0)
self.temperature.setSingleStep(0.1)
self.temperature.setValue(self.temp_settings["assistant"]["temperature"])
layout.addRow("Temperature:", self.temperature)
# Max tokens
self.max_tokens = QtWidgets.QSpinBox()
self.max_tokens.setRange(1, 8192)
self.max_tokens.setValue(self.temp_settings["assistant"]["max_tokens"])
layout.addRow("Max Tokens:", self.max_tokens)
# Default language
self.default_language = QtWidgets.QComboBox()
self.default_language.addItems([
"English (en-US)", "English (en-GB)", "Arabic (ar-SA)", "Chinese (zh-CN)",
"Danish (da-DK)", "Dutch (nl-NL)", "Finnish (fi-FI)", "French (fr-FR)",
"German (de-DE)", "Italian (it-IT)", "Japanese (ja-JP)", "Korean (ko-KR)",
"Norwegian (nb-NO)", "Portuguese (pt-BR)", "Portuguese (pt-PT)",
"Spanish (es-ES)", "Swedish (sv-SE)", "Ukrainian (uk-UA)"
])
self.default_language.setCurrentText(self.temp_settings["assistant"]["default_language"])
layout.addRow("Default Language:", self.default_language)
# Auto scroll
self.auto_scroll = QtWidgets.QCheckBox("Auto scroll to bottom")
self.auto_scroll.setChecked(self.temp_settings["assistant"]["auto_scroll"])
layout.addRow(self.auto_scroll)
# Markdown rendering
self.markdown_rendering = QtWidgets.QCheckBox("Enable markdown rendering")
self.markdown_rendering.setChecked(self.temp_settings["assistant"]["markdown_rendering"])
layout.addRow(self.markdown_rendering)
self.tab_widget.addTab(tab, "Assistant")
def create_terminal_tab(self):
tab = QtWidgets.QWidget()
layout = QtWidgets.QFormLayout(tab)
# Font settings
font_layout = QtWidgets.QHBoxLayout()
self.terminal_font_family = QtWidgets.QFontComboBox()
self.terminal_font_family.setCurrentText(self.temp_settings["terminal"]["font_family"])
self.terminal_font_size = QtWidgets.QSpinBox()
self.terminal_font_size.setRange(8, 72)
self.terminal_font_size.setValue(self.temp_settings["terminal"]["font_size"])
font_layout.addWidget(self.terminal_font_family)
font_layout.addWidget(self.terminal_font_size)
layout.addRow("Font:", font_layout)
# Theme
self.terminal_theme = QtWidgets.QComboBox()
self.terminal_theme.addItems(["Dark", "Light", "Tokyo Night Day", "Tokyo Night Storm", "Solarized Light", "Solarized Dark"])
self.terminal_theme.setCurrentText(self.temp_settings["terminal"]["theme"])
layout.addRow("Terminal Theme:", self.terminal_theme)
# Startup command
self.startup_command = QtWidgets.QLineEdit()
self.startup_command.setText(self.temp_settings["terminal"]["startup_command"])
layout.addRow("Startup Command:", self.startup_command)
# History size
self.history_size = QtWidgets.QSpinBox()
self.history_size.setRange(100, 10000)
self.history_size.setValue(self.temp_settings["terminal"]["history_size"])
layout.addRow("History Size:", self.history_size)
# Auto complete
self.terminal_auto_complete = QtWidgets.QCheckBox("Enable auto completion")
self.terminal_auto_complete.setChecked(self.temp_settings["terminal"]["auto_complete"])
layout.addRow(self.terminal_auto_complete)
self.tab_widget.addTab(tab, "Terminal")
def create_interface_tab(self):
tab = QtWidgets.QWidget()
layout = QtWidgets.QFormLayout(tab)
# Panel visibility
self.show_project_explorer = QtWidgets.QCheckBox("Show Project Explorer")
self.show_project_explorer.setChecked(self.temp_settings["interface"]["show_project_explorer"])
layout.addRow(self.show_project_explorer)
self.show_assistant = QtWidgets.QCheckBox("Show Assistant Panel")
self.show_assistant.setChecked(self.temp_settings["interface"]["show_assistant"])
layout.addRow(self.show_assistant)
self.show_terminal = QtWidgets.QCheckBox("Show Terminal Panel")
self.show_terminal.setChecked(self.temp_settings["interface"]["show_terminal"])
layout.addRow(self.show_terminal)
# UI elements
self.toolbar_visible = QtWidgets.QCheckBox("Show Toolbar")
self.toolbar_visible.setChecked(self.temp_settings["interface"]["toolbar_visible"])
layout.addRow(self.toolbar_visible)
self.status_bar_visible = QtWidgets.QCheckBox("Show Status Bar")
self.status_bar_visible.setChecked(self.temp_settings["interface"]["status_bar_visible"])
layout.addRow(self.status_bar_visible)
# Panel layout
self.panel_layout = QtWidgets.QComboBox()
self.panel_layout.addItems(["vertical", "horizontal", "tabs"])
self.panel_layout.setCurrentText(self.temp_settings["interface"]["panel_layout"])
layout.addRow("Panel Layout:", self.panel_layout)
self.tab_widget.addTab(tab, "Interface")
def create_shortcuts_tab(self):
tab = QtWidgets.QWidget()
layout = QtWidgets.QVBoxLayout(tab)
# Create scroll area for shortcuts
scroll = QtWidgets.QScrollArea()
scroll_widget = QtWidgets.QWidget()
scroll_layout = QtWidgets.QFormLayout(scroll_widget)
self.shortcut_editors = {}
shortcuts = self.temp_settings["shortcuts"]
for action, shortcut in shortcuts.items():
editor = QtWidgets.QKeySequenceEdit()
editor.setKeySequence(QtGui.QKeySequence(shortcut))
self.shortcut_editors[action] = editor
scroll_layout.addRow(action.replace("_", " ").title() + ":", editor)
scroll.setWidget(scroll_widget)
layout.addWidget(scroll)
self.tab_widget.addTab(tab, "Shortcuts")
def create_advanced_tab(self):
tab = QtWidgets.QWidget()
layout = QtWidgets.QFormLayout(tab)
# Debug mode
self.debug_mode = QtWidgets.QCheckBox("Enable debug mode")
self.debug_mode.setChecked(self.temp_settings["advanced"]["debug_mode"])
layout.addRow(self.debug_mode)
# Performance mode
self.performance_mode = QtWidgets.QCheckBox("Enable performance mode")
self.performance_mode.setChecked(self.temp_settings["advanced"]["performance_mode"])
layout.addRow(self.performance_mode)
# Memory limit
self.memory_limit = QtWidgets.QSpinBox()
self.memory_limit.setRange(128, 4096)
self.memory_limit.setSuffix(" MB")
self.memory_limit.setValue(self.temp_settings["advanced"]["memory_limit"])
layout.addRow("Memory Limit:", self.memory_limit)
# Plugin directory
plugin_layout = QtWidgets.QHBoxLayout()
self.plugin_directory = QtWidgets.QLineEdit()
self.plugin_directory.setText(self.temp_settings["advanced"]["plugin_directory"])
plugin_browse = QtWidgets.QPushButton("Browse...")
plugin_layout.addWidget(self.plugin_directory)
plugin_layout.addWidget(plugin_browse)
layout.addRow("Plugin Directory:", plugin_layout)
# Backup directory
backup_layout = QtWidgets.QHBoxLayout()
self.backup_directory = QtWidgets.QLineEdit()
self.backup_directory.setText(self.temp_settings["advanced"]["backup_directory"])
backup_browse = QtWidgets.QPushButton("Browse...")
backup_layout.addWidget(self.backup_directory)
backup_layout.addWidget(backup_browse)
layout.addRow("Backup Directory:", backup_layout)
# Backup count
self.backup_count = QtWidgets.QSpinBox()
self.backup_count.setRange(1, 100)
self.backup_count.setValue(self.temp_settings["advanced"]["backup_count"])
layout.addRow("Backup Count:", self.backup_count)
# Check updates
self.check_updates = QtWidgets.QCheckBox("Check for updates")
self.check_updates.setChecked(self.temp_settings["advanced"]["check_updates"])
layout.addRow(self.check_updates)
# Telemetry
self.telemetry = QtWidgets.QCheckBox("Send anonymous usage data")
self.telemetry.setChecked(self.temp_settings["advanced"]["telemetry"])
layout.addRow(self.telemetry)
self.tab_widget.addTab(tab, "Advanced")
def collect_settings(self):
# General
self.temp_settings["general"]["theme"] = self.general_theme.currentText()
self.temp_settings["general"]["auto_save"] = self.auto_save.isChecked()
self.temp_settings["general"]["auto_save_interval"] = self.auto_save_interval.value()
self.temp_settings["general"]["restore_tabs"] = self.restore_tabs.isChecked()
self.temp_settings["general"]["confirm_exit"] = self.confirm_exit.isChecked()
self.temp_settings["general"]["startup_behavior"] = self.startup_behavior.currentText()
# Editor
self.temp_settings["editor"]["font_family"] = self.editor_font_family.currentText()
self.temp_settings["editor"]["font_size"] = self.editor_font_size.value()
self.temp_settings["editor"]["theme"] = self.editor_theme.currentText()
self.temp_settings["editor"]["line_numbers"] = self.line_numbers.isChecked()
self.temp_settings["editor"]["word_wrap"] = self.word_wrap.isChecked()
self.temp_settings["editor"]["indent_size"] = self.indent_size.value()
self.temp_settings["editor"]["auto_indent"] = self.auto_indent.isChecked()
self.temp_settings["editor"]["highlight_current_line"] = self.highlight_current_line.isChecked()
self.temp_settings["editor"]["show_whitespace"] = self.show_whitespace.isChecked()
self.temp_settings["editor"]["bracket_matching"] = self.bracket_matching.isChecked()
self.temp_settings["editor"]["auto_completion"] = self.auto_completion.isChecked()
self.temp_settings["editor"]["minimap"] = self.minimap.isChecked()
# Assistant
self.temp_settings["assistant"]["font_family"] = self.assistant_font_family.currentText()
self.temp_settings["assistant"]["font_size"] = self.assistant_font_size.value()
self.temp_settings["assistant"]["theme"] = self.assistant_theme.currentText()
self.temp_settings["assistant"]["api_key"] = self.api_key.text()
self.temp_settings["assistant"]["model"] = self.model.currentText()
self.temp_settings["assistant"]["temperature"] = self.temperature.value()
self.temp_settings["assistant"]["max_tokens"] = self.max_tokens.value()
self.temp_settings["assistant"]["default_language"] = self.default_language.currentText()
self.temp_settings["assistant"]["auto_scroll"] = self.auto_scroll.isChecked()
self.temp_settings["assistant"]["markdown_rendering"] = self.markdown_rendering.isChecked()
# Terminal
self.temp_settings["terminal"]["font_family"] = self.terminal_font_family.currentText()
self.temp_settings["terminal"]["font_size"] = self.terminal_font_size.value()
self.temp_settings["terminal"]["theme"] = self.terminal_theme.currentText()
self.temp_settings["terminal"]["startup_command"] = self.startup_command.text()
self.temp_settings["terminal"]["history_size"] = self.history_size.value()
self.temp_settings["terminal"]["auto_complete"] = self.terminal_auto_complete.isChecked()
# Interface
self.temp_settings["interface"]["show_project_explorer"] = self.show_project_explorer.isChecked()
self.temp_settings["interface"]["show_assistant"] = self.show_assistant.isChecked()
self.temp_settings["interface"]["show_terminal"] = self.show_terminal.isChecked()
self.temp_settings["interface"]["toolbar_visible"] = self.toolbar_visible.isChecked()
self.temp_settings["interface"]["status_bar_visible"] = self.status_bar_visible.isChecked()
self.temp_settings["interface"]["panel_layout"] = self.panel_layout.currentText()
# Shortcuts
for action, editor in self.shortcut_editors.items():
self.temp_settings["shortcuts"][action] = editor.keySequence().toString()
# Advanced
self.temp_settings["advanced"]["debug_mode"] = self.debug_mode.isChecked()
self.temp_settings["advanced"]["performance_mode"] = self.performance_mode.isChecked()
self.temp_settings["advanced"]["memory_limit"] = self.memory_limit.value()
self.temp_settings["advanced"]["plugin_directory"] = self.plugin_directory.text()
self.temp_settings["advanced"]["backup_directory"] = self.backup_directory.text()
self.temp_settings["advanced"]["backup_count"] = self.backup_count.value()
self.temp_settings["advanced"]["check_updates"] = self.check_updates.isChecked()
self.temp_settings["advanced"]["telemetry"] = self.telemetry.isChecked()
def apply_settings(self):
self.collect_settings()
self.settings_manager.settings = self.temp_settings
self.settings_manager.save_settings()
def restore_defaults(self):
reply = QtWidgets.QMessageBox.question(
self, "Restore Defaults",
"Are you sure you want to restore all settings to default values?",
QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No
)
if reply == QtWidgets.QMessageBox.StandardButton.Yes:
if os.path.exists(self.settings_manager.config_file):
os.remove(self.settings_manager.config_file)
self.settings_manager.settings = self.settings_manager.load_settings()
self.temp_settings = json.loads(json.dumps(self.settings_manager.settings))
self.close()
dialog = SettingsDialog(self.settings_manager, self.parent())
dialog.exec()
def accept(self):
self.apply_settings()
super().accept()
class ClaudeAIWorker(QtCore.QThread):
response_received = QtCore.pyqtSignal(str)
def __init__(self, user_input, parent=None):
super().__init__(parent)
self.user_input = user_input
def run(self):
api_key = "YOUR-CLAUDE-API" # Store securely
client = anthropic.Anthropic(api_key=api_key)
try:
response = client.messages.create(
model="claude-3-7-sonnet-20250219",
messages=[
{"role": "user", "content": self.user_input}
],
max_tokens=4096,
temperature=0.7
)
self.response_received.emit(response.content[0].text)
except Exception as e:
self.response_received.emit(f"Error: {e}")
class ClaudeAIWidget(QtWidgets.QWidget):
def closeEvent(self, event):
if hasattr(self, 'worker') and self.worker.isRunning():
self.worker.quit()
if not self.worker.wait(1000): # Wait up to 1 second
self.worker.terminate() # Force terminate if not quitting cleanly
self.worker.wait() # Wait for termination
event.accept()
def __init__(self, settings_manager=None):
super().__init__()
self.settings_manager = settings_manager
# Set up the layout
self.layout = QtWidgets.QVBoxLayout(self)
# Output window (read-only)
self.output_window = QtWidgets.QTextEdit(self)
# Apply settings if available, otherwise use defaults
if self.settings_manager:
assistant_settings = self.settings_manager.get_category("assistant")
self.apply_settings(assistant_settings)
else:
# Default fallback styling
self.output_window.setStyleSheet("background-color: #FDF6E3; color: #657B83;")
font = QtGui.QFont("Monospace")
font.setPointSize(11)
self.output_window.setFont(font)
self.output_window.setReadOnly(True)
self.layout.addWidget(self.output_window)
# Controls row (language selector and mic button)
controls_layout = QtWidgets.QHBoxLayout()
# Add language selector for speech recognition
self.language_selector = QtWidgets.QComboBox(self)
self.language_selector.addItems([
"English (en-US)",
"English (en-GB)",
"Arabic (ar-SA)",
"Chinese (zh-CN)",
"Danish (da-DK)",
"Dutch (nl-NL)",
"Finnish (fi-FI)",
"French (fr-FR)",
"German (de-DE)",
"Italian (it-IT)",
"Japanese (ja-JP)",
"Korean (ko-KR)",
"Norwegian (nb-NO)",
"Portuguese (pt-BR)",
"Portuguese (pt-PT)",
"Spanish (es-ES)",
"Swedish (sv-SE)",
"Ukrainian (uk-UA)"
])
self.language_selector.setToolTip("Select Speech Recognition Language")
self.language_selector.setSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Fixed)
controls_layout.addWidget(self.language_selector)
# Add a microphone button to trigger voice input
self.microphone_button = QtWidgets.QPushButton("Mic", self)
self.microphone_button.setToolTip("Start/Stop Voice Input")
self.microphone_button.clicked.connect(self.toggle_voice_input)
self.is_listening = False # Flag to track voice input state
self.microphone_button.setSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Fixed)
controls_layout.addWidget(self.microphone_button)
# Add controls row to main layout
self.layout.addLayout(controls_layout)
# Input field with inline send button for extra writing space
input_row = QtWidgets.QHBoxLayout()
self.input_field = QtWidgets.QLineEdit(self)
input_row.addWidget(self.input_field)
self.send_button = QtWidgets.QPushButton("Send", self)
self.send_button.setToolTip("Send the input to Claude")
self.send_button.clicked.connect(self.send_request)
input_row.addWidget(self.send_button)
self.layout.addLayout(input_row)
# Add a loading spinner while getting the response from Claude
self.loading_spinner = QtWidgets.QProgressBar(self)
self.loading_spinner.setRange(0, 0) # Indeterminate progress
self.layout.addWidget(self.loading_spinner)
self.loading_spinner.hide() # Hide initially
# Initialize worker
self.worker = ClaudeAIWorker("")
self.worker.response_received.connect(self.update_output)
# Connect signals to show and hide the loading spinner
self.worker.started.connect(self.loading_spinner.show)
self.worker.finished.connect(self.loading_spinner.hide)
# Send request on pressing Enter
self.input_field.returnPressed.connect(self.send_request)
# Set size of AI prompt widget
self.setFixedWidth(int(0.25 * QtWidgets.QApplication.primaryScreen().size().width()))
# Try to import markdown library
try:
self.markdown_module = markdown
except ImportError:
self.markdown_module = None
def apply_settings(self, settings):
"""Apply assistant settings to this widget"""
# Font settings
font_family = settings.get("font_family", "Monospace")
font_size = settings.get("font_size", 11)
font = QtGui.QFont(font_family)
font.setPointSize(font_size)
self.output_window.setFont(font)
# Theme
theme = settings.get("theme", "Solarized Light")
theme_styles = {
"Tokyo Night Day": "background-color: #D5D6DB; color: #4C505E;",
"Tokyo Night Storm": "background-color: #24283b; color: #a9b1d6;",
"Solarized Light": "background-color: #FDF6E3; color: #657B83;",
"Solarized Dark": "background-color: #002B36; color: #839496;",
"Dark": "background-color: #2b2b2b; color: #f8f8f2;",
"Light": "background-color: #ffffff; color: #000000;"
}
style = theme_styles.get(theme, theme_styles["Solarized Light"])
self.output_window.setStyleSheet(style)
# Default language
default_language = settings.get("default_language", "English (en-US)")
if hasattr(self, 'language_selector'):
index = self.language_selector.findText(default_language)
if index >= 0:
self.language_selector.setCurrentIndex(index)
def toggle_voice_input(self):
if self.is_listening:
self.stop_listening()
else:
self.start_listening()
def start_listening(self):
self.is_listening = True
self.microphone_button.setStyleSheet("background-color: red;")
self.microphone_button.setText("Stop")
self.input_field.setPlaceholderText("Listening...")
# Create a timer to stop listening after silence
self.silence_timer = QtCore.QTimer(self)
self.silence_timer.setInterval(10000) # 10 seconds for longer inputs
self.silence_timer.setSingleShot(True)
self.silence_timer.timeout.connect(self.stop_listening)
try:
# Initialize PyAudio explicitly first
self.audio = pyaudio.PyAudio()
# Start listening for voice input
self.recognizer = sr.Recognizer()
self.microphone = sr.Microphone()
# Set up listening in background
self.stop_listening_callback = self.recognizer.listen_in_background(
self.microphone, self.process_voice_input)
# Start the silence timer
self.silence_timer.start()
except Exception as e:
print(f"Error starting listening: {e}")
self.is_listening = False
self.microphone_button.setStyleSheet("")
self.microphone_button.setText("Mic")
self.input_field.setPlaceholderText("")
def stop_listening(self):
self.is_listening = False
self.microphone_button.setStyleSheet("")
self.microphone_button.setText("Mic")
self.input_field.setPlaceholderText("")
# Stop the silence timer if it exists and is active
if hasattr(self, 'silence_timer') and self.silence_timer.isActive():
self.silence_timer.stop()
# First, stop the background listening and wait for it to complete
# This ensures the thread isn't still using the resources we're about to clean up
if hasattr(self, 'stop_listening_callback'):
try:
# Wait for the callback to stop properly
self.stop_listening_callback(wait_for_stop=True)
except Exception:
pass
finally:
# Remove the reference
if hasattr(self, 'stop_listening_callback'):
del self.stop_listening_callback
# Give a short delay to ensure threads have stopped
QtCore.QThread.msleep(100)
# Clean up microphone (which will also clean up its stream)
if hasattr(self, 'microphone'):
try:
# Check if the microphone has a stream attribute and it's not None
if hasattr(self.microphone, 'stream') and self.microphone.stream is not None:
self.microphone.__exit__(None, None, None)
except Exception as e:
print(f"Error closing microphone: {e}")
finally:
# Always delete the microphone reference
del self.microphone
def process_voice_input(self, recognizer, audio):
try:
# Get the selected language code from the combobox
selected_language = self.language_selector.currentText()
language_code = selected_language.split('(')[1].strip(')')
user_input = recognizer.recognize_google(audio, language=language_code)
if user_input:
self.input_field.setText(user_input)
# Only send if we detected actual text
if len(user_input.strip()) > 0:
self.send_request()
# After sending, wait a bit before stopping
QtCore.QTimer.singleShot(500, self.stop_listening)
return
# Voice input was detected, reset the silence timer to continue listening
if hasattr(self, 'silence_timer'):
# Increase timeout to 10 seconds for longer speaking time
self.silence_timer.setInterval(10000)
self.silence_timer.start()
except sr.UnknownValueError:
# Reset the silence timer even when nothing is recognized
# This gives more time when user is thinking
if hasattr(self, 'silence_timer'):
self.silence_timer.start()
except sr.RequestError:
# Handle network errors more gracefully
self.input_field.setPlaceholderText("Network error, try again")
QtCore.QTimer.singleShot(2000, self.stop_listening)
except Exception as e:
# Generic error handler
self.input_field.setPlaceholderText(f"Error: {str(e)[:20]}")
QtCore.QTimer.singleShot(2000, self.stop_listening)
if hasattr(self, 'silence_timer'):
# Increase timeout to 10 seconds for longer speaking time
self.silence_timer.setInterval(10000)
self.silence_timer.start()
def send_request(self):
user_input = str(self.input_field.text())
if user_input.strip() == "/clear":
self.output_window.clear()
else:
self.worker.user_input = user_input
self.worker.start()
self.input_field.clear()
def format_markdown(self, text):
"""
Convert markdown text to HTML using a markdown transpiler.
Uses the markdown library if available, otherwise falls back to basic formatter.
"""
if self.markdown_module:
try:
# Convert markdown to HTML with code highlighting
html = self.markdown_module.markdown(text, extensions=['fenced_code'])
return html
except:
pass # Fall back to basic formatter on error
# Fallback to basic formatter
return self.format_markdown_code_blocks(text)
def format_markdown_code_blocks(self, text):
# Detect code fences and wrap them in HTML for better readability
pattern = r'```(.*?)\n(.*?)´´´'
def replacer(match):
lang = match.group(1).strip()
code_text = match.group(2).replace('<', '<').replace('>', '>')
if lang and lang.lower() == 'python':
# Python code
return f"<pre><code style='color: #0000AA;'>{code_text}</code></pre>"
else:
# No specified language
return f"<pre><code>{code_text}</code></pre>"
# Process code blocks
processed_text = re.sub(pattern, replacer, text, flags=re.DOTALL)
# Process headers (# Header)
processed_text = re.sub(r'^#\s+(.+)$', r'<h1>\1</h1>', processed_text, flags=re.MULTILINE)
processed_text = re.sub(r'^##\s+(.+)$', r'<h2>\1</h2>', processed_text, flags=re.MULTILINE)
processed_text = re.sub(r'^###\s+(.+)$', r'<h3>\1</h3>', processed_text, flags=re.MULTILINE)
# Process bullet lists
processed_text = re.sub(r'^\*\s+(.+)$', r'<li>\1</li>', processed_text, flags=re.MULTILINE)
processed_text = re.sub(r'^-\s+(.+)$', r'<li>\1</li>', processed_text, flags=re.MULTILINE)
# Process numbered lists
processed_text = re.sub(r'^\d+\.\s+(.+)$', r'<li>\1</li>', processed_text, flags=re.MULTILINE)
# Process bold (**text**)
processed_text = re.sub(r'\*\*(.+?)\*\*', r'<b>\1</b>', processed_text)
# Process italic (*text*)
processed_text = re.sub(r'\*(.+?)\*', r'<i>\1</i>', processed_text)
# Process links [text](url)
processed_text = re.sub(r'\[(.+?)\]\((.+?)\)', r'<a href="\2">\1</a>', processed_text)
# Add paragraph breaks
processed_text = re.sub(r'\n\n+', r'<br><br>', processed_text)
return processed_text
def update_output(self, response):
user_input = self.worker.user_input
formatted_response = self.format_markdown(response)
self.output_window.append(
f"<span style='color: red; font-weight: bold;'>Human:</span> {user_input}<br><br>"
f"<span style='color: blue; font-weight: bold;'>Assistant:</span> {formatted_response}<br>"
)
# Advanced line number widget with perfect pixel-level alignment
class LineCountWidget(QtWidgets.QWidget):
line_clicked = QtCore.pyqtSignal(int)
def __init__(self, editor):
super().__init__()
self.editor = editor
self.breakpoints = set()
self._theme_signature = None
self._gutter_background = QtGui.QColor("#f8f8f8")
self._border_color = QtGui.QColor("#d0d0d0")
self._text_muted_color = QtGui.QColor("#666666")
self._current_line_color = QtGui.QColor("#1976d2")
self._breakpoint_color = QtGui.QColor("#d32f2f")
# Set initial properties
self.setFixedWidth(10)
self.setMinimumHeight(0)
self.sync_theme_with_editor()
# Connect to editor signals for perfect synchronization
self.editor.blockCountChanged.connect(self.update_line_numbers)
self.editor.textChanged.connect(self.update_line_numbers)
self.editor.cursorPositionChanged.connect(self.update_line_numbers)
self.editor.verticalScrollBar().valueChanged.connect(self.update_line_numbers)
# Install event filter on editor for resize and font change events
self.editor.installEventFilter(self)
# Create timer for periodic font synchronization
self.font_sync_timer = QtCore.QTimer()
self.font_sync_timer.timeout.connect(self.sync_font_with_editor)
self.font_sync_timer.start(100) # Check every 100ms for font changes
# Initialize
QtCore.QTimer.singleShot(0, self.update_line_numbers)
def _extract_style_color(self, style_sheet, property_name):