Skip to content

Commit 82e82c2

Browse files
sulaiman al qusaimisulaiman al qusaimi
authored andcommitted
a lot of local changes
1 parent 54f548d commit 82e82c2

File tree

12 files changed

+186
-90
lines changed

12 files changed

+186
-90
lines changed

appModules/whatsapp.py

Lines changed: 113 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,47 @@
66
from keyboardHandler import KeyboardInputGesture
77
import addonHandler
88
import os
9-
import winsound
109
from gui import SettingsPanel, NVDASettingsDialog, guiHelper
1110
import wx
1211
import config
1312

1413

1514
addonHandler.initTranslation()
1615

17-
path = os.path.abspath(os.path.join(os.path.dirname(os.path.dirname(__file__)), "sounds"))
1816

1917

20-
spec = {"record_sounds": "boolean(default=true)"}
18+
19+
spec = {
20+
"unread_focus": "integer(default=0)",
21+
"ignore_number": "boolean(default=true)"
22+
}
2123
config.confspec["whatsapp_enhansements"] = spec
2224

2325

26+
2427
class SettingsPanel(SettingsPanel):
2528
title = "whatsapp enhansements"
2629
def makeSettings(self, settingsSizer):
2730
sHelper = guiHelper.BoxSizerHelper(self, sizer=settingsSizer)
28-
self.recordSounds = sHelper.addItem(wx.CheckBox(self, -1, "مؤثرات التسجيل", name="record_sounds"))
29-
self.recordSounds.Value = config.conf["whatsapp_enhansements"]["record_sounds"]
30-
31+
self.ignoreNumber = sHelper.addItem(wx.CheckBox(self, -1, _("ignore reading phone number for unknown contacts"), name="ignore_number"))
32+
self.ignoreNumber.Value = config.conf["whatsapp_enhansements"]["ignore_number"]
33+
sHelper.addItem(wx.StaticText(self, -1, _("focus position for the unread shortcut")))
34+
self.positions = sHelper.addItem(wx.Choice(self, -1, choices=[_("The first unread message"), _("messages count")], name="unread_focus"))
35+
self.positions.Selection = config.conf["whatsapp_enhansements"]["unread_focus"]
3136
def postInit(self):
32-
self.recordSounds.SetFocus()
37+
self.ignoreNumber.SetFocus()
3338
def onSave(self):
3439
for control in self.GetChildren():
3540
if type(control) == wx.CheckBox:
3641
config.conf["whatsapp_enhansements"][control.Name] = control.Value
37-
42+
elif type(control) == wx.Choice:
43+
config.conf["whatsapp_enhansements"][control.Name] = control.Selection
3844

3945
class AppModule(appModuleHandler.AppModule):
4046
def __init__(self, *args, **kwargs):
4147
super().__init__(*args, **kwargs)
4248
NVDASettingsDialog.categoryClasses.append(SettingsPanel)
49+
self.message = None
4350
def find(self, automationId):
4451
fg = api.getForegroundObject().children[1]
4552
for obj in fg.children:
@@ -53,7 +60,7 @@ def find(self, automationId):
5360
def script_subtitles(self, gesture):
5461
obj = self.find("TitleButton")
5562
if obj:
56-
message(", ".join([o.name for o in obj.children if len(o.name) < 50]))
63+
message(", ".join([o.name for o in obj.children]))
5764
else:
5865
gesture.send()
5966

@@ -68,26 +75,13 @@ def script_info(self, gesture):
6875
else:
6976
gesture.send()
7077

71-
@script(
72-
gesture="kb:alt+o",
73-
description=_("go to More options"),
74-
category="whatsapp")
75-
def script_options(self, gesture):
76-
obj = self.find("SettingsButton")
77-
if obj:
78-
message(obj.name)
79-
obj.doAction()
80-
else:
81-
gesture.send()
82-
8378
@script(
8479
gesture="kb:control+o",
8580
description=_("Attach item"),
8681
category="whatsapp")
8782
def script_attach(self, gesture):
8883
obj = self.find("AttachButton")
8984
if obj:
90-
message(obj.name)
9185
obj.doAction()
9286
else:
9387
gesture.send()
@@ -98,7 +92,7 @@ def script_attach(self, gesture):
9892
category="whatsapp")
9993
def script_unread(self, gesture):
10094
def search(txt):
101-
words = ["غير مقرو", "unread", "непрочитанное сообщение", "Непрочитано", "непрочитанных сообщений", "Непрочитане"]
95+
words = ["غير مقرو", "unread"]
10296
for word in words:
10397
if txt.find(word) != -1:
10498
return word
@@ -107,30 +101,33 @@ def search(txt):
107101
if obj:
108102
for msg in obj.children[::-1]:
109103
if len(msg.children) == 1 and search(msg.name) != -1:
110-
msg.next.setFocus()
104+
msg.next.setFocus() if config.conf["whatsapp_enhansements"]["unread_focus"] == 0 else msg.setFocus()
111105
break
112106
else:
113-
message("There's no unread messages")
107+
message("لا توجد رسائل جديدة غير مقروءة")
114108
else:
115109
gesture.send()
116110

