-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactautomatetoolv2.pyw
1125 lines (938 loc) · 35.5 KB
/
reactautomatetoolv2.pyw
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
"""
Modern React Project Automator
-----------------------------
A professional-grade desktop application for automating React project creation
with advanced features and industry-standard practices.
Author: Assistant
Version: 2.0.0
License: MIT
"""
import sys
import os
import subprocess
import shutil
import json
import git
import logging
from enum import Enum
from pathlib import Path
from datetime import datetime
from typing import Optional, Dict, List, Any
from dataclasses import dataclass
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QVBoxLayout, QLineEdit, QPushButton,
QLabel, QWidget, QMessageBox, QComboBox, QFileDialog, QHBoxLayout,
QFrame, QProgressDialog, QTabWidget, QScrollArea, QGridLayout,
QGroupBox, QSpinBox, QCheckBox, QTextEdit, QSplitter, QMenuBar,
QMenu, QAction, QStyle, QToolBar, QDialog, QDialogButtonBox,
QFileDialog, QInputDialog
)
from PyQt5.QtGui import (
QFont, QPalette, QColor, QLinearGradient, QBrush, QIcon,
QPainter, QPaintEvent, QFontDatabase, QTextCharFormat,
QSyntaxHighlighter, QTextCursor, QKeySequence
)
from PyQt5.QtCore import (
Qt, QThread, pyqtSignal, QSize, QTimer, QPropertyAnimation,
QEasingCurve, QRect, QProcess, QSettings, QPoint, QRegExp
)
from dataclasses import dataclass
# Application Constants
APP_NAME = "Modern React Project Automator"
APP_VERSION = "2.0.0"
ORGANIZATION_NAME = "ReactAutomator"
SETTINGS_FILE = "config.json"
@dataclass
class AppTheme:
"""Theme configuration for the application"""
name: str
background: str
text: str
primary: str
secondary: str
accent: str
terminal_background: str
terminal_text: str
@classmethod
def light(cls) -> 'AppTheme':
return cls(
name="light",
background="#ffffff",
text="#1f2937",
primary="#2563eb",
secondary="#4b5563",
accent="#3b82f6",
terminal_background="#1a1a1a",
terminal_text="#00ff00"
)
@classmethod
def dark(cls) -> 'AppTheme':
return cls(
name="dark",
background="#1f2937",
text="#ffffff",
primary="#3b82f6",
secondary="#9ca3af",
accent="#60a5fa",
terminal_background="#000000",
terminal_text="#00ff00"
)
class LogLevel(Enum): # LogLevel tanımlaması
INFO = "INFO"
WARNING = "WARNING"
ERROR = "ERROR"
SUCCESS = "SUCCESS"
DEBUG = "DEBUG"
@dataclass
class ProjectConfig:
"""Configuration for React project creation"""
name: str
template: str
dependencies: List[str]
dev_dependencies: List[str]
git_integration: bool
test_framework: str
styling_solution: str
typescript: bool
eslint: bool
prettier: bool
@classmethod
def create_default(cls) -> 'ProjectConfig':
return cls(
name="",
template="react",
dependencies=[],
dev_dependencies=[],
git_integration=True,
test_framework="jest",
styling_solution="Tailwind CSS",
typescript=True,
eslint=True,
prettier=True
)
class ProjectWorker(QThread):
"""Worker thread for project creation tasks"""
progress = pyqtSignal(int, str)
terminal_output = pyqtSignal(str, str)
finished = pyqtSignal(bool, str)
def __init__(self, config: ProjectConfig, npm_path: str, npx_path: str):
super().__init__()
self.config = config
self.npm_path = npm_path
self.npx_path = npx_path
self.logger = logging.getLogger("ProjectWorker")
def emit_log(self, message: str, level: str):
self.terminal_output.emit(message, level)
def run_process(self, command: List[str], shell: bool = False) -> bool:
"""Run a process and capture its output"""
process = QProcess()
process.setProcessChannelMode(QProcess.MergedChannels)
def handle_output():
output = process.readAll().data().decode()
self.terminal_output.emit(output, LogLevel.INFO)
process.readyReadStandardOutput.connect(handle_output)
process.readyReadStandardError.connect(handle_output)
if shell:
process.start(command[0], command[1:])
else:
process.start(command[0], command[1:])
process.waitForFinished()
return process.exitCode() == 0
def run(self):
"""Main worker thread execution"""
try:
self.progress.emit(0, "Initializing project...")
self.terminal_output.emit("Starting project creation...", "INFO")
# Create project directory
project_path = Path.cwd() / self.config.name
project_path.mkdir(parents=True, exist_ok=True)
# Create Vite project
self.progress.emit(20, "Creating Vite project...")
self.terminal_output.emit(
"Creating Vite project structure...",
LogLevel.INFO
)
template_suffix = "-ts" if self.config.typescript else ""
template = f"{self.config.template}{template_suffix}"
success = self.run_process([
self.npx_path,
"create-vite@latest",
self.config.name,
"--template",
template
])
if not success:
raise Exception("Failed to create Vite project")
# Change to project directory
os.chdir(project_path)
# Install dependencies
self.progress.emit(40, "Installing dependencies...")
self.terminal_output.emit(
"Installing project dependencies...",
LogLevel.INFO
)
success = self.run_process([self.npm_path, "install"])
if not success:
raise Exception("Failed to install dependencies")
# Setup additional features
self.progress.emit(60, "Setting up additional features...")
self.terminal_output.emit(
"Configuring project features...",
LogLevel.INFO
)
self.setup_features()
# Finalize setup
self.progress.emit(80, "Finalizing setup...")
self.terminal_output.emit(
"Finalizing project setup...",
LogLevel.INFO
)
self.setup_project_config()
# Git initialization
if self.config.git_integration:
self.setup_git()
self.progress.emit(100, "Project created successfully!")
self.terminal_output.emit(
"Project created successfully!",
LogLevel.SUCCESS
)
self.finished.emit(True, "Project created successfully!")
except Exception as e:
self.terminal_output.emit(str(e), LogLevel.ERROR)
self.finished.emit(False, str(e))
def setup_features(self):
"""Setup additional project features"""
try:
if self.config.typescript:
self.setup_typescript()
if self.config.test_framework:
self.setup_testing()
if self.config.styling_solution:
self.setup_styling()
if self.config.eslint or self.config.prettier:
self.setup_linting()
except Exception as e:
self.terminal_output.emit(
f"Error setting up features: {str(e)}",
LogLevel.ERROR
)
raise
def setup_typescript(self):
"""Configure TypeScript"""
self.terminal_output.emit(
"Setting up TypeScript configuration...",
LogLevel.INFO
)
tsconfig = {
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": True,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": False,
"skipLibCheck": True,
"esModuleInterop": False,
"allowSyntheticDefaultImports": True,
"strict": True,
"forceConsistentCasingInFileNames": True,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": True,
"isolatedModules": True,
"noEmit": True,
"jsx": "react-jsx"
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
with open("tsconfig.json", "w") as f:
json.dump(tsconfig, f, indent=2)
def setup_testing(self):
"""Configure testing framework"""
self.terminal_output.emit(
"Setting up testing configuration...",
LogLevel.INFO
)
# Install testing dependencies
test_deps = [
"@testing-library/react",
"@testing-library/jest-dom",
"@testing-library/user-event",
"vitest",
"jsdom",
]
success = self.run_process([
self.npm_path, "install", "-D",
*test_deps
])
if not success:
raise Exception("Failed to install testing dependencies")
# Create test setup file
test_setup = """
import '@testing-library/jest-dom'
import { expect, afterEach } from 'vitest'
import { cleanup } from '@testing-library/react'
afterEach(() => {
cleanup()
})
"""
os.makedirs("test", exist_ok=True)
with open("test/setup.ts", "w") as f:
f.write(test_setup.strip())
def setup_styling(self):
"""Configure styling solution"""
self.terminal_output.emit(
f"Setting up {self.config.styling_solution}...",
LogLevel.INFO
)
if self.config.styling_solution == "Tailwind CSS":
self.setup_tailwind()
elif self.config.styling_solution == "Styled Components":
self.setup_styled_components()
def setup_tailwind(self):
"""Configure Tailwind CSS"""
success = self.run_process([
self.npm_path, "install", "-D",
"tailwindcss",
"postcss",
"autoprefixer"
])
if not success:
raise Exception("Failed to install Tailwind CSS")
success = self.run_process([
self.npx_path, "tailwindcss", "init", "-p"
])
if not success:
raise Exception("Failed to initialize Tailwind CSS")
# Update tailwind.config.js
tailwind_config = {
"content": [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}"
],
"theme": {
"extend": {}
},
"plugins": []
}
with open("tailwind.config.js", "w") as f:
f.write(f"module.exports = {json.dumps(tailwind_config, indent=2)}")
def setup_styled_components(self):
"""Configure Styled Components"""
success = self.run_process([
self.npm_path, "install",
"styled-components"
])
if not success:
raise Exception("Failed to install Styled Components")
if self.config.typescript:
success = self.run_process([
self.npm_path, "install", "-D",
"@types/styled-components"
])
if not success:
raise Exception("Failed to install Styled Components types")
# Create theme file
theme_file = """
export const theme = {
colors: {
primary: '#2563eb',
secondary: '#4b5563',
background: '#ffffff',
text: '#1f2937',
},
breakpoints: {
sm: '640px',
md: '768px',
lg: '1024px',
xl: '1280px',
},
}
"""
os.makedirs("src/styles", exist_ok=True)
with open("src/styles/theme.ts", "w") as f:
f.write(theme_file.strip())
def setup_linting(self):
"""Configure ESLint and Prettier"""
if self.config.eslint:
self.terminal_output.emit(
"Setting up ESLint...",
LogLevel.INFO
)
eslint_deps = [
"eslint",
"eslint-plugin-react",
"eslint-plugin-react-hooks",
"@typescript-eslint/parser",
"@typescript-eslint/eslint-plugin"
]
success = self.run_process([
self.npm_path, "install", "-D",
*eslint_deps
])
if not success:
raise Exception("Failed to install ESLint")
eslint_config = {
"env": {
"browser": True,
"es2021": True
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": True
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"react",
"@typescript-eslint"
],
"rules": {
"react/react-in-jsx-scope": "off"
}
}
with open(".eslintrc.json", "w") as f:
json.dump(eslint_config, f, indent=2)
if self.config.prettier:
self.terminal_output.emit(
"Setting up Prettier...",
LogLevel.INFO
)
success = self.run_process([
self.npm_path, "install", "-D",
"prettier"
])
if not success:
raise Exception("Failed to install Prettier")
prettier_config = {
"semi": True,
"trailingComma": "es5",
"singleQuote": True,
"printWidth": 80,
"tabWidth": 2
}
with open(".prettierrc", "w") as f:
json.dump(prettier_config, f, indent=2)
def setup_git(self):
"""Initialize Git repository"""
self.terminal_output.emit(
"Initializing Git repository...",
LogLevel.INFO
)
try:
repo = git.Repo.init()
# Create .gitignore
gitignore = """
# Dependencies
node_modules
.pnp
.pnp.js
# Testing
coverage
# Production
build
dist
# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
# Debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor
.idea
.vscode
*.sublime-workspace
*.sublime-project
"""
with open(".gitignore", "w") as f:
f.write(gitignore.strip())
# Initial commit
repo.index.add(["."])
repo.index.commit("Initial commit")
self.terminal_output.emit(
"Git repository initialized successfully",
LogLevel.SUCCESS
)
except Exception as e:
self.terminal_output.emit(
f"Failed to initialize Git repository: {str(e)}",
LogLevel.ERROR
)
raise
class TerminalHighlighter(QSyntaxHighlighter):
"""Syntax highlighter for terminal output"""
def __init__(self, parent=None):
super().__init__(parent)
self.setup_formats()
def setup_formats(self):
"""Initialize text formats for different log levels"""
self.formats = {
"INFO": self.create_format("#ffffff"),
"WARNING": self.create_format("#fbbf24"),
"ERROR": self.create_format("#ef4444"),
"SUCCESS": self.create_format("#10b981"),
"DEBUG": self.create_format("#8b5cf6")
}
def create_format(self, color: str) -> QTextCharFormat:
"""Create text format with specified color"""
fmt = QTextCharFormat()
fmt.setForeground(QColor(color))
return fmt
def highlightBlock(self, text: str):
"""Highlight text block based on log level"""
for level, fmt in self.formats.items():
pattern = f"^\\[{level}\\].*$"
expression = QRegExp(pattern)
index = expression.indexIn(text)
while index >= 0:
length = expression.matchedLength()
self.setFormat(index, length, fmt)
index = expression.indexIn(text, index + length)
class TerminalOutput(QWidget):
"""Advanced terminal output widget with search and logging capabilities"""
def __init__(self, parent=None):
super().__init__(parent)
self.setup_ui()
self.setup_logging()
def setup_ui(self):
layout = QVBoxLayout(self)
# Toolbar
toolbar = QToolBar()
# Save action
save_action = QAction(
self.style().standardIcon(QStyle.SP_DialogSaveButton),
"Save Output",
self
)
save_action.triggered.connect(self.save_output)
toolbar.addAction(save_action)
# Search action
search_action = QAction(
self.style().standardIcon(QStyle.SP_FileDialogContentsView),
"Search",
self
)
search_action.triggered.connect(self.show_search_dialog)
toolbar.addAction(search_action)
# Clear action
clear_action = QAction(
self.style().standardIcon(QStyle.SP_TrashIcon),
"Clear",
self
)
clear_action.triggered.connect(self.clear_output)
toolbar.addAction(clear_action)
layout.addWidget(toolbar)
# Terminal output
self.output = QTextEdit()
self.output.setReadOnly(True)
self.highlighter = TerminalHighlighter(self.output.document())
layout.addWidget(self.output)
def setup_logging(self):
self.logger = logging.getLogger("TerminalOutput")
self.logger.setLevel(logging.DEBUG)
def save_output(self):
filename, _ = QFileDialog.getSaveFileName(
self,
"Save Terminal Output",
"",
"Text Files (*.txt);;Log Files (*.log)"
)
if filename:
try:
with open(filename, 'w') as f:
f.write(self.output.toPlainText())
self.logger.info(f"Output saved to {filename}")
except Exception as e:
self.logger.error(f"Failed to save output: {str(e)}")
def show_search_dialog(self):
dialog = SearchDialog(self)
if dialog.exec_() == QDialog.Accepted:
self.search_text(
dialog.search_input.text(),
dialog.case_sensitive.isChecked(),
dialog.forward_radio.isChecked()
)
def append_output(self, text: str, level: str = "INFO"):
cursor = self.output.textCursor()
cursor.movePosition(QTextCursor.End)
self.output.setTextCursor(cursor)
# Format message with log level
formatted_text = f"[{level}] {text}"
self.output.insertPlainText(formatted_text + "\n")
# Scroll to bottom
self.output.verticalScrollBar().setValue(
self.output.verticalScrollBar().maximum()
)
def clear_output(self):
self.output.clear()
self.logger.info("Terminal output cleared")
def search_text(self, text: str, case_sensitive: bool, forward: bool):
flags = QTextDocument.FindFlags()
if case_sensitive:
flags |= QTextDocument.FindCaseSensitively
if not forward:
flags |= QTextDocument.FindBackward
cursor = self.output.textCursor()
found = self.output.find(text, flags)
if found:
self.logger.info(f"Found text: {text}")
else:
self.logger.warning(f"Text not found: {text}")
class ModernReactAutomator(QMainWindow):
"""Main application window"""
def __init__(self):
super().__init__()
self.setWindowTitle(f"{APP_NAME} v{APP_VERSION}")
self.settings = QSettings(ORGANIZATION_NAME, APP_NAME)
self.current_theme = AppTheme.light()
self.init_ui()
self.setup_npm_paths()
self.project_config = ProjectConfig.create_default()
self.load_settings()
# UI initialization
self.terminal = None # Terminal değişkenini önce tanımla
self.init_ui() # Sonra UI'ı başlat
self.setup_npm_paths()
self.load_settings()
def init_ui(self):
"""Initialize user interface"""
self.setMinimumSize(1200, 800)
self.setup_fonts()
# Ana widget'ı oluştur
main_widget = QWidget()
self.setCentralWidget(main_widget)
# Splitter oluştur
splitter = QSplitter(Qt.Vertical)
# Üst widget (proje konfigürasyonu)
top_widget = QWidget()
top_layout = QVBoxLayout(top_widget)
self.setup_project_form(top_layout)
splitter.addWidget(top_widget)
# Terminal widget'ı oluştur
self.terminal = TerminalOutput()
splitter.addWidget(self.terminal)
# Splitter boyutlarını ayarla
splitter.setSizes([600, 200])
# Ana layout
main_layout = QVBoxLayout(main_widget)
main_layout.addWidget(splitter)
# Menu bar'ı en son ekle
self.setup_menu_bar()
self.apply_theme()
def setup_fonts(self):
"""Setup application fonts"""
default_font = QFont()
default_font.setPointSize(10)
self.setFont(default_font)
def setup_menu_bar(self):
"""Setup application menu bar"""
menubar = self.menuBar()
# File menu
file_menu = menubar.addMenu('&File')
new_action = QAction('&New Project', self)
new_action.setShortcut('Ctrl+N')
new_action.triggered.connect(self.create_project)
file_menu.addAction(new_action)
save_action = QAction('&Save Terminal Output', self)
save_action.setShortcut('Ctrl+S')
save_action.triggered.connect(self.terminal.save_output)
file_menu.addAction(save_action)
file_menu.addSeparator()
exit_action = QAction('&Exit', self)
exit_action.setShortcut('Ctrl+Q')
exit_action.triggered.connect(self.close)
file_menu.addAction(exit_action)
# Edit menu
edit_menu = menubar.addMenu('&Edit')
search_action = QAction('&Search Terminal', self)
search_action.setShortcut('Ctrl+F')
search_action.triggered.connect(self.terminal.show_search_dialog)
edit_menu.addAction(search_action)
clear_action = QAction('&Clear Terminal', self)
clear_action.setShortcut('Ctrl+L')
clear_action.triggered.connect(self.terminal.clear_output)
edit_menu.addAction(clear_action)
# View menu
view_menu = menubar.addMenu('&View')
theme_menu = view_menu.addMenu('&Theme')
light_action = QAction('&Light', self)
light_action.triggered.connect(lambda: self.change_theme(AppTheme.light()))
theme_menu.addAction(light_action)
dark_action = QAction('&Dark', self)
dark_action.triggered.connect(lambda: self.change_theme(AppTheme.dark()))
theme_menu.addAction(dark_action)
# Help menu
help_menu = menubar.addMenu('&Help')
about_action = QAction('&About', self)
about_action.triggered.connect(self.show_about_dialog)
help_menu.addAction(about_action)
def setup_main_widget(self):
"""Setup main application widget"""
main_widget = QWidget()
self.setCentralWidget(main_widget)
# Create vertical splitter
splitter = QSplitter(Qt.Vertical)
# Top widget (project configuration)
top_widget = QWidget()
top_layout = QVBoxLayout(top_widget)
self.setup_project_form(top_layout)
splitter.addWidget(top_widget)
# Bottom widget (terminal)
self.terminal = TerminalOutput()
splitter.addWidget(self.terminal)
# Set initial splitter sizes
splitter.setSizes([600, 200])
# Main layout
main_layout = QVBoxLayout(main_widget)
main_layout.addWidget(splitter)
def setup_project_form(self, layout: QVBoxLayout):
"""Setup project configuration form"""
# Project Configuration
config_group = QGroupBox("Project Configuration")
config_layout = QGridLayout()
# Project Name
name_label = QLabel("Project Name:")
self.name_input = QLineEdit()
self.name_input.setPlaceholderText("my-awesome-project")
self.name_input.textChanged.connect(self.update_project_config)
config_layout.addWidget(name_label, 0, 0)
config_layout.addWidget(self.name_input, 0, 1)
# Template
template_label = QLabel("Template:")
self.template_combo = QComboBox()
self.template_combo.addItems([
"react", "next", "remix", "gatsby"
])
self.template_combo.currentTextChanged.connect(self.update_project_config)
config_layout.addWidget(template_label, 1, 0)
config_layout.addWidget(self.template_combo, 1, 1)
config_group.setLayout(config_layout)
layout.addWidget(config_group)
# Features
features_group = QGroupBox("Features")
features_layout = QGridLayout()
self.typescript_check = QCheckBox("TypeScript")
self.eslint_check = QCheckBox("ESLint")
self.prettier_check = QCheckBox("Prettier")
self.testing_check = QCheckBox("Testing")
for check in [self.typescript_check, self.eslint_check,
self.prettier_check, self.testing_check]:
check.stateChanged.connect(self.update_project_config)
features_layout.addWidget(self.typescript_check, 0, 0)
features_layout.addWidget(self.eslint_check, 0, 1)
features_layout.addWidget(self.prettier_check, 1, 0)
features_layout.addWidget(self.testing_check, 1, 1)
features_group.setLayout(features_layout)
layout.addWidget(features_group)
# Styling
styling_group = QGroupBox("Styling Solution")
styling_layout = QVBoxLayout()
self.styling_combo = QComboBox()
self.styling_combo.addItems([
"Tailwind CSS",
"Styled Components",
"CSS Modules",
"None"
])
self.styling_combo.currentTextChanged.connect(self.update_project_config)
styling_layout.addWidget(self.styling_combo)
styling_group.setLayout(styling_layout)
layout.addWidget(styling_group)
# Git Integration
git_group = QGroupBox("Git Integration")
git_layout = QVBoxLayout()
self.git_check = QCheckBox("Initialize Git repository")
self.git_check.setChecked(True)
self.git_check.stateChanged.connect(self.update_project_config)
git_layout.addWidget(self.git_check)
git_group.setLayout(git_layout)
layout.addWidget(git_group)
# Action Buttons
buttons_layout = QHBoxLayout()
create_btn = QPushButton("Create Project")
create_btn.setStyleSheet("""
QPushButton {
background-color: #2563eb;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
font-weight: bold;
}
QPushButton:hover {
background-color: #1d4ed8;
}
QPushButton:pressed {
background-color: #1e40af;
}
""")
create_btn.clicked.connect(self.create_project)
clear_btn = QPushButton("Clear Form")
clear_btn.clicked.connect(self.clear_form)
buttons_layout.addWidget(clear_btn)
buttons_layout.addWidget(create_btn)
layout.addLayout(buttons_layout)
def update_project_config(self):
"""Update project configuration based on form values"""
self.project_config = ProjectConfig(
name=self.name_input.text(),
template=self.template_combo.currentText(),
dependencies=[],
dev_dependencies=[],
git_integration=self.git_check.isChecked(),
test_framework="jest" if self.testing_check.isChecked() else None,
styling_solution=self.styling_combo.currentText(),
typescript=self.typescript_check.isChecked(),
eslint=self.eslint_check.isChecked(),
prettier=self.prettier_check.isChecked()
)
def create_project(self):
"""Start project creation process"""
if not self.project_config.name:
QMessageBox.warning(
self,
"Validation Error",
"Project name is required!"
)
return
# Create worker thread
self.project_worker = ProjectWorker(
self.project_config,
self.npm_path,
self.npx_path
)
# Connect signals
self.project_worker.progress.connect(self.update_progress)
self.project_worker.terminal_output.connect(self.terminal.append_output)
self.project_worker.finished.connect(self.handle_completion)
# Show progress dialog
self.progress_dialog = QProgressDialog(
"Creating project...",
None,
0,
100,
self
)
self.progress_dialog.setWindowModality(Qt.WindowModal)
self.progress_dialog.setAutoClose(False)
self.progress_dialog.show()