Skip to content

Commit

Permalink
Merge pull request #45 from dougollerenshaw/usability_improvements
Browse files Browse the repository at this point in the history
Some useability improvements
  • Loading branch information
dougollerenshaw authored Oct 5, 2024
2 parents 0f3dbd2 + 594cfc7 commit 21e2a64
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions codeaide/ui/chat_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def __init__(self, chat_handler):
self.waiting_for_api_key = False
self.chat_contents = []
self.setup_ui()
self.setup_input_placeholder()
self.update_submit_button_state()

# Check API key status
if not self.chat_handler.api_key_valid:
Expand Down Expand Up @@ -75,7 +77,7 @@ def setup_ui(self):
dropdown_widget = QWidget()
dropdown_layout = QHBoxLayout(dropdown_widget)
dropdown_layout.setContentsMargins(0, 0, 0, 0)
dropdown_layout.setSpacing(5) # Minimal spacing between items
dropdown_layout.setSpacing(5)

# Provider dropdown
self.provider_dropdown = QComboBox()
Expand Down Expand Up @@ -111,7 +113,7 @@ def setup_ui(self):
self.input_text.setStyleSheet(
f"background-color: {CHAT_WINDOW_BG}; color: {CHAT_WINDOW_FG}; border: 1px solid #ccc; padding: 5px;"
)
self.input_text.setAcceptRichText(False) # Add this line
self.input_text.setAcceptRichText(False)
self.input_text.setFont(general_utils.set_font(USER_FONT))
self.input_text.setFixedHeight(100)
self.input_text.textChanged.connect(self.on_modify)
Expand Down Expand Up @@ -140,6 +142,10 @@ def setup_ui(self):

self.logger.info("Chat window UI initialized")

def setup_input_placeholder(self):
self.placeholder_text = "Enter text here..."
self.input_text.setPlaceholderText(self.placeholder_text)

def eventFilter(self, obj, event):
if obj == self.input_text and event.type() == event.KeyPress:
if (
Expand Down Expand Up @@ -183,6 +189,8 @@ def on_submit(self):
self.logger.info("ChatWindow: Scheduling call_process_input_async")
QTimer.singleShot(100, lambda: self.call_process_input_async(user_input))

self.update_submit_button_state()

def call_process_input_async(self, user_input):
self.logger.info(
f"ChatWindow: call_process_input_async called with input: {user_input[:50]}..."
Expand All @@ -195,18 +203,27 @@ def call_process_input_async(self, user_input):

def on_modify(self):
self.input_text.ensureCursorVisible()
if self.input_text.toPlainText() == self.placeholder_text:
self.input_text.clear()
self.input_text.setStyleSheet(
f"background-color: {CHAT_WINDOW_BG}; color: {CHAT_WINDOW_FG}; border: 1px solid #ccc; padding: 5px;"
)
self.update_submit_button_state()

def add_to_chat(self, sender, message):
color = USER_MESSAGE_COLOR if sender == "User" else AI_MESSAGE_COLOR
font = USER_FONT if sender == "User" else AI_FONT
sender = AI_EMOJI if sender == "AI" else sender
html_message = general_utils.format_chat_message(sender, message, font, color)
self.chat_display.append(html_message + "<br>")

# Move cursor to the end of the document
cursor = self.chat_display.textCursor()
cursor.movePosition(cursor.End)
self.chat_display.setTextCursor(cursor)
self.chat_display.ensureCursorVisible()

self.logger.debug(
f"Adding message to chat from {sender}: {message}"
) # Log first 50 chars
self.logger.debug(f"Adding message to chat from {sender}: {message}")

# Add message to chat contents
self.chat_contents.append({"sender": sender, "message": message})
Expand Down Expand Up @@ -285,6 +302,7 @@ def load_example(self):
if example:
self.input_text.setPlainText(example)
self.input_text.moveCursor(self.input_text.textCursor().End)
self.input_text.setFocus()
else:
QMessageBox.information(self, "No Selection", "No example was selected.")

Expand All @@ -307,7 +325,7 @@ def closeEvent(self, event):
self.code_popup.terminal_manager.cleanup()

# Use a timer to allow for a short delay before closing
QTimer.singleShot(1000, self.force_close)
QTimer.singleShot(100, self.force_close)
event.ignore() # Prevent immediate closure

def force_close(self):
Expand Down Expand Up @@ -424,3 +442,6 @@ def show_traceback_dialog(self, traceback_text):
self.chat_handler.send_traceback_to_agent(traceback_text)
else:
self.logger.info("ChatWindow: User chose to ignore the traceback")

def update_submit_button_state(self):
self.submit_button.setEnabled(bool(self.input_text.toPlainText().strip()))

0 comments on commit 21e2a64

Please sign in to comment.