Skip to content

Commit

Permalink
incubates #6202
Browse files Browse the repository at this point in the history
Speech viewer attempts to re-open with the same size at last location.
Re #5050

Merge branch 'i5050-RememberPositionOfSpeechViewer' into next
  • Loading branch information
feerrenrut committed Jul 29, 2016
2 parents 9b1f771 + 9017c3d commit 521ea12
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
7 changes: 7 additions & 0 deletions source/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ def validateConfig(configObj,validator,validationResult=None,keyList=None):
[speechViewer]
showSpeechViewerAtStartup = boolean(default=false)
autoPositionWindow = boolean(default=True)
# values for positioning the window. Defaults are not used. They should not be read if autoPositionWindow is True
x = integer()
y = integer()
width = integer()
height = integer()
displays = string_list()
#Keyboard settings
[keyboard]
Expand Down
33 changes: 30 additions & 3 deletions source/speechViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
class SpeechViewerFrame(wx.Dialog):

def __init__(self, onDestroyCallBack):
super(SpeechViewerFrame, self).__init__(gui.mainFrame, wx.ID_ANY, _("NVDA Speech Viewer"), style=wx.CAPTION | wx.RESIZE_BORDER | wx.STAY_ON_TOP)
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,size=(500,500),style=wx.TE_RICH2|wx.TE_READONLY|wx.TE_MULTILINE)
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"))
Expand All @@ -26,7 +33,6 @@ def __init__(self, onDestroyCallBack):
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()
sizer.Fit(self)
self.SetSizer(sizer)
self.Show(True)

Expand All @@ -43,7 +49,28 @@ def onShouldShowOnStartupChanged(self, evt):

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
Expand Down

0 comments on commit 521ea12

Please sign in to comment.