-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDEMOFILE.py
More file actions
1507 lines (1309 loc) · 57.3 KB
/
DEMOFILE.py
File metadata and controls
1507 lines (1309 loc) · 57.3 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
import sys
import os
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QVBoxLayout, QWidget, QFileDialog, QSplitter,
QTreeView, QFileSystemModel, QTabWidget, QAction, QInputDialog, QMessageBox, QComboBox, QDialog, QSpinBox, QLabel, QPushButton, QTextEdit,
QPlainTextEdit, QWidget, QDialogButtonBox, QCheckBox, QGroupBox, QHBoxLayout, QLineEdit, QListWidget
)
from PyQt5.QtGui import (
QFont, QTextCharFormat, QSyntaxHighlighter, QColor, QPainter, QTextFormat,
QTextDocument, QTextCursor
)
from PyQt5.QtCore import Qt, QRegExp, QRect, QSize, QTranslator, QLocale
from translations import TRANSLATIONS
# Übersetzer für verschiedene Sprachen
class PythonHighlighter(QSyntaxHighlighter):
def __init__(self, parent=None):
super().__init__(parent)
self.highlighting_rules = []
# Keyword Format
keyword_format = QTextCharFormat()
keyword_format.setForeground(QColor("#ff6b9b"))
keywords = [
"and", "as", "assert", "break", "class", "continue", "def",
"del", "elif", "else", "except", "False", "finally", "for",
"from", "global", "if", "import", "in", "is", "lambda", "None",
"nonlocal", "not", "or", "pass", "raise", "return", "True",
"try", "while", "with", "yield"
]
for word in keywords:
pattern = QRegExp("\\b" + word + "\\b")
rule = (pattern, keyword_format)
self.highlighting_rules.append(rule)
# Function Format
function_format = QTextCharFormat()
function_format.setForeground(QColor("#dcdcaa"))
pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()")
rule = (pattern, function_format)
self.highlighting_rules.append(rule)
# String Format
string_format = QTextCharFormat()
string_format.setForeground(QColor("#ce9178"))
pattern = QRegExp("\".*\"")
pattern.setMinimal(True)
rule = (pattern, string_format)
self.highlighting_rules.append(rule)
pattern = QRegExp("'.*'")
pattern.setMinimal(True)
rule = (pattern, string_format)
self.highlighting_rules.append(rule)
# Comment Format
comment_format = QTextCharFormat()
comment_format.setForeground(QColor("#6a9955"))
pattern = QRegExp("#[^\n]*")
rule = (pattern, comment_format)
self.highlighting_rules.append(rule)
# Numbers Format
number_format = QTextCharFormat()
number_format.setForeground(QColor("#b5cea8"))
pattern = QRegExp("\\b[0-9]+\\b")
rule = (pattern, number_format)
self.highlighting_rules.append(rule)
# Class Format
class_format = QTextCharFormat()
class_format.setForeground(QColor("#4ec9b0"))
pattern = QRegExp("\\bclass\\b\\s*(\\w+)")
rule = (pattern, class_format)
self.highlighting_rules.append(rule)
def highlightBlock(self, text):
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)
class LineNumberArea(QWidget):
def __init__(self, editor):
super().__init__(editor)
self.editor = editor
def sizeHint(self):
return QSize(self.editor.getLineNumberAreaWidth(), 0)
def paintEvent(self, event):
self.editor.lineNumberAreaPaintEvent(event)
class CodeEditor(QPlainTextEdit):
"""Ein einfacher Code-Editor mit Syntax-Hervorhebung."""
def __init__(self):
super().__init__()
self.current_theme = "dark" # Default theme
self.matching_tag_selections = []
self.current_line_selection = []
self._auto_indent = True
# Font setup - using system default monospace font as fallback
font = QFont()
font.setFamily("Consolas, Courier New, monospace")
font.setFixedPitch(True)
font.setPointSize(10)
self.setFont(font)
# Setup line numbers
self.line_number_area = LineNumberArea(self)
self.blockCountChanged.connect(self.updateLineNumberAreaWidth)
self.updateRequest.connect(self.updateLineNumberArea)
self.cursorPositionChanged.connect(self.highlightCurrentLine)
self.cursorPositionChanged.connect(self.highlightMatchingTags)
# Initial updates
self.updateLineNumberAreaWidth(0)
self.highlightCurrentLine()
# Setup editor properties
self.setTabStopWidth(self.fontMetrics().width(' ') * 4)
self.document().setDocumentMargin(10)
# Setup syntax highlighter
self.highlighter = None
def getLineNumberAreaWidth(self):
"""Berechnet die Breite des Zeilennummernbereichs."""
digits = 1
max_num = max(1, self.blockCount())
while max_num >= 10:
max_num //= 10
digits += 1
space = 3 + self.fontMetrics().horizontalAdvance('9') * digits
return space
def updateLineNumberAreaWidth(self, _):
"""Update the width of the line number area."""
width = self.getLineNumberAreaWidth()
self.setViewportMargins(width, 0, 0, 0)
def updateLineNumberArea(self, rect, dy):
"""Update the line number area."""
if dy:
self.line_number_area.scroll(0, dy)
else:
self.line_number_area.update(0, rect.y(), self.line_number_area.width(), rect.height())
if rect.contains(self.viewport().rect()):
self.updateLineNumberAreaWidth(0)
def resizeEvent(self, event):
"""Handle resize events."""
super().resizeEvent(event)
cr = self.contentsRect()
self.line_number_area.setGeometry(QRect(cr.left(), cr.top(), self.getLineNumberAreaWidth(), cr.height()))
def lineNumberAreaPaintEvent(self, event):
"""Paint the line number area."""
painter = QPainter(self.line_number_area)
painter.fillRect(event.rect(), QColor("#2b2b2b") if self.current_theme == "dark" else QColor("#f0f0f0"))
block = self.firstVisibleBlock()
block_number = block.blockNumber()
offset = self.contentOffset()
top = round(self.blockBoundingGeometry(block).translated(offset).top())
bottom = round(top + self.blockBoundingRect(block).height())
while block.isValid() and top <= event.rect().bottom():
if block.isVisible() and bottom >= event.rect().top():
number = str(block_number + 1)
painter.setPen(QColor("#808080") if self.current_theme == "dark" else QColor("#404040"))
rect = QRect(0, top, self.line_number_area.width() - 2, self.fontMetrics().height())
painter.drawText(rect, Qt.AlignRight, number)
block = block.next()
top = bottom
bottom = round(top + self.blockBoundingRect(block).height())
block_number += 1
def highlightCurrentLine(self):
"""Highlight the current line."""
if not hasattr(self, 'current_line_selection'):
self.current_line_selection = []
if not hasattr(self, 'matching_tag_selections'):
self.matching_tag_selections = []
extra_selections = []
if not self.isReadOnly():
selection = QTextEdit.ExtraSelection()
line_color = QColor("#2d2d2d") if self.current_theme == "dark" else QColor("#f0f0f0")
selection.format.setBackground(line_color)
selection.format.setProperty(QTextFormat.FullWidthSelection, True)
selection.cursor = self.textCursor()
selection.cursor.clearSelection()
extra_selections.append(selection)
self.current_line_selection = extra_selections
self.setExtraSelections(self.current_line_selection + self.matching_tag_selections)
# Nach dem Hervorheben der aktuellen Zeile, prüfen wir auf Tags/Klammern
self.highlightMatchingTags()
def highlightMatchingTags(self):
"""Hebt zusammengehörige Tags und Klammern hervor."""
# Alte Hervorhebungen entfernen
self.matching_tag_selections = []
cursor = self.textCursor()
document = self.document()
current_pos = cursor.position()
# Text des gesamten Dokuments
text = document.toPlainText()
# Position in der aktuellen Zeile finden
block_pos = cursor.block().position()
pos_in_block = current_pos - block_pos
line_text = cursor.block().text()
# Dateiendung bestimmen
current_file = self.parent().current_file if hasattr(self.parent(), 'current_file') else ""
file_ext = os.path.splitext(current_file)[1].lower() if current_file else ""
# Klammerpaare für verschiedene Sprachen
brackets = {
'common': [('(', ')'), ('[', ']'), ('{', '}')],
'.py': [('(', ')'), ('[', ']'), ('{', '}'), ('"""', '"""'), ("'''", "'''")],
'.js': [('(', ')'), ('[', ']'), ('{', '}'), ('`', '`')],
'.java': [('(', ')'), ('[', ']'), ('{', '}'), ('/**', '*/')],
'.cpp': [('(', ')'), ('[', ']'), ('{', '}'), ('/*', '*/')],
'.html': [('<', '>')],
'.xml': [('<', '>')],
'.php': [('(', ')'), ('[', ']'), ('{', '}'), ('<?php', '?>'), ('<!--', '-->')],
}
# Aktuelle Sprache bestimmen
current_brackets = brackets.get(file_ext, brackets['common'])
if file_ext in ['.html', '.xml']:
self.highlight_xml_tags()
return
# Position des Cursors prüfen
if pos_in_block >= len(line_text):
return
char = line_text[pos_in_block] if pos_in_block < len(line_text) else ''
prev_char = line_text[pos_in_block - 1] if pos_in_block > 0 else ''
# Prüfen auf Multi-Char-Brackets (z.B. """)
for start, end in current_brackets:
if len(start) > 1 or len(end) > 1:
# Vorwärts prüfen
if pos_in_block + len(start) <= len(line_text):
forward_text = line_text[pos_in_block:pos_in_block + len(start)]
if forward_text == start or forward_text == end:
self.find_and_highlight_multichar(forward_text, start, end, block_pos + pos_in_block)
return
# Rückwärts prüfen
if pos_in_block >= len(start):
backward_text = line_text[pos_in_block - len(start):pos_in_block]
if backward_text == start or backward_text == end:
self.find_and_highlight_multichar(backward_text, start, end, block_pos + pos_in_block - len(start))
return
# Single-Char-Brackets prüfen
for start, end in current_brackets:
if len(start) == 1 and len(end) == 1:
if char in (start, end):
self.find_and_highlight_bracket(char, start, end, block_pos + pos_in_block)
return
elif prev_char in (start, end):
self.find_and_highlight_bracket(prev_char, start, end, block_pos + pos_in_block - 1)
return
def find_and_highlight_bracket(self, char, start, end, pos):
"""Findet und hebt passende Einzelzeichen-Klammern hervor."""
format = QTextCharFormat()
format.setBackground(QColor("#4d4d4d") if self.current_theme == "dark" else QColor("#e6e6e6"))
format.setForeground(QColor("#ffffff") if self.current_theme == "dark" else QColor("#000000"))
# Erste Klammer hervorheben
selection = QTextEdit.ExtraSelection()
selection.format = format
cursor = QTextCursor(self.document())
cursor.setPosition(pos)
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)
selection.cursor = cursor
self.matching_tag_selections.append(selection)
# Richtung und Zielzeichen bestimmen
is_opening = char == start
target = end if is_opening else start
count = 1
# Suche nach passender Klammer
cursor = QTextCursor(self.document())
cursor.setPosition(pos)
if is_opening:
while not cursor.atEnd():
cursor.movePosition(QTextCursor.Right)
current_char = cursor.document().characterAt(cursor.position())
if current_char == start:
count += 1
elif current_char == end:
count -= 1
if count == 0:
selection = QTextEdit.ExtraSelection()
selection.format = format
cursor2 = QTextCursor(cursor)
cursor2.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor)
selection.cursor = cursor2
self.matching_tag_selections.append(selection)
break
else:
while not cursor.atStart():
cursor.movePosition(QTextCursor.Left)
current_char = cursor.document().characterAt(cursor.position())
if current_char == end:
count += 1
elif current_char == start:
count -= 1
if count == 0:
selection = QTextEdit.ExtraSelection()
selection.format = format
selection.cursor = cursor
self.matching_tag_selections.append(selection)
break
self.setExtraSelections(self.current_line_selection + self.matching_tag_selections)
def find_and_highlight_multichar(self, text, start, end, pos):
"""Findet und hebt Multi-Zeichen-Klammern hervor (z.B. ''')."""
format = QTextCharFormat()
format.setBackground(QColor("#4d4d4d") if self.current_theme == "dark" else QColor("#e6e6e6"))
format.setForeground(QColor("#ffffff") if self.current_theme == "dark" else QColor("#000000"))
# Erstes Multi-Char hervorheben
selection = QTextEdit.ExtraSelection()
selection.format = format
cursor = QTextCursor(self.document())
cursor.setPosition(pos)
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor, len(text))
selection.cursor = cursor
self.matching_tag_selections.append(selection)
# Suche nach dem passenden Multi-Char
is_start = text == start
target = end if is_start else start
doc_text = self.document().toPlainText()
if is_start:
next_pos = doc_text.find(target, pos + len(start))
if next_pos != -1:
selection = QTextEdit.ExtraSelection()
selection.format = format
cursor = QTextCursor(self.document())
cursor.setPosition(next_pos)
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor, len(target))
selection.cursor = cursor
self.matching_tag_selections.append(selection)
else:
prev_pos = doc_text.rfind(target, 0, pos)
if prev_pos != -1:
selection = QTextEdit.ExtraSelection()
selection.format = format
cursor = QTextCursor(self.document())
cursor.setPosition(prev_pos)
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor, len(target))
selection.cursor = cursor
self.matching_tag_selections.append(selection)
self.setExtraSelections(self.current_line_selection + self.matching_tag_selections)
def highlight_xml_tags(self):
"""Spezielle Behandlung für XML/HTML Tags."""
cursor = self.textCursor()
document = self.document()
current_pos = cursor.position()
# Text des gesamten Dokuments
text = document.toPlainText()
# Position in der aktuellen Zeile finden
block_pos = cursor.block().position()
pos_in_block = current_pos - block_pos
line_text = cursor.block().text()
# Prüfen, ob wir uns in einem Tag befinden
tag_start = -1
tag_end = -1
is_closing_tag = False
# Rückwärts suchen nach '<'
for i in range(pos_in_block - 1, -1, -1):
if line_text[i] == '<':
tag_start = block_pos + i
if i + 1 < len(line_text) and line_text[i + 1] == '/':
is_closing_tag = True
break
elif line_text[i] == '>':
break
# Vorwärts suchen nach '>'
if tag_start != -1:
for i in range(pos_in_block, len(line_text)):
if line_text[i] == '>':
tag_end = block_pos + i
break
if tag_start != -1 and tag_end != -1:
# Tag-Name extrahieren
tag_text = text[tag_start:tag_end + 1]
if is_closing_tag:
tag_name = tag_text[2:-1].split()[0]
search_pattern = f"<{tag_name}[^>]*>"
else:
tag_name = tag_text[1:-1].split()[0]
search_pattern = f"</{tag_name}>"
# Hervorhebungsformat
format = QTextCharFormat()
format.setBackground(QColor("#4d4d4d") if self.current_theme == "dark" else QColor("#e6e6e6"))
format.setForeground(QColor("#ffffff") if self.current_theme == "dark" else QColor("#000000"))
# Aktuelles Tag hervorheben
selection = QTextEdit.ExtraSelection()
selection.format = format
cursor = QTextCursor(document)
cursor.setPosition(tag_start)
cursor.setPosition(tag_end + 1, QTextCursor.KeepAnchor)
selection.cursor = cursor
self.matching_tag_selections.append(selection)
# Nach dem passenden Tag suchen
cursor = QTextCursor(document)
regex = QRegExp(search_pattern)
if is_closing_tag:
# Rückwärts suchen für schließendes Tag
cursor.setPosition(tag_start)
cursor = document.find(regex, cursor, QTextDocument.FindBackward)
else:
# Vorwärts suchen für öffnendes Tag
cursor.setPosition(tag_end)
cursor = document.find(regex, cursor)
if not cursor.isNull():
selection = QTextEdit.ExtraSelection()
selection.format = format
selection.cursor = cursor
self.matching_tag_selections.append(selection)
# Hervorhebungen anwenden
self.setExtraSelections(self.current_line_selection + self.matching_tag_selections)
def update_theme(self, theme):
"""Aktualisiert das Theme des Editors."""
if theme == "dark":
# Dunkles Theme
self.setStyleSheet("""
QPlainTextEdit {
background-color: #1e1e1e;
color: #d4d4d4;
border: none;
}
""")
# Syntax-Highlighter für Python
self.highlighter = PythonHighlighter(self.document())
else:
# Helles Theme
self.setStyleSheet("""
QPlainTextEdit {
background-color: white;
color: black;
border: none;
}
""")
if self.highlighter:
self.highlighter.setDocument(None)
self.highlighter = None
def update_font(self):
"""Aktualisiert die Schriftgröße."""
font = QFont("Consolas", self.font_size)
font.setFixedPitch(True)
self.setFont(font)
def update_status_bar(self):
"""Aktualisiert die Statusleiste."""
text = self.toPlainText()
total_lines = text.count('\n') + 1
# Zähle tatsächliche Code-Zeilen (keine leeren Zeilen oder Kommentare)
code_lines = 0
for line in text.split('\n'):
line = line.strip()
if line and not line.startswith('#'):
code_lines += 1
# Status-Text aktualisieren
status_text = f"Lines: {total_lines} | Code Lines: {code_lines}"
# print(status_text) # Debugging
def keyPressEvent(self, event):
"""Handle key press events for auto-indentation."""
if event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter:
self.handleNewLine()
else:
super().keyPressEvent(event)
def handleNewLine(self):
"""Handle new line with auto-indentation."""
cursor = self.textCursor()
block = cursor.block()
text = block.text()
indent = self.getIndentation(text)
# Check for special cases that need extra indentation
if text.rstrip().endswith((':','{','[','(')):
indent += ' '
cursor.insertText('\n' + indent)
def getIndentation(self, text):
"""Get the indentation of the current line."""
return text[:len(text) - len(text.lstrip())]
def setAutoIndentation(self, enabled):
"""Enable or disable auto-indentation."""
self._auto_indent = enabled
class EditorWindow(QMainWindow):
"""Hauptfenster des Editors."""
def __init__(self):
super().__init__()
self.setWindowTitle("General Editor")
self.setGeometry(100, 100, 1280, 800) # Default-Größe, falls nicht maximiert
self.showMaximized() # Fenster maximiert starten
self.current_theme = "dark"
self.current_language = "Deutsch" # Standardsprache
self.translations = TRANSLATIONS
# Hauptlayout
main_layout = QVBoxLayout()
central_widget = QWidget()
central_widget.setLayout(main_layout)
self.setCentralWidget(central_widget)
# Splitter für Dateibaum und Tabs
splitter = QSplitter(Qt.Horizontal)
main_layout.addWidget(splitter)
# Dateibaum
self.file_tree = QTreeView()
self.file_model = QFileSystemModel()
self.file_tree.setModel(self.file_model)
self.file_tree.hideColumn(3) # Versteckt die "Date Modified" Spalte
self.file_tree.clicked.connect(self.open_file)
splitter.addWidget(self.file_tree)
# Tabs für Dateien
self.tabs = QTabWidget()
self.tabs.setTabsClosable(True)
self.tabs.tabCloseRequested.connect(self.close_tab)
self.tabs.currentChanged.connect(self.update_status_bar) # Update bei Tab-Wechsel
splitter.addWidget(self.tabs)
# Splitter-Größen setzen (20% für Dateibaum, 80% für Tabs)
splitter.setSizes([200, 800])
# Status Bar
self.status_bar = self.statusBar()
# Linke Seite: Zeilen-Zähler
self.line_count_label = QLabel()
self.status_bar.addWidget(self.line_count_label)
self.line_count_label.setText("Zeilen: 0 | Code-Zeilen: 0") # Initial anzeigen
# Rechte Seite: Copyright
copyright_label = QLabel("Copyright 2025 Funlight Studios")
copyright_label.setStyleSheet("padding-right: 5px;") # Padding rechts hinzufügen
self.status_bar.addPermanentWidget(copyright_label)
# Menü
self.create_menu()
# Initial theme anwenden
self.apply_theme()
def update_status_bar(self):
"""Aktualisiert die Statusleiste mit Informationen zum aktuellen Dokument."""
current_editor = self.tabs.currentWidget()
if isinstance(current_editor, CodeEditor):
text = current_editor.toPlainText()
total_lines = text.count('\n') + 1
# Zähle tatsächliche Code-Zeilen (keine leeren Zeilen oder Kommentare)
code_lines = 0
for line in text.split('\n'):
line = line.strip()
if line and not line.startswith('#'):
code_lines += 1
else:
total_lines = 0
code_lines = 0
# Status-Text aktualisieren mit Übersetzung
status_text = f"{self.tr('Lines')}: {total_lines} | {self.tr('Code Lines')}: {code_lines}"
self.line_count_label.setText(status_text)
def tr(self, text):
"""Übersetzt einen Text in die aktuelle Sprache."""
return self.translations[self.current_language].get(text, text)
def load_file(self, path):
"""Lädt eine Datei in einen neuen Tab."""
with open(path, "r", encoding="utf-8") as file:
content = file.read()
editor = CodeEditor()
editor.setPlainText(content)
editor.update_theme(self.current_theme)
# Verbinde das textChanged-Signal mit update_status_bar
editor.textChanged.connect(self.update_status_bar)
tab_index = self.tabs.addTab(editor, os.path.basename(path))
self.tabs.setCurrentIndex(tab_index)
editor.setProperty("file_path", path)
# Status Bar initial aktualisieren
self.update_status_bar()
def apply_theme(self):
"""Wendet das aktuelle Theme auf alle Komponenten an."""
if self.current_theme == "dark":
# Dunkles Theme
self.setStyleSheet("""
QMainWindow {
background-color: #1e1e1e;
color: #d4d4d4;
}
QMenuBar {
background-color: #1e1e1e;
color: #d4d4d4;
}
QMenuBar::item:selected {
background-color: #2d2d2d;
}
QMenu {
background-color: #1e1e1e;
color: #d4d4d4;
border: 1px solid #2d2d2d;
}
QMenu::item:selected {
background-color: #2d2d2d;
}
QTabWidget::pane {
border: 1px solid #2d2d2d;
}
QTabBar::tab {
background-color: #2d2d2d;
color: #d4d4d4;
padding: 5px;
border: 1px solid #1e1e1e;
}
QTabBar::tab:selected {
background-color: #1e1e1e;
border-bottom: none;
}
QTreeView {
background-color: #1e1e1e;
color: #d4d4d4;
border: none;
}
QTreeView::item:hover {
background-color: #2d2d2d;
}
QTreeView::item:selected {
background-color: #264f78;
}
QTreeView::branch {
background-color: #1e1e1e;
}
QHeaderView::section {
background-color: #2d2d2d;
color: #d4d4d4;
padding: 5px;
border: none;
}
QStatusBar {
background-color: #2d2d2d;
color: #d4d4d4;
border-top: 1px solid #1e1e1e;
}
QSplitter::handle {
background-color: #2d2d2d;
}
QDialog {
background-color: #1e1e1e;
color: #d4d4d4;
}
QLabel {
color: #d4d4d4;
}
QPushButton {
background-color: #0e639c;
color: white;
border: none;
padding: 5px 10px;
}
QPushButton:hover {
background-color: #1177bb;
}
QPushButton:pressed {
background-color: #094771;
}
QLineEdit {
background-color: #3c3c3c;
color: #d4d4d4;
border: 1px solid #2d2d2d;
padding: 3px;
}
QSpinBox {
background-color: #3c3c3c;
color: #d4d4d4;
border: 1px solid #2d2d2d;
}
QComboBox {
background-color: #3c3c3c;
color: #d4d4d4;
border: 1px solid #2d2d2d;
padding: 3px;
}
QComboBox::drop-down {
border: none;
}
QComboBox::down-arrow {
image: none;
border-left: 3px solid none;
border-right: 3px solid none;
border-top: 6px solid #d4d4d4;
width: 0;
height: 0;
}
QComboBox QAbstractItemView {
background-color: #1e1e1e;
color: #d4d4d4;
selection-background-color: #264f78;
}
QGroupBox {
color: #d4d4d4;
border: 1px solid #2d2d2d;
margin-top: 5px;
}
QGroupBox::title {
color: #d4d4d4;
}
QCheckBox {
color: #d4d4d4;
}
QCheckBox::indicator {
width: 13px;
height: 13px;
}
QCheckBox::indicator:unchecked {
border: 1px solid #d4d4d4;
}
QCheckBox::indicator:checked {
background-color: #007acc;
border: 1px solid #007acc;
}
QListWidget {
background-color: #1e1e1e;
color: #d4d4d4;
border: 1px solid #2d2d2d;
}
QListWidget::item:hover {
background-color: #2d2d2d;
}
QListWidget::item:selected {
background-color: #264f78;
}
""")
# Syntax-Highlighting für dunkles Theme
for i in range(self.tabs.count()):
editor = self.tabs.widget(i)
if isinstance(editor, CodeEditor):
editor.update_theme("dark")
else:
# Helles Theme
self.setStyleSheet("""
QMainWindow {
background-color: white;
color: black;
}
QMenuBar {
background-color: white;
color: black;
}
QMenuBar::item:selected {
background-color: #e5e5e5;
}
QMenu {
background-color: white;
color: black;
border: 1px solid #c0c0c0;
}
QMenu::item:selected {
background-color: #e5e5e5;
}
QTabWidget::pane {
border: 1px solid #c0c0c0;
}
QTabBar::tab {
background-color: #f0f0f0;
color: black;
padding: 5px;
border: 1px solid #c0c0c0;
}
QTabBar::tab:selected {
background-color: white;
border-bottom: none;
}
QTreeView {
background-color: white;
color: black;
border: none;
}
QTreeView::item:hover {
background-color: #e5e5e5;
}
QTreeView::item:selected {
background-color: #cce8ff;
}
QTreeView::branch {
background-color: white;
}
QHeaderView::section {
background-color: #f0f0f0;
color: black;
padding: 5px;
border: none;
}
QStatusBar {
background-color: #f0f0f0;
color: black;
border-top: 1px solid #c0c0c0;
}
QSplitter::handle {
background-color: #e5e5e5;
}
QDialog {
background-color: white;
color: black;
}
QLabel {
color: black;
}
QPushButton {
background-color: #0078d7;
color: white;
border: none;
padding: 5px 10px;
}
QPushButton:hover {
background-color: #1084d7;
}
QPushButton:pressed {
background-color: #006cc1;
}
QLineEdit {
background-color: white;
color: black;
border: 1px solid #c0c0c0;
padding: 3px;
}
QSpinBox {
background-color: white;
color: black;
border: 1px solid #c0c0c0;
}
QComboBox {
background-color: white;
color: black;
border: 1px solid #c0c0c0;
padding: 3px;
}
QComboBox::drop-down {
border: none;
}
QComboBox::down-arrow {
image: none;
border-left: 3px solid none;
border-right: 3px solid none;
border-top: 6px solid black;
width: 0;
height: 0;
}
QComboBox QAbstractItemView {
background-color: white;
color: black;
selection-background-color: #cce8ff;
}
QGroupBox {
color: black;
border: 1px solid #c0c0c0;
margin-top: 5px;
}
QGroupBox::title {
color: black;
}
QCheckBox {
color: black;
}
QCheckBox::indicator {
width: 13px;
height: 13px;
}
QCheckBox::indicator:unchecked {
border: 1px solid black;
}
QCheckBox::indicator:checked {
background-color: #0078d7;
border: 1px solid #0078d7;
}
QListWidget {
background-color: white;
color: black;
border: 1px solid #c0c0c0;
}
QListWidget::item:hover {
background-color: #e5e5e5;
}
QListWidget::item:selected {
background-color: #cce8ff;
}
""")
# Syntax-Highlighting für helles Theme
for i in range(self.tabs.count()):
editor = self.tabs.widget(i)
if isinstance(editor, CodeEditor):
editor.update_theme("light")
def create_menu(self):
"""Erstellt die Menüleiste."""
menubar = self.menuBar()
# Datei-Menü
file_menu = menubar.addMenu(self.tr('File'))
new_file_action = QAction(self.tr('New File'), self)
new_file_action.setShortcut('Ctrl+N')
new_file_action.triggered.connect(self.new_file)
file_menu.addAction(new_file_action)
open_file_action = QAction(self.tr('Open File'), self)
open_file_action.setShortcut('Ctrl+O')
open_file_action.triggered.connect(self.open_file_dialog)
file_menu.addAction(open_file_action)
open_folder_action = QAction(self.tr('Open Folder'), self)
open_folder_action.setShortcut('Ctrl+K')
open_folder_action.triggered.connect(self.open_folder_dialog)
file_menu.addAction(open_folder_action)
save_file_action = QAction(self.tr('Save'), self)
save_file_action.setShortcut('Ctrl+S')
save_file_action.triggered.connect(self.save_file)
file_menu.addAction(save_file_action)
save_as_action = QAction(self.tr('Save As'), self)
save_as_action.setShortcut('Ctrl+Shift+S')
save_as_action.triggered.connect(self.save_file_as)
file_menu.addAction(save_as_action)
file_menu.addSeparator()
exit_action = QAction(self.tr('Exit'), self)
exit_action.setShortcut('Alt+F4')
exit_action.triggered.connect(self.close)
file_menu.addAction(exit_action)
# Bearbeiten-Menü
edit_menu = menubar.addMenu(self.tr('Edit'))
undo_action = QAction(self.tr('Undo'), self)
undo_action.setShortcut('Ctrl+Z')