117111
@script(
118112
gesture="kb:alt+m",
119113
description=_("go to the messages list"),
120114
category="whatsapp")
115+
121116
def script_messagesList(self, gesture):
122117
obj = self.find("ListView")
123118
if obj:
124119
obj.lastChild.setFocus() if obj.childCount > 0 else obj.setFocus()
125120
else:
126121
gesture.send()
127122

123+
128124
@script(
129125
gesture="kb:alt+c",
130126
description=_("go to the chats list"),
131127
category="whatsapp")
132128
def script_chatsList(self, gesture):
133129
obj = self.find("ChatList")
130+
134131
if obj:
135132
for child in obj.children:
136133
if any([i.UIAAutomationId == "ChatsListItem" for i in child.children]):
@@ -140,6 +137,7 @@ def script_chatsList(self, gesture):
140137
gesture.send()
141138
return
142139

140+
143141
for chat in chats.children:
144142
if controlTypes.STATE_SELECTED in chat.states:
145143
chat.setFocus()
@@ -149,32 +147,6 @@ def script_chatsList(self, gesture):
149147
else:
150148
gesture.send()
151149

152-
@script(
153-
gesture="kb:alt+shift+c",
154-
description=_("Press audio call button"),
155-
category="whatsapp")
156-
def script_audiocall(self, gesture):
157-
obj = self.find("AudioCallButton")
158-
audioname = self.find("TitleButton")
159-
if obj:
160-
message("Please wait, you will be connected with"+ " "+audioname.firstChild.name +" "+ "through an audio call.")
161-
obj.doAction()
162-
else:
163-
gesture.send()
164-
165-
@script(
166-
gesture="kb:alt+shift+v",
167-
description=_("Press video call button"),
168-
category="whatsapp")
169-
def script_vCall(self, gesture):
170-
obj = self.find("VideoCallButton")
171-
vName = self.find("TitleButton")
172-
if obj:
173-
message("Please wait, you will be connected with"+ " "+vName.firstChild.name +" "+ "through a video call.")
174-
obj.doAction()
175-
else:
176-
gesture.send()
177-
178150
@script(
179151
gesture="kb:control+n",
180152
description=_("new chat"),
@@ -191,22 +163,33 @@ def script_newChat(self, gesture):
191163
description=_("go to the typing message text field"),
192164
category="whatsapp")
193165
def script_messageField(self, gesture):
194-
obj = self.find("TextBox")
195-
if obj:
196-
obj.setFocus()
166+
167+
if not self.message and api.getFocusObject().UIAAutomationId == "TextBox":
168+
self.find("ListView").children[-1].setFocus()
169+
elif self.message and api.getFocusObject().UIAAutomationId == "TextBox":
170+
messages = self.find("ListView")
171+
try:
172+
index = messages.children.index(self.message)
173+
messages.children[index].setFocus()
174+
except ValueError:
175+
messages.children[-1].setFocus()
176+
self.message = None
177+
elif api.getFocusObject().UIAAutomationId == "BubbleListItem":
178+
self.message = api.getFocusObject()
179+
self.find("TextBox").setFocus()
197180
else:
198-
gesture.send()
181+
obj = self.find("TextBox")
182+
obj.setFocus() if obj else gesture.send()
199183

200184
@script(
201185
gesture="kb:control+r",
202186
description=_("record voice notes"),
203187
category="whatsapp")
204188
def script_record(self, gesture):
189+
txt = self.find("TextBox")
205190
obj = self.find("RightButton") or self.find("PttSendButton")
206191
if obj and (obj.UIAAutomationId == "RightButton" and obj.firstChild.name == "\ue720") or obj.UIAAutomationId == "PttSendButton":
207192
obj.doAction()
208-
if config.conf["whatsapp_enhansements"]["record_sounds"]:
209-
winsound.PlaySound(os.path.join(path, "record.wav"), 1) if obj.UIAAutomationId == "RightButton" else winsound.PlaySound(os.path.join(path, "stop.wav"), 1)
210193
else:
211194
gesture.send()
212195

@@ -218,12 +201,68 @@ def script_recordDelete(self, gesture):
218201
obj = self.find("PttDeleteButton")
219202
if obj:
220203
obj.doAction()
221-
winsound.PlaySound(os.path.join(path, "error.wav"), 1) if config.conf["whatsapp_enhansements"]["record_sounds"] else None
204+
else:
205+
gesture.send()
206+
207+
@script(
208+
gesture="kb:alt+shift+r",
209+
description=_("pause/resume voice note recording"),
210+
category="whatsapp")
211+
def script_recordPauseResume(self, gesture):
212+
obj = self.find("PttPauseButton") or self.find("PttResumeButton")
213+
if obj:
214+
obj.doAction()
215+
else:
216+
gesture.send()
217+
218+
@script(
219+
gesture="kb:alt+o",
220+
description=_("Activate the more options menu"),
221+
category="whatsapp")
222+
def script_options(self, gesture):
223+
obj = self.find("SettingsButton")
224+
if obj:
225+
obj.doAction()
226+
else:
227+
gesture.send()
228+
229+
@script(
230+
gesture="kb:alt+shift+c",
231+
description=_("Press audio call button"),
232+
category="whatsapp")
233+
def script_audiocall(self, gesture):
234+
obj = self.find("AudioCallButton")
235+
if obj:
236+
message(_("Calling. Please wait"))
237+
obj.doAction()
238+
else:
239+
gesture.send()
240+
241+
@script(
242+
gesture="kb:alt+shift+v",
243+
description=_("Press video call button"),
244+
category="whatsapp")
245+
def script_videoCall(self, gesture):
246+
obj = self.find("VideoCallButton")
247+
if obj:
248+
message(_("Calling. Please wait"))
249+
obj.doAction()
222250
else:
223251
gesture.send()
224252

225253

226254

255+
@script(
256+
gesture="kb:alt+shift+n",
257+
description=_("toggle reading number for unknown contacts behaviour"),
258+
category="whatsapp")
259+
def script_togleIgnoringNumbers(self, gesture):
260+
config.conf["whatsapp_enhansements"]["ignore_number"] = not config.conf["whatsapp_enhansements"]["ignore_number"]
261+
if config.conf["whatsapp_enhansements"]["ignore_number"]:
262+
message(_("ignore reading numbers for unknown contacts is on"))
263+
else:
264+
message(_("ignore reading numbers for unknown contacts is off"))
265+
227266
def event_gainFocus(self, obj, nextHandler):
228267
if obj.name in ("WhatsApp.GroupParticipantsItemVm", "WhatsApp.ChatListMessageSearchCellVm", "WhatsApp.ChatListGroupSearchCellVm", "WhatsApp.Pages.Recipients.UserRecipientItemVm"):
229268
obj.name = ", ".join([m.name for m in obj.children])
@@ -233,15 +272,29 @@ def event_gainFocus(self, obj, nextHandler):
233272
obj.name = obj.previous.name +" "+ obj.firstChild.children[1].name
234273
elif obj.name == "WhatsApp.Design.ThemeData":
235274
obj.name = obj.children[1].name
236-
elif obj.UIAAutomationId == "BackButton":
237-
obj.name = _("Back")
238275
elif obj.name == "\ue8bb":
239276
obj.name = _("Cancel reply")
240277
elif obj.UIAAutomationId == "SendMessages":
241278
obj.name = _(obj.previous.name +": "+ obj.firstChild.name)
242279
elif obj.UIAAutomationId == "EditInfo":
243280
obj.name = _(obj.previous.name +": "+ obj.firstChild.name)
281+
elif obj.name == "WhatsApp.Design.LightBoxExtendedTextItemVm":
282+
obj.name = obj.children[0].name
283+
elif obj.UIAAutomationId in ("NewMessagesNotificationSwitch", "WhenWAClosedSwitch"):
284+
obj.name = obj.previous.name
285+
elif obj.UIAAutomationId == "BubbleListItem":
286+
if config.conf["whatsapp_enhansements"]["ignore_number"]:
287+
notificationName = None
288+
name = None
289+
for item in obj.children:
290+
if name is None and item.UIAAutomationId == "NameTextBlock":
291+
name = item.name
292+
continue
293+
if notificationName is None and item.UIAAutomationId == "PushNameTextBlock":
294+
notificationName = item.name
244295

296+
if notificationName:
297+
obj.name = obj.name.replace(name, "")
245298
nextHandler()
246299
def terminate(self):
247300
NVDASettingsDialog.categoryClasses.remove(SettingsPanel)

locale/ar/lc_messages/nvda.mo

1.21 KB
Binary file not shown.

0 commit comments

Comments
 (0)