vipmud.py
1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#appModules/vipmud.py
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2011 Willem Venter and Rynhardt Kruger
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
from NVDAObjects.window import edit
import ui
import appModuleHandler
import controlTypes
"""
App module for VIP Mud
This module makes NVDA read incoming text, as well as allowing the user to review the last nine messages with control 1 through 9.
"""
class AppModule(appModuleHandler.AppModule):
lastLength=0
msgs =[]
historyLength =9
def chooseNVDAObjectOverlayClasses(self, obj, clsList):
if controlTypes.STATE_READONLY in obj.states:
clsList.insert(0, MudText)
def __init__(self, *args, **kwargs):
super(AppModule, self).__init__(*args, **kwargs)
for n in xrange(1, self.historyLength +1):
self.bindGesture("kb:control+%s" % n, "readMessage")
def script_readMessage(self,gesture):
num=int(gesture.mainKeyName[-1])
try:
ui.message(self.msgs[num-1])
except IndexError:
ui.message(_("No message yet"))
script_readMessage.__doc__=_("Displays one of the recent messages")
class MudText(edit.Edit):
def event_valueChange(self):
text=self.windowText
nt =text[self.appModule.lastLength:]
ui.message(nt)
lines =nt.split("\n")
for line in lines:
line =line.strip()
if not line:
continue
self.appModule.msgs.insert(0, line)
del self.appModule.msgs[self.appModule.historyLength:]
self.appModule.lastLength =len(text)