Fix some bugs when clicking on language names caused by the support for embedding

This commit is contained in:
Kovid Goyal 2024-10-09 09:31:48 +05:30
parent 97d476811a
commit 2e569b0a49
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -176,11 +176,12 @@ class Voices(QTreeWidget):
if column == 0 and item.parent() is not self.invisibleRootItem() and not self.ignore_item_changes:
if item.checkState(0) == Qt.CheckState.Checked:
p = item.parent()
for child in (p.child(i) for i in range(p.childCount())):
if child is not item and child.checkState(0) == Qt.CheckState.Checked:
self.ignore_item_changes = True
child.setCheckState(0, Qt.CheckState.Unchecked)
self.ignore_item_changes = False
if p is not None:
for child in (p.child(i) for i in range(p.childCount())):
if child is not item and child.checkState(0) == Qt.CheckState.Checked:
self.ignore_item_changes = True
child.setCheckState(0, Qt.CheckState.Unchecked)
self.ignore_item_changes = False
def mousePressEvent(self, event):
item = self.itemAt(event.pos())
@ -201,8 +202,9 @@ class Voices(QTreeWidget):
def set_item_downloaded_state(self, ans: QTreeWidgetItem) -> None:
voice = ans.data(0, Qt.ItemDataRole.UserRole)
is_downloaded = bool(voice and voice.engine_data and voice.engine_data.get('is_downloaded'))
ans.setFont(0, self.highlight_font if is_downloaded else self.normal_font)
if isinstance(voice, Voice):
is_downloaded = bool(voice and voice.engine_data and voice.engine_data.get('is_downloaded'))
ans.setFont(0, self.highlight_font if is_downloaded else self.normal_font)
def set_voices(
self, all_voices: tuple[Voice, ...], current_voice: str, engine_metadata: EngineMetadata,
@ -272,11 +274,13 @@ class Voices(QTreeWidget):
def current_voice(self) -> Voice | None:
ci = self.currentItem()
if ci is not None:
return ci.data(0, Qt.ItemDataRole.UserRole)
ans = ci.data(0, Qt.ItemDataRole.UserRole)
if isinstance(ans, Voice):
return ans
def refresh_current_item(self) -> None:
ci = self.currentItem()
if ci is not None:
if ci is not None and ci.parent() is not self.invisibleRootItem():
self.set_item_downloaded_state(ci)