~stomato463/+junk/nvdajp

« back to all changes in this revision

Viewing changes to source/nvdajp_keyEvents.py

  • Committer: Masataka Shinke
  • Date: 2011-10-25 12:35:26 UTC
  • mfrom: (4185 jpmain)
  • mto: This revision was merged to the branch mainline in revision 4211.
  • Revision ID: mshinke@users.sourceforge.jp-20111025123526-ze527a2rl3z0g2ky
lp:~nishimotz/nvdajp/main : 4185 をマージ

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# coding: UTF-8
3
 
#nvdajp_keyEvents.py
4
 
#A part of NonVisual Desktop Access (NVDA)
5
 
# Masataka.Shinke
6
 
import pythoncom
7
 
import time
8
 
import threading
9
 
import winUser      # NVDA
10
 
import winInputHook # NVDA
11
 
import speech       # NVDA
12
 
import nvdajp_TSF   # Masataka.Shinke
13
 
import nvdajp_dic   # Masataka Shinke
14
 
 
15
 
import logHandler           # NVDA
16
 
import globalVars           # NVDA
17
 
from logHandler import log  # NVDA
18
 
 
19
 
global RunFlag
20
 
RunFlag = True
21
 
 
22
 
global Buff
23
 
Buff = u""
24
 
 
25
 
global LastKey
26
 
LastKey = 0
27
 
 
28
 
def TSF_Thread():
29
 
    global RunFlag
30
 
    global Buff
31
 
    global LastKey
32
 
    while RunFlag:
33
 
        TextValue = nvdajp_TSF.TSF_text().strip()
34
 
        if TextValue ==u"":
35
 
            TextValue = nvdajp_TSF.IMM_text().strip()
36
 
        ### if Buff!=TextValue:
37
 
        if (Buff!=TextValue)+((LastKey!=winUser.VK_SPACE)*(nvdajp_TSF.LastKeyCode()==winUser.VK_SPACE)) :
38
 
            if nvdajp_TSF.LastKeyCode() in [winUser.VK_RETURN]:
39
 
                speech.speakText(Buff)
40
 
            elif nvdajp_TSF.LastKeyCode() in [winUser.VK_SPACE]:
41
 
                for i in TextValue:
42
 
                    if nvdajp_dic.dic1.has_key(i):
43
 
                        speech.speakText(nvdajp_dic.dic1.get(i)[2])
44
 
                    else:
45
 
                        speech.speakText(i)
46
 
                speech.speakText(u"の")
47
 
                speech.speakText(TextValue)
48
 
            elif TextValue != u"":
49
 
                pos=0
50
 
                if len(TextValue)==1:
51
 
                    pos=0
52
 
                elif len(Buff)>len(TextValue):
53
 
                    pos=len(TextValue)-1
54
 
                else:
55
 
                    for i in Buff:
56
 
                        if i!=TextValue[pos]:
57
 
                            break;
58
 
                        pos+=1
59
 
                speech.speakText(TextValue[pos:])
60
 
            Buff = TextValue
61
 
            LastKey = nvdajp_TSF.LastKeyCode()
62
 
        time.sleep(.01)
63
 
 
64
 
def initialize():
65
 
    global RunFlag
66
 
    RunFlag = True
67
 
    nvdajp_TSF.initialize()
68
 
    threading.Thread(target=TSF_Thread, args=()).start()
69
 
 
70
 
def terminate():
71
 
    global RunFlag
72
 
    RunFlag = False
73
 
    nvdajp_TSF.terminate()
74