speechViewer.py
4.17 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#speechViewer.py
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2006-2008 NVDA Contributors <http://www.nvda-project.org/>
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
import wx
import gui
import config
from logHandler import log
class SpeechViewerFrame(wx.Dialog):
def __init__(self, onDestroyCallBack):
dialogSize=wx.Size(w=500, h=500)
dialogPos=None
if not config.conf["speechViewer"]["autoPositionWindow"] and self.doDisplaysMatchConfig():
log.debug("Setting speechViewer window position")
speechViewSection = config.conf["speechViewer"]
dialogSize = wx.Size(w=speechViewSection["width"], h=speechViewSection["height"])
dialogPos = wx.Point(x=speechViewSection["x"], y=speechViewSection["y"])
super(SpeechViewerFrame, self).__init__(gui.mainFrame, wx.ID_ANY, _("NVDA Speech Viewer"), size=dialogSize, pos=dialogPos, style=wx.CAPTION | wx.RESIZE_BORDER | wx.STAY_ON_TOP)
self.onDestroyCallBack = onDestroyCallBack
self.Bind(wx.EVT_CLOSE, self.onClose)
self.Bind(wx.EVT_WINDOW_DESTROY, self.onDestroy)
sizer = wx.BoxSizer(wx.VERTICAL)
self.textCtrl = wx.TextCtrl(self, -1,style=wx.TE_RICH2|wx.TE_READONLY|wx.TE_MULTILINE)
sizer.Add(self.textCtrl, proportion=1, flag=wx.EXPAND)
# Translators: The label for a setting in the speech viewer that controls whether the speech viewer is shown at startup or not.
self.shouldShowOnStartupCheckBox = wx.CheckBox(self,wx.NewId(),label=_("&Show Speech Viewer on Startup"))
self.shouldShowOnStartupCheckBox.SetValue(config.conf["speechViewer"]["showSpeechViewerAtStartup"])
self.shouldShowOnStartupCheckBox.Bind(wx.EVT_CHECKBOX, self.onShouldShowOnStartupChanged)
sizer.Add(self.shouldShowOnStartupCheckBox, border=5, flag=wx.ALL)
# set the check box as having focus, by default the textCtrl has focus which stops the speechviewer output (even if another window is in focus)
self.shouldShowOnStartupCheckBox.SetFocus()
self.SetSizer(sizer)
self.Show(True)
#self.danilo = open('speech_log.txt', 'a+')
#self.danilo.write('janela abertaaaaaaa')
def onClose(self, evt):
#self.danilo.write('janela fechadaaa')
#self.danilo.close()
deactivate()
return
if not evt.CanVeto():
self.Destroy()
return
evt.Veto()
def onShouldShowOnStartupChanged(self, evt):
config.conf["speechViewer"]["showSpeechViewerAtStartup"] = self.shouldShowOnStartupCheckBox.IsChecked()
def onDestroy(self, evt):
log.debug("SpeechViewer destroyed")
self.savePositionInformation()
self.onDestroyCallBack()
evt.Skip()
def doDisplaysMatchConfig(self):
configSizes = config.conf["speechViewer"]["displays"]
attachedSizes = self.getAttachedDisplaySizesAsStringArray()
return len(configSizes) == len(attachedSizes) and all( configSizes[i] == attachedSizes[i] for i in xrange(len(configSizes)))
def getAttachedDisplaySizesAsStringArray(self):
displays = ( wx.Display(i).GetGeometry().GetSize() for i in xrange(wx.Display.GetCount()) )
return [repr( (i.width, i.height) ) for i in displays]
def savePositionInformation(self):
position = self.GetPosition()
config.conf["speechViewer"]["x"] = position.x
config.conf["speechViewer"]["y"] = position.y
size = self.GetSize()
config.conf["speechViewer"]["width"] = size.width
config.conf["speechViewer"]["height"] = size.height
config.conf["speechViewer"]["displays"] = self.getAttachedDisplaySizesAsStringArray()
config.conf["speechViewer"]["autoPositionWindow"] = False
_guiFrame=None
isActive=False
def activate():
global _guiFrame, isActive
_guiFrame = SpeechViewerFrame(_cleanup)
isActive=True
def appendText(text):
if not isActive:
return
if not isinstance(text,basestring):
return
#If the speech viewer text control has the focus, we want to disable updates
#Otherwise it would be impossible to select text, or even just read it (as a blind person).
if _guiFrame.FindFocus()==_guiFrame.textCtrl:
return
#self.danilo.write(text + "\n")
_guiFrame.textCtrl.AppendText(text + "\n")
def _cleanup():
global _guiFrame, isActive
if not isActive:
return
isActive=False
_guiFrame = None
def deactivate():
global _guiFrame, isActive
if not isActive:
return
_guiFrame.Destroy()
#global file
#file.close()