From e985fec9c462e7aaa6175d99d1fec062a26ff9f5 Mon Sep 17 00:00:00 2001 From: Rastislav Kish Date: Wed, 10 Jul 2024 14:58:47 +0200 Subject: [PATCH] A11Y: Improve the accessibility of the Preferences dialog (#3255) * Configure buddy widgets for labels in the Preferences dialog Labels are often used to describe the purpose of a different widget like a combobox, edit field or a spinbox by providing a textual name for their functionality. The relation between a label and a widget is typically expressed by placing the label next to the relevant object. In addition to this visual linking intended for human users, frameworks usually also offer semantic way to link labels with other widgets, so the relation can be noticed by programs like screenreaders, which can figure out the correct textual description for the focused widgets based on this information. By default, labels on their own are not focusable elements, so users dependend on keyboard navigation and speech get to notice only the widget types (textbox, spinbox, etc.) while moving around without any contextual information if labels are not linked. When the linking is done, the component names get included as well. QT provides the "buddy" property for QLabel, which creates a semantic link between the label and its buddy widget. This commit configures the buddy properties on labels of the Anki Preferences dialog. * Configure spinbox suffixes in Preferrences dialog QSpinBox provides a suffix property. This property makes it possible to display a measurement unit next to the component value, which is linked to it both visually and semantically for the GUI framework without affecting the spinbox value itself. For purposes of accessibility, it's better to use this property than simply place a label next to the component, since it can be directly accessed by screenreaders and other assistive technology. This commit configures suffix properties for spinboxes in the Anki Preferences dialog. Note: Removal of the original unit labels may have altered the UI a little bit. * Assign buddy widgets in the ID and password retrieval dialog Set buddy widgets of the labels in the Get ID and password for synchronization dialog. * Fix positioning/size of text boxes * Style the suffixes of Preferences' QSpinBoxes Style QSpinBox suffixes (for those that have one) in the Preferences dialog by prepending them by a space character. --- CONTRIBUTORS | 1 + qt/aqt/forms/preferences.ui | 101 +++++++++++++++++++++--------------- qt/aqt/preferences.py | 7 +++ qt/aqt/sync.py | 2 + 4 files changed, 70 insertions(+), 41 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index d1db7eebc..bff13c38e 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -177,6 +177,7 @@ RRomeroJr <117.rromero@gmail.com> Xidorn Quan Alexander Bocken James Elmore +Rastislav Kish ******************** diff --git a/qt/aqt/forms/preferences.ui b/qt/aqt/forms/preferences.ui index 871c07f9b..671b45600 100644 --- a/qt/aqt/forms/preferences.ui +++ b/qt/aqt/forms/preferences.ui @@ -44,6 +44,9 @@ preferences_language + + lang + @@ -64,6 +67,9 @@ preferences_video_driver + + video_driver + @@ -116,6 +122,9 @@ preferences_style + + styleComboBox + @@ -123,6 +132,9 @@ preferences_theme + + theme + @@ -130,6 +142,9 @@ preferences_user_interface_size + + uiScale + @@ -264,33 +279,25 @@ - 60 + 16777215 16777215 + + preferences_mins + 999 - - - - preferences_mins - - - preferences_timebox_time_limit - - - - - - preferences_hours_past_midnight + + timeLimit @@ -298,10 +305,13 @@ - 60 + 16777215 16777215 + + preferences_hours_past_midnight + 23 @@ -312,6 +322,9 @@ preferences_learn_ahead_limit + + lrnCutoff + @@ -319,17 +332,16 @@ preferences_next_day_starts_at - - - - - - preferences_mins + + dayOffset + + preferences_mins + 9999 @@ -513,6 +525,9 @@ preferences_default_deck + + useCurrent + @@ -553,6 +568,9 @@ preferences_default_search_text + + default_search_text + @@ -705,10 +723,16 @@ preferences_network_timeout + + network_timeout + + + scheduling_seconds + 30 @@ -717,26 +741,6 @@ - - - - scheduling_seconds - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -853,6 +857,9 @@ preferences_custom_sync_url + + custom_sync_url + @@ -954,6 +961,9 @@ preferences_daily_backups + + daily_backups + @@ -968,6 +978,9 @@ preferences_monthly_backups + + monthly_backups + @@ -975,6 +988,9 @@ preferences_weekly_backups + + weekly_backups + @@ -982,6 +998,9 @@ preferences_minutes_between_backups + + minutes_between_backups + diff --git a/qt/aqt/preferences.py b/qt/aqt/preferences.py index b0af7cce2..f1dab502d 100644 --- a/qt/aqt/preferences.py +++ b/qt/aqt/preferences.py @@ -36,6 +36,13 @@ class Preferences(QDialog): self.prof = self.mw.pm.profile self.form = aqt.forms.preferences.Ui_Preferences() self.form.setupUi(self) + for spinbox in ( + self.form.lrnCutoff, + self.form.dayOffset, + self.form.timeLimit, + self.form.network_timeout, + ): + spinbox.setSuffix(f" {spinbox.suffix()}") disable_help_button(self) self.form.buttonBox.button(QDialogButtonBox.StandardButton.Help).setAutoDefault( False diff --git a/qt/aqt/sync.py b/qt/aqt/sync.py index ad1801c91..652fd3a2f 100644 --- a/qt/aqt/sync.py +++ b/qt/aqt/sync.py @@ -355,12 +355,14 @@ def get_id_and_pass_from_user( user = QLineEdit() user.setText(username) g.addWidget(user, 0, 1) + l1.setBuddy(user) l2 = QLabel(tr.sync_password_label()) g.addWidget(l2, 1, 0) passwd = QLineEdit() passwd.setText(password) passwd.setEchoMode(QLineEdit.EchoMode.Password) g.addWidget(passwd, 1, 1) + l2.setBuddy(passwd) vbox.addLayout(g) bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) # type: ignore bb.button(QDialogButtonBox.StandardButton.Ok).setAutoDefault(True)