-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_window.py
More file actions
118 lines (97 loc) · 4.77 KB
/
main_window.py
File metadata and controls
118 lines (97 loc) · 4.77 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
import os
from PyQt5.QtWidgets import (
QMainWindow, QSplitter, QTextEdit, QCheckBox, QVBoxLayout, QWidget, QMessageBox, QFileDialog, QPushButton, QLabel,
QApplication
)
from PyQt5.QtCore import Qt
from ui.file_tree import FileTreeWidget
from context_builder import build_context
from utils.settings_utils import load_settings, save_settings
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
# ADD THESE LINES for better visibility
font = QApplication.font()
font.setPointSize(11) # Increase from default (usually 9)
font.setFamily("Segoe UI") # Modern, readable font
QApplication.setFont(font)
self.setWindowTitle("Repo Prompt Tool")
self.setGeometry(100, 100, 800, 600)
# Load last folder from settings
self.settings = load_settings()
self.folder_path = self.settings.get("last_folder", "")
# Main splitter
self.splitter = QSplitter()
self.setCentralWidget(self.splitter)
# Left side: File tree and checkboxes
self.left_widget = QWidget()
self.left_layout = QVBoxLayout()
# File Picker Button
self.file_picker_button = QPushButton("Choose or Change Folder")
self.file_picker_button.clicked.connect(self.open_folder_dialog)
self.left_layout.addWidget(self.file_picker_button)
# Select All Checkbox
self.select_all_checkbox = QCheckBox("Select All")
self.select_all_checkbox.stateChanged.connect(self.toggle_select_all)
self.left_layout.addWidget(self.select_all_checkbox)
# File Tree Widget
self.file_tree = FileTreeWidget()
self.file_tree.itemChanged.connect(self.update_context)
self.left_layout.addWidget(self.file_tree)
# Include File Tree Checkbox
self.include_file_tree_checkbox = QCheckBox("Include File Tree")
self.include_file_tree_checkbox.setChecked(True)
self.include_file_tree_checkbox.stateChanged.connect(self.update_context)
self.left_layout.addWidget(self.include_file_tree_checkbox)
# Include File Content Checkbox
self.include_file_content_checkbox = QCheckBox("Include File Content")
self.include_file_content_checkbox.setChecked(True) # ADD THIS LINE
self.include_file_content_checkbox.stateChanged.connect(self.update_context)
self.left_layout.addWidget(self.include_file_content_checkbox)
self.left_widget.setLayout(self.left_layout)
self.splitter.addWidget(self.left_widget)
# Right side: Context Text Edit
self.right_widget = QWidget()
self.right_layout = QVBoxLayout()
self.text_edit = QTextEdit()
self.right_layout.addWidget(self.text_edit)
# Word Count Label
self.word_count_label = QLabel("Words: 0")
self.right_layout.addWidget(self.word_count_label)
# Copy Button
self.copy_button = QPushButton("Copy to Clipboard")
self.copy_button.clicked.connect(self.copy_to_clipboard)
self.right_layout.addWidget(self.copy_button)
self.right_widget.setLayout(self.right_layout)
self.splitter.addWidget(self.right_widget)
# Load folder if it exists
if self.folder_path and os.path.isdir(self.folder_path):
self.file_tree.populate_tree(self.folder_path)
def open_folder_dialog(self):
"""Open a folder selection dialog."""
folder_path = QFileDialog.getExistingDirectory(self, "Select Folder")
if folder_path:
self.folder_path = folder_path
self.settings["last_folder"] = folder_path
save_settings(self.settings)
self.file_tree.populate_tree(self.folder_path)
def toggle_select_all(self, state):
"""Toggle the selection of all files in the tree."""
self.file_tree.set_all_checkboxes(state)
def update_context(self):
"""Update the context text based on selected files and options."""
selected_files = self.file_tree.get_selected_files()
include_file_tree = self.include_file_tree_checkbox.isChecked()
include_file_content = self.include_file_content_checkbox.isChecked()
context = build_context(self.folder_path, selected_files, include_file_tree, include_file_content)
self.text_edit.setPlainText(context)
self.update_word_count(context)
def update_word_count(self, text):
"""Update the word count label."""
word_count = len(text.split())
self.word_count_label.setText(f"Words: {word_count}")
def copy_to_clipboard(self):
"""Copy the context text to the clipboard."""
clipboard = QApplication.clipboard()
clipboard.setText(self.text_edit.toPlainText())
QMessageBox.information(self, "Copied", "Context text copied to clipboard.")