Skip to content

Commit

Permalink
Add screen reader feedback for copy action:
Browse files Browse the repository at this point in the history
- Integrated `UniversalSpeech.say` to announce "تم نسخ النص إلى الحافظة" when text is copied.
- This helps visually impaired users know the action was successful.
  • Loading branch information
MesterPerfect committed Nov 17, 2024
1 parent fd1f806 commit a6bacfa
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions ui/dialogs/info_dialog.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
import sys
from PyQt6.QtWidgets import QDialog, QVBoxLayout, QLabel, QTextEdit, QPushButton
from PyQt6.QtWidgets import QDialog, QVBoxLayout, QLabel, QTextEdit, QPushButton, QApplication
from PyQt6.QtCore import QTimer
from PyQt6.QtGui import QKeySequence
from PyQt6.QtGui import QKeySequence, QClipboard
from ui.widgets.qText_edit import ReadOnlyTextEdit
from utils.universal_speech import UniversalSpeech


class InfoDialog(QDialog):
def __init__(self, title: str, label: str, text: str, is_html_content: bool=False):
def __init__(self, title: str, label: str, text: str, is_html_content: bool = False):
super().__init__()
self.title = title
self.label = label
self.text = text
self.is_html_content = is_html_content
self.init_ui()


def init_ui(self):

self.setWindowTitle(self.title)
self.resize(400, 300)
self.setFocus()

label = QLabel(self.label, self)

text_edit = ReadOnlyTextEdit(self)
text_edit.setAccessibleName(self.label)
self.text_edit = ReadOnlyTextEdit(self)
self.text_edit.setAccessibleName(self.label)
if self.is_html_content:
text_edit.setHtml(self.text)
self.text_edit.setHtml(self.text)
else:
text_edit.setText(self.text)
self.text_edit.setText(self.text)

# Copy button
copy_button = QPushButton('نسخ', self)
copy_button.clicked.connect(self.copy_text)
copy_button.setShortcut(QKeySequence("Ctrl+C"))
copy_button.setStyleSheet('background-color: red; color: white;')

# close button

# Close button
close_button = QPushButton('إغلاق', self)
close_button.setShortcut(QKeySequence("Ctrl+W"))
close_button.clicked.connect(self.reject)
close_button.setStyleSheet(f'background-color: red; color: white;')
close_button.setStyleSheet('background-color: red; color: white;')

# Layout
layout = QVBoxLayout()
layout.addWidget(label)
layout.addWidget(text_edit)
layout.addWidget(self.text_edit)
layout.addWidget(copy_button)
layout.addWidget(close_button)
self.setLayout(layout)
QTimer.singleShot(300, text_edit.setFocus)

# Focus the text edit after dialog opens
QTimer.singleShot(300, self.text_edit.setFocus)

def copy_text(self):
clipboard = QApplication.clipboard()
clipboard.setText(self.text_edit.toPlainText())
clipboard.setText(self.text_edit.toPlainText())
UniversalSpeech.say("تم نسخ النص إلى الحافظة")

0 comments on commit a6bacfa

Please sign in to comment.