Skip to content

Fix unreliable stylesheet selector in highlight preview widget#69

Merged
JezaChen merged 4 commits into
masterfrom
dev-0.5.1/settings-sync-to-client
Apr 8, 2026
Merged

Fix unreliable stylesheet selector in highlight preview widget#69
JezaChen merged 4 commits into
masterfrom
dev-0.5.1/settings-sync-to-client

Conversation

@JezaChen

@JezaChen JezaChen commented Apr 8, 2026

Copy link
Copy Markdown
Owner

The _HighlightPreviewWidget was using a Python class-name CSS selector (_HighlightPreviewWidget { ... }), which is unreliable when the stylesheet is set on the widget itself.

Changes

  • Set WA_StyledBackground on the widget to enable stylesheet-driven painting (required for border-radius to render correctly on plain QWidget subclasses)
  • Replaced the class-name selector with a stable #objectName selector:
# Before
self.setStyleSheet("_HighlightPreviewWidget { border: 1px solid #aaa; }")

# After
self.setAttribute(QtCore.Qt.WA_StyledBackground, True)
self.setObjectName("highlightPreview")
self.setStyleSheet("#highlightPreview { border: 1px solid #aaa; border-radius: 4px; }")
  • Centered the hint label inside the preview area

…ETTINGS_CHANGED

Previously, client-relevant settings (e.g. highlight overlay color) were
only transmitted via CMD_ENABLE_INSPECT extra data, which was cleared on
disable_inspect(). This caused the highlight color to revert to default
when selecting widgets from control tree/hierarchy bar after inspect ended,
or when settings were changed without an active inspect session.

This commit introduces CMD_SETTINGS_CHANGED (1018) to immediately broadcast
client-relevant settings to all connected clients when the user saves
settings. Also stores highlight_color as a dedicated field on PyDB that
persists across inspect sessions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 8, 2026 12:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new server→client “settings changed” broadcast so connected clients can immediately pick up client-relevant settings updates (notably highlight overlay color), and updates the Settings UI with a live hover preview of the overlay.

Changes:

  • Introduce CMD_SETTINGS_CHANGED (1018) and plumbing to send/receive updated client settings at runtime.
  • Persist highlight_color on the client (PyDB) across inspect enable/disable cycles and update it via settings sync.
  • Add a settings-saved signal and a highlight overlay preview widget in the settings window.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
PyQtInspect/pqi.py Persist highlight color on PyDB and update it from inspect extra data + settings sync.
PyQtInspect/pqi_server_gui.py Build reusable client settings payload and broadcast it on settings save.
PyQtInspect/pqi_gui/workers/pqy_worker.py Add worker API to fan out settings-changed messages to all dispatchers.
PyQtInspect/pqi_gui/workers/dispatcher.py Add dispatcher method to send CMD_SETTINGS_CHANGED.
PyQtInspect/pqi_gui/windows/settings_window.py Add sigSettingsSaved + highlight overlay preview widget.
PyQtInspect/_pqi_bundle/pqi_comm.py Handle CMD_SETTINGS_CHANGED on the client and add message factory method.
PyQtInspect/_pqi_bundle/pqi_comm_constants.py Define CMD_SETTINGS_CHANGED = 1018 and add to ID_TO_MEANING.
Comments suppressed due to low confidence (1)

PyQtInspect/pqi_server_gui.py:606

  • Settings are only pushed to the client on save (CMD_SETTINGS_CHANGED) or when enabling inspect (extra_data). If a client connects and the user never enables inspect nor re-saves settings, highlight overlays triggered from the control tree/hierarchy will still use the client default color rather than the persisted SettingsController highlightColor. Consider sending _buildClientSettings() once on new dispatcher connection / initial handshake so the client starts with the correct settings even before any save/inspect action.
    def _buildClientSettings(self) -> dict:
        """ Build a dict of settings that need to be synced to the client. """
        return {
            'highlight_color': SettingsController.instance().highlightColor,
        }

    def _buildInspectExtraData(self) -> dict:
        return {
            'mock_left_button_down': self._isMockLeftButtonDownAction.isChecked(),
            **self._buildClientSettings(),
        }

    def _beginInspect(self):
        worker = self._getWorker()
        if not worker:
            return
        worker.sendEnableInspect(self._buildInspectExtraData())

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

super().__init__(parent)
self._highlightColor = QtGui.QColor(255, 0, 0, 51)

self.setStyleSheet("_HighlightPreviewWidget { border: 1px solid #aaa; }")

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

_HighlightPreviewWidget.setStyleSheet("_HighlightPreviewWidget { ... }") is unlikely to apply as intended because the selector may not match when the stylesheet is set on the widget itself (and Python subclass names/selectors can be unreliable). If the goal is just to draw a border around the preview, set the border style directly (no selector) or set a stable objectName and target it via #objectName to ensure the border consistently appears.

Suggested change
self.setStyleSheet("_HighlightPreviewWidget { border: 1px solid #aaa; }")
self.setStyleSheet("border: 1px solid #aaa;")

Copilot uses AI. Check for mistakes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bc6d571a50

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread PyQtInspect/pqi_server_gui.py Outdated
Comment on lines +643 to +646
def _onSettingsSaved(self):
worker = self._getWorker()
if worker:
worker.sendSettingsChanged(self._buildClientSettings())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Log settings sync broadcasts to connected clients

The new real-time sync path sends CMD_SETTINGS_CHANGED from _onSettingsSaved without any pqi_log entry, so when highlight-color updates appear stale there is no observable trace showing that the broadcast was attempted (or with what settings). For this feature, the save→broadcast step is a critical execution path, and missing logs here makes production diagnosis and regression triage significantly harder.

Useful? React with 👍 / 👎.

Comment thread PyQtInspect/pqi.py
Comment on lines +543 to +545
def on_settings_changed(self, settings: dict):
if 'highlight_color' in settings:
self._highlight_color = settings['highlight_color']

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Log client-side application of synced settings

on_settings_changed mutates runtime highlight behavior but does so silently, which leaves no evidence that a received CMD_SETTINGS_CHANGED was actually applied on the client. Because this is the endpoint of the new synchronization feature, the lack of logging on this branch makes it difficult to distinguish transport issues from apply-time issues when users report mismatched overlay colors.

Useful? React with 👍 / 👎.

…ings on connect

- Use #objectName selector for preview widget border to avoid unreliable
  Python class name matching
- Add pqi_log entries for server-side settings broadcast and client-side
  settings application
- Send client settings to newly connected clients on CMD_QT_PATCH_SUCCESS
  so they start with the correct highlight color before any inspect/save

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 8, 2026

Copy link
Copy Markdown

Deploying pyqtinspect-open with  Cloudflare Pages  Cloudflare Pages

Latest commit: 82afb5f
Status: ✅  Deploy successful!
Preview URL: https://b092b450.pyqtinspect-open.pages.dev
Branch Preview URL: https://dev-0-5-1-settings-sync-to-c.pyqtinspect-open.pages.dev

View logs

@JezaChen

JezaChen commented Apr 8, 2026

Copy link
Copy Markdown
Owner Author

@copilot review again, pls

@JezaChen JezaChen changed the title Add real-time settings sync from server to client Add real-time settings sync from server to client and change title of "Clear Logs" window Apr 8, 2026
…ectName selector in _HighlightPreviewWidget

Agent-Logs-Url: https://github.com/JezaChen/PyQtInspect-Open/sessions/ab36e99d-e962-4cf1-8c96-591e997106fc

Co-authored-by: JezaChen <31545780+JezaChen@users.noreply.github.com>

Copilot AI commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

@copilot review again, pls

Applied the reviewer's suggestion in commit 9ec7992 — replaced the #objectName { ... } selector in _HighlightPreviewWidget with a direct "border: 1px solid #aaa;" style (no selector), which is simpler and reliably applies to the widget itself.

Copilot AI changed the title Add real-time settings sync from server to client and change title of "Clear Logs" window Fix unreliable stylesheet selector in highlight preview widget Apr 8, 2026
- Add WA_StyledBackground comment explaining why it's needed
- Center-align the preview label text
- Add border-radius to preview widget border

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JezaChen

JezaChen commented Apr 8, 2026

Copy link
Copy Markdown
Owner Author

@copilot review again carefully

Copilot AI commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

@copilot review again carefully

Done a thorough review of all four commits. Here's the full picture:

Stylesheet selector — current code (82afb5f) uses WA_StyledBackground + setObjectName("highlightPreview") + "#highlightPreview { border: 1px solid #aaa; border-radius: 4px; }". This is the second approach the reviewer explicitly approved ("set a stable objectName and target it via #objectName"). WA_StyledBackground is the correct flag to enable stylesheet painting (including border-radius) on a plain QWidget subclass. The original class-name selector concern is resolved.

ProtocolCMD_SETTINGS_CHANGED (1018) is correctly defined, encoded, transmitted, and decoded on both sides, consistent with all existing JSON command handlers.

Client state_highlight_color on PyDB persists correctly across enable/disable cycles; enable_inspect preserves a previously synced value when highlight_color is absent from extra_data; on_settings_changed updates it on live broadcast.

Server-side sync_buildClientSettings() is correctly shared between _buildInspectExtraData and settings broadcast; _onSettingsSaved guard with if worker: is correct because DummyWorker.__bool__ returns False; sigSettingsSaved is connected exactly once on first window creation.

Overlay rendering — the _highlightOverlay child intentionally omits WA_StyledBackground, matching the production _createHighlightFg pattern in pqi_monkey_qt_helpers.py.

No remaining issues found.

@JezaChen JezaChen merged commit 9d57d54 into master Apr 8, 2026
2 checks passed
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.

3 participants