fix: Fix hotkey thread-safety issue in Skill Scanner
BUG: TypeError when using F12 hotkey - invokeMethod syntax was wrong for PyQt6. FIX: 1. Added hotkey_triggered = pyqtSignal() at class level 2. Connected signal to _scan_page_for_multi in initialize() 3. _hotkey_scan() now just emits the signal (thread-safe) 4. Signal ensures scan runs on main Qt thread This is the proper Qt way to handle cross-thread communication. The hotkey callback runs in keyboard library's thread, but the scan must run in Qt's main thread to update UI safely.
This commit is contained in:
parent
e132a80f2b
commit
d0ccb791f7
|
|
@ -150,6 +150,9 @@ class SkillScannerPlugin(BasePlugin):
|
||||||
description = "Uses core OCR and Log services"
|
description = "Uses core OCR and Log services"
|
||||||
hotkey = "ctrl+shift+s"
|
hotkey = "ctrl+shift+s"
|
||||||
|
|
||||||
|
# Signal for thread-safe hotkey scanning
|
||||||
|
hotkey_triggered = pyqtSignal()
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
"""Setup skill scanner."""
|
"""Setup skill scanner."""
|
||||||
self.data_file = Path("data/skill_tracker.json")
|
self.data_file = Path("data/skill_tracker.json")
|
||||||
|
|
@ -164,6 +167,9 @@ class SkillScannerPlugin(BasePlugin):
|
||||||
self.current_scan_session = {} # Skills collected in current multi-page scan
|
self.current_scan_session = {} # Skills collected in current multi-page scan
|
||||||
self.pages_scanned = 0
|
self.pages_scanned = 0
|
||||||
|
|
||||||
|
# Connect hotkey signal
|
||||||
|
self.hotkey_triggered.connect(self._scan_page_for_multi)
|
||||||
|
|
||||||
# Subscribe to skill gain events from core Log service
|
# Subscribe to skill gain events from core Log service
|
||||||
try:
|
try:
|
||||||
from core.plugin_api import get_api
|
from core.plugin_api import get_api
|
||||||
|
|
@ -756,12 +762,9 @@ class SkillScannerPlugin(BasePlugin):
|
||||||
self.auto_scan_active = False
|
self.auto_scan_active = False
|
||||||
|
|
||||||
def _hotkey_scan(self):
|
def _hotkey_scan(self):
|
||||||
"""Scan triggered by F12 hotkey."""
|
"""Scan triggered by F12 hotkey - thread safe via signal."""
|
||||||
from PyQt6.QtCore import QMetaObject, Qt, Q_ARG
|
# Emit signal to safely call from hotkey thread
|
||||||
QMetaObject.invokeMethod(
|
self.hotkey_triggered.emit()
|
||||||
self, "_scan_page_for_multi",
|
|
||||||
Qt.ConnectionType.QueuedConnection
|
|
||||||
)
|
|
||||||
|
|
||||||
def _check_for_page_change(self):
|
def _check_for_page_change(self):
|
||||||
"""Auto-detect page changes by monitoring page number area."""
|
"""Auto-detect page changes by monitoring page number area."""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue