6
6
from keyboardHandler import KeyboardInputGesture
7
7
import addonHandler
8
8
import os
9
- import winsound
10
9
from gui import SettingsPanel , NVDASettingsDialog , guiHelper
11
10
import wx
12
11
import config
13
12
14
13
15
14
addonHandler .initTranslation ()
16
15
17
- path = os .path .abspath (os .path .join (os .path .dirname (os .path .dirname (__file__ )), "sounds" ))
18
16
19
17
20
- spec = {"record_sounds" : "boolean(default=true)" }
18
+
19
+ spec = {
20
+ "unread_focus" : "integer(default=0)" ,
21
+ "ignore_number" : "boolean(default=true)"
22
+ }
21
23
config .confspec ["whatsapp_enhansements" ] = spec
22
24
23
25
26
+
24
27
class SettingsPanel (SettingsPanel ):
25
28
title = "whatsapp enhansements"
26
29
def makeSettings (self , settingsSizer ):
27
30
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" ]
31
36
def postInit (self ):
32
- self .recordSounds .SetFocus ()
37
+ self .ignoreNumber .SetFocus ()
33
38
def onSave (self ):
34
39
for control in self .GetChildren ():
35
40
if type (control ) == wx .CheckBox :
36
41
config .conf ["whatsapp_enhansements" ][control .Name ] = control .Value
37
-
42
+ elif type (control ) == wx .Choice :
43
+ config .conf ["whatsapp_enhansements" ][control .Name ] = control .Selection
38
44
39
45
class AppModule (appModuleHandler .AppModule ):
40
46
def __init__ (self , * args , ** kwargs ):
41
47
super ().__init__ (* args , ** kwargs )
42
48
NVDASettingsDialog .categoryClasses .append (SettingsPanel )
49
+ self .message = None
43
50
def find (self , automationId ):
44
51
fg = api .getForegroundObject ().children [1 ]
45
52
for obj in fg .children :
@@ -53,7 +60,7 @@ def find(self, automationId):
53
60
def script_subtitles (self , gesture ):
54
61
obj = self .find ("TitleButton" )
55
62
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 ]))
57
64
else :
58
65
gesture .send ()
59
66
@@ -68,26 +75,13 @@ def script_info(self, gesture):
68
75
else :
69
76
gesture .send ()
70
77
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
-
83
78
@script (
84
79
gesture = "kb:control+o" ,
85
80
description = _ ("Attach item" ),
86
81
category = "whatsapp" )
87
82
def script_attach (self , gesture ):
88
83
obj = self .find ("AttachButton" )
89
84
if obj :
90
- message (obj .name )
91
85
obj .doAction ()
92
86
else :
93
87
gesture .send ()
@@ -98,7 +92,7 @@ def script_attach(self, gesture):
98
92
category = "whatsapp" )
99
93
def script_unread (self , gesture ):
100
94
def search (txt ):
101
- words = ["غير مقرو" , "unread" , "непрочитанное сообщение" , "Непрочитано" , "непрочитанных сообщений" , "Непрочитане" ]
95
+ words = ["غير مقرو" , "unread" ]
102
96
for word in words :
103
97
if txt .find (word ) != - 1 :
104
98
return word
@@ -107,30 +101,33 @@ def search(txt):
107
101
if obj :
108
102
for msg in obj .children [::- 1 ]:
109
103
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 ()
111
105
break
112
106
else :
113
- message ("There's no unread messages " )
107
+ message ("لا توجد رسائل جديدة غير مقروءة " )
114
108
else :
115
109
gesture .send ()
116
110
117
111
@script (
118
112
gesture = "kb:alt+m" ,
119
113
description = _ ("go to the messages list" ),
120
114
category = "whatsapp" )
115
+
121
116
def script_messagesList (self , gesture ):
122
117
obj = self .find ("ListView" )
123
118
if obj :
124
119
obj .lastChild .setFocus () if obj .childCount > 0 else obj .setFocus ()
125
120
else :
126
121
gesture .send ()
127
122
123
+
128
124
@script (
129
125
gesture = "kb:alt+c" ,
130
126
description = _ ("go to the chats list" ),
131
127
category = "whatsapp" )
132
128
def script_chatsList (self , gesture ):
133
129
obj = self .find ("ChatList" )
130
+
134
131
if obj :
135
132
for child in obj .children :
136
133
if any ([i .UIAAutomationId == "ChatsListItem" for i in child .children ]):
@@ -140,6 +137,7 @@ def script_chatsList(self, gesture):
140
137
gesture .send ()
141
138
return
142
139
140
+
143
141
for chat in chats .children :
144
142
if controlTypes .STATE_SELECTED in chat .states :
145
143
chat .setFocus ()
@@ -149,32 +147,6 @@ def script_chatsList(self, gesture):
149
147
else :
150
148
gesture .send ()
151
149
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
-
178
150
@script (
179
151
gesture = "kb:control+n" ,
180
152
description = _ ("new chat" ),
@@ -191,22 +163,33 @@ def script_newChat(self, gesture):
191
163
description = _ ("go to the typing message text field" ),
192
164
category = "whatsapp" )
193
165
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 ()
197
180
else :
198
- gesture .send ()
181
+ obj = self .find ("TextBox" )
182
+ obj .setFocus () if obj else gesture .send ()
199
183
200
184
@script (
201
185
gesture = "kb:control+r" ,
202
186
description = _ ("record voice notes" ),
203
187
category = "whatsapp" )
204
188
def script_record (self , gesture ):
189
+ txt = self .find ("TextBox" )
205
190
obj = self .find ("RightButton" ) or self .find ("PttSendButton" )
206
191
if obj and (obj .UIAAutomationId == "RightButton" and obj .firstChild .name == "\ue720 " ) or obj .UIAAutomationId == "PttSendButton" :
207
192
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 )
210
193
else :
211
194
gesture .send ()
212
195
@@ -218,12 +201,68 @@ def script_recordDelete(self, gesture):
218
201
obj = self .find ("PttDeleteButton" )
219
202
if obj :
220
203
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 ()
222
250
else :
223
251
gesture .send ()
224
252
225
253
226
254
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
+
227
266
def event_gainFocus (self , obj , nextHandler ):
228
267
if obj .name in ("WhatsApp.GroupParticipantsItemVm" , "WhatsApp.ChatListMessageSearchCellVm" , "WhatsApp.ChatListGroupSearchCellVm" , "WhatsApp.Pages.Recipients.UserRecipientItemVm" ):
229
268
obj .name = ", " .join ([m .name for m in obj .children ])
@@ -233,15 +272,29 @@ def event_gainFocus(self, obj, nextHandler):
233
272
obj .name = obj .previous .name + " " + obj .firstChild .children [1 ].name
234
273
elif obj .name == "WhatsApp.Design.ThemeData" :
235
274
obj .name = obj .children [1 ].name
236
- elif obj .UIAAutomationId == "BackButton" :
237
- obj .name = _ ("Back" )
238
275
elif obj .name == "\ue8bb " :
239
276
obj .name = _ ("Cancel reply" )
240
277
elif obj .UIAAutomationId == "SendMessages" :
241
278
obj .name = _ (obj .previous .name + ": " + obj .firstChild .name )
242
279
elif obj .UIAAutomationId == "EditInfo" :
243
280
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
244
295
296
+ if notificationName :
297
+ obj .name = obj .name .replace (name , "" )
245
298
nextHandler ()
246
299
def terminate (self ):
247
300
NVDASettingsDialog .categoryClasses .remove (SettingsPanel )
0 commit comments