Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the PyHTMX GUI client #73

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open

Conversation

femelo
Copy link

@femelo femelo commented Dec 29, 2024

This PR adds support for the PyHTMX GUI client.

Summary by CodeRabbit

  • New Features

    • Added support for a new "py-htmx" GUI framework.
    • Enhanced message handling for GUI websocket connections to accommodate changes in message structure.
  • Bug Fixes

    • Improved message data parsing to correctly extract framework information.

Copy link
Contributor

coderabbitai bot commented Dec 29, 2024

Walkthrough

The pull request introduces modifications to two files in the ovos_gui module. In bus.py, the on_message method of the GUIWebsocketHandler class is updated to access message data from a nested data key. In page.py, the get_file_extension static method of the GuiPage class is extended to support a new "py-htmx" framework, allowing it to return the "py" file extension for this specific framework.

Changes

File Change Summary
ovos_gui/bus.py Modified on_message method to extract msg_data from parsed_message.data.get('data', {}) instead of directly from parsed_message.data
ovos_gui/page.py Updated get_file_extension static method to return "py" extension when framework is "py-htmx"

Poem

🐰 A websocket whispers, data nested deep,
Pages dancing with frameworks that leap,
HTMX joins the GUI's merry band,
Extensions growing, hand in hand!
Code hops forward with playful might 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de2dcfd and 71d0df2.

📒 Files selected for processing (1)
  • ovos_gui/bus.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ovos_gui/bus.py

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
ovos_gui/bus.py (1)

Protocol documentation needs to be updated with current message structure

Based on the code analysis, I can confirm that:

  1. The protocol documentation in protocol.md is outdated and doesn't reflect the current message structure
  2. The actual implementation in ovos_gui/namespace.py shows the message contains:
    • gui_id at the root level
    • framework field for new API
    • qt_version for legacy API

The protocol documentation should be updated to show:

{
    "type": "mycroft.gui.connected",
    "gui_id": "unique_identifier_provided_by_client",
    "data": {
        "framework": "qt6|qt5",  // new API
        "qt_version": "5|6"      // legacy API
    }
}
🔗 Analysis chain

Line range hint 204-214: Document protocol changes and verify message structure

The change in message structure (nested 'data' field) represents a protocol change that should be documented. Additionally, we should verify the message structure usage across the codebase.

Consider adding a comment documenting the expected message structure:

# Message structure for 'mycroft.gui.connected':
# {
#     'type': 'mycroft.gui.connected',
#     'data': {
#         'data': {
#             'framework': str,  # new API
#             'qt_version': int  # legacy API
#         }
#     }
# }

Protocol documentation exists but needs to be updated with new message structure

The protocol documentation exists in protocol.md but doesn't reflect the current message structure with the nested 'data' field and framework/qt_version fields. The documentation should be updated to match the actual implementation.

  • protocol.md: Update the mycroft.gui.connected message structure to include:
    • The nested 'data' field
    • The 'framework' field for new API
    • The 'qt_version' field for legacy API

Let me verify the complete message structure in the codebase:


Let me try one more search to find where these messages are constructed:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for message structure usage
echo "Checking message structure usage..."
rg -A 5 "mycroft\.gui\.connected"

# Search for protocol documentation
echo "Checking for protocol documentation..."
fd -t f "README|PROTOCOL|transportProtocol" -X cat

Length of output: 4523


Script:

#!/bin/bash
# Search for message structure construction
echo "Checking message construction..."
rg -A 5 "mycroft\.gui\.connected.*data" 

# Search for message parsing
echo "Checking message parsing..."
ast-grep --pattern 'parsed_message.data["data"]'

Length of output: 232


Script:

#!/bin/bash
# Search for message construction in GUI clients
echo "Checking GUI client message construction..."
rg -l "gui.*connected" --type py | xargs rg -A 10 "emit.*connected"

# Search for message handling
echo "Checking message handling..."
rg -A 10 "handle_client_connected"

Length of output: 2406

🧹 Nitpick comments (1)
ovos_gui/page.py (1)

33-36: Remove redundant else block

The empty else: pass block is redundant since it's followed by return "". This can be simplified.

 elif framework in ("py-htmx", ):
     return "py"
-else:
-    pass
 return ""
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ff2777 and de2dcfd.

📒 Files selected for processing (2)
  • ovos_gui/bus.py (1 hunks)
  • ovos_gui/page.py (1 hunks)
🔇 Additional comments (1)
ovos_gui/page.py (1)

33-34: Verify framework string constant usage

The framework identifier "py-htmx" should be consistently used across the codebase. Let's verify this.

✅ Verification successful

Let me check the actual framework-related code in these files to ensure consistency.


Framework string usage is consistent and well-handled

The codebase consistently handles framework identifiers, including "py-htmx". The framework handling is implemented with proper fallbacks and clear logic:

  • In page.py, "py-htmx" is correctly used in the file extension mapping
  • Framework handling includes proper support for:
    • "qt5" (default)
    • "qt6"
    • "py-htmx"
  • The codebase has a robust framework detection system that handles both new API (framework parameter) and legacy API (qt_version parameter)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for framework string usage
echo "Searching for py-htmx framework string usage..."
rg -l "py-htmx"

# Search for framework-related constants
echo "Checking for framework-related constants..."
rg -l "FRAMEWORK|framework.*=.*['\"]"

Length of output: 358


Script:

#!/bin/bash
# Check content of files with framework references
echo "Content of ovos_gui/page.py:"
rg -A 2 -B 2 "framework" ovos_gui/page.py

echo -e "\nContent of ovos_gui/bus.py:"
rg -A 2 -B 2 "framework" ovos_gui/bus.py

echo -e "\nContent of ovos_gui/namespace.py:"
rg -A 2 -B 2 "framework" ovos_gui/namespace.py

echo -e "\nContent of test/unittests/test_bus.py:"
rg -A 2 -B 2 "framework" test/unittests/test_bus.py

Length of output: 6196

ovos_gui/bus.py Outdated Show resolved Hide resolved
ovos_gui/bus.py Outdated
@@ -201,7 +201,7 @@ def on_message(self, message: str):
default_qt_version = \
Configuration().get('gui', {}).get('default_qt_version') or 5
msg_type = parsed_message.msg_type
msg_data = parsed_message.data
msg_data = parsed_message.data['data']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain this change?

Copy link
Author

@femelo femelo Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a misunderstanding on my part because of an omission in the protocol documentation. The protocol defines the client announcing message as:

{
    "type": "mycroft.gui.connected",
    "gui_id": "unique_identifier_provided_by_client"
}

but it does not mention whether reporting the framework attribute should be at the root of the message or under the key data (as a payload). By the sake of similarity, I assumed the message would probably look like a session message (or as the page_gained_focus event message), which is treated by the socket handler like this:

msg_data = parsed_message.data['data']

Since I was not sure, I put both options in the announcing message from the client - https://github.com/femelo/pyhtmx-gui-client/blob/20ffc157931709db7573162d479577e07b0da933/src/pyhtmx_gui/ovos_gui_client.py#L48 - but I haven't had time to discuss it with you.
So, which option should I use?

@femelo femelo requested a review from JarbasAl January 2, 2025 12:00
@JarbasAl
Copy link
Member

JarbasAl commented Jan 2, 2025

to add support for a new GUI we need to also include all templates

all the files prefixed with SYSTEM here need an equivalent for the new GUI https://github.com/OpenVoiceOS/ovos-gui/tree/dev/ovos_gui/res/gui/qt5 (the others can be ignores, they are just implementation details of the SYSTEM_XXX qmls)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants