From 295675d80025789780a77b1e91885fa59d715ae6 Mon Sep 17 00:00:00 2001 From: Reef Turner Date: Fri, 22 Jul 2016 15:33:18 +0800 Subject: [PATCH 1/3] Remember the position and size of the speechViewer The speechViewer window will open in the same location at the same size as it was when previously closed. If the monitor setup has changed (resolution, or number of monitors) the window is auto positioned/sized. --- source/config/__init__.py | 3 +++ source/speechViewer.py | 42 +++++++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/source/config/__init__.py b/source/config/__init__.py index c539b62e386..3426a7fd1fc 100644 --- a/source/config/__init__.py +++ b/source/config/__init__.py @@ -135,6 +135,9 @@ def validateConfig(configObj,validator,validationResult=None,keyList=None): audioCoordinates_maxPitch = integer(default=880) reportMouseShapeChanges = boolean(default=false) +[speechView] + autoPositionWindow = boolean(default=True) + #Keyboard settings [keyboard] useCapsLockAsNVDAModifierKey = boolean(default=false) diff --git a/source/speechViewer.py b/source/speechViewer.py index b8f2fdeded4..e68a3815321 100644 --- a/source/speechViewer.py +++ b/source/speechViewer.py @@ -6,16 +6,25 @@ import wx import gui +import config +from logHandler import log -class SpeechViewerFrame(wx.MiniFrame): +class SpeechViewerFrame(wx.Dialog): def __init__(self): - 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["speechView"]["autoPositionWindow"] and self.doDisplaysMatchConfig(): + log.debug("Setting speechViewer window position") + speechViewSection = config.conf["speechView"] + dialogSize = wx.Size(w=int(speechViewSection["width"]), h=int(speechViewSection["height"])) + dialogPos = wx.Point(x=int(speechViewSection["x"]), y=int(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.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) - sizer.Fit(self) self.SetSizer(sizer) self.Show(True) @@ -27,6 +36,31 @@ def onClose(self, evt): return evt.Veto() + def onDestroy(self, evt): + log.debug("SpeechViewer Destroyed") + self.savePositionInformation() + evt.Skip() + + def doDisplaysMatchConfig(self): + configSizes = config.conf["speechView"]["displays"] + attachedSizes = self.getAttachedDisplaySizes() + convertedAttachedSizes = [repr( (i.width, i.height) ) for i in attachedSizes] + return len(configSizes) == len(attachedSizes) and all( configSizes[i] == convertedAttachedSizes[i] for i in range(0, len(configSizes))) + + def getAttachedDisplaySizes(self): + displays = (wx.Display(i) for i in range(wx.Display.GetCount())) + return [display.GetGeometry().GetSize() for display in displays] + + def savePositionInformation(self): + position = self.GetPosition() + config.conf["speechView"]["x"] = position.x + config.conf["speechView"]["y"] = position.y + size = self.GetSize() + config.conf["speechView"]["width"] = size.width + config.conf["speechView"]["height"] = size.height + config.conf["speechView"]["displays"] = self.getAttachedDisplaySizes() + config.conf["speechView"]["autoPositionWindow"] = False + _guiFrame=None isActive=False From 78b23ebe4282d73531aad8b737c93bdd668f98f7 Mon Sep 17 00:00:00 2001 From: Reef Turner Date: Thu, 28 Jul 2016 17:55:17 +0800 Subject: [PATCH 2/3] review actions for #6202 Added speechViewer x,y,width,height,displays to the config schema. Tested with configuration profiles. --- source/config/__init__.py | 8 +++++++- source/speechViewer.py | 29 +++++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/source/config/__init__.py b/source/config/__init__.py index 3426a7fd1fc..742cf2e3778 100644 --- a/source/config/__init__.py +++ b/source/config/__init__.py @@ -135,8 +135,14 @@ def validateConfig(configObj,validator,validationResult=None,keyList=None): audioCoordinates_maxPitch = integer(default=880) reportMouseShapeChanges = boolean(default=false) -[speechView] +[speechViewer] 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] diff --git a/source/speechViewer.py b/source/speechViewer.py index e68a3815321..3ee31d7d379 100644 --- a/source/speechViewer.py +++ b/source/speechViewer.py @@ -14,9 +14,9 @@ class SpeechViewerFrame(wx.Dialog): def __init__(self): dialogSize=wx.Size(w=500, h=500) dialogPos=None - if not config.conf["speechView"]["autoPositionWindow"] and self.doDisplaysMatchConfig(): + if not config.conf["speechViewer"]["autoPositionWindow"] and self.doDisplaysMatchConfig(): log.debug("Setting speechViewer window position") - speechViewSection = config.conf["speechView"] + speechViewSection = config.conf["speechViewer"] dialogSize = wx.Size(w=int(speechViewSection["width"]), h=int(speechViewSection["height"])) dialogPos = wx.Point(x=int(speechViewSection["x"]), y=int(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) @@ -42,24 +42,25 @@ def onDestroy(self, evt): evt.Skip() def doDisplaysMatchConfig(self): - configSizes = config.conf["speechView"]["displays"] - attachedSizes = self.getAttachedDisplaySizes() - convertedAttachedSizes = [repr( (i.width, i.height) ) for i in attachedSizes] - return len(configSizes) == len(attachedSizes) and all( configSizes[i] == convertedAttachedSizes[i] for i in range(0, len(configSizes))) + configSizes = config.conf["speechViewer"]["displays"] + attachedSizes = self.getAttachedDisplaySizesAsStringArray() + return len(configSizes) == len(attachedSizes) and all( configSizes[i] == attachedSizes[i] for i in range(0, len(configSizes))) - def getAttachedDisplaySizes(self): + def getAttachedDisplaySizesAsStringArray(self): displays = (wx.Display(i) for i in range(wx.Display.GetCount())) - return [display.GetGeometry().GetSize() for display in displays] + displays = [display.GetGeometry().GetSize() for display in displays] + return [repr( (i.width, i.height) ) for i in displays] + def savePositionInformation(self): position = self.GetPosition() - config.conf["speechView"]["x"] = position.x - config.conf["speechView"]["y"] = position.y + config.conf["speechViewer"]["x"] = position.x + config.conf["speechViewer"]["y"] = position.y size = self.GetSize() - config.conf["speechView"]["width"] = size.width - config.conf["speechView"]["height"] = size.height - config.conf["speechView"]["displays"] = self.getAttachedDisplaySizes() - config.conf["speechView"]["autoPositionWindow"] = False + 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 From 9017c3de726cbaa68db389e26189a955c619a1f2 Mon Sep 17 00:00:00 2001 From: Reef Turner Date: Fri, 29 Jul 2016 11:50:36 +0800 Subject: [PATCH 3/3] Further review actions #6202 Remove unnecessary casts to int when reading the config. Tidy up generator code. --- source/speechViewer.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/speechViewer.py b/source/speechViewer.py index 3ee31d7d379..b614e162fbe 100644 --- a/source/speechViewer.py +++ b/source/speechViewer.py @@ -17,8 +17,8 @@ def __init__(self): if not config.conf["speechViewer"]["autoPositionWindow"] and self.doDisplaysMatchConfig(): log.debug("Setting speechViewer window position") speechViewSection = config.conf["speechViewer"] - dialogSize = wx.Size(w=int(speechViewSection["width"]), h=int(speechViewSection["height"])) - dialogPos = wx.Point(x=int(speechViewSection["x"]), y=int(speechViewSection["y"])) + 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.Bind(wx.EVT_CLOSE, self.onClose) self.Bind(wx.EVT_WINDOW_DESTROY, self.onDestroy) @@ -44,11 +44,10 @@ def onDestroy(self, evt): 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 range(0, len(configSizes))) + return len(configSizes) == len(attachedSizes) and all( configSizes[i] == attachedSizes[i] for i in xrange(len(configSizes))) def getAttachedDisplaySizesAsStringArray(self): - displays = (wx.Display(i) for i in range(wx.Display.GetCount())) - displays = [display.GetGeometry().GetSize() for display in displays] + displays = ( wx.Display(i).GetGeometry().GetSize() for i in xrange(wx.Display.GetCount()) ) return [repr( (i.width, i.height) ) for i in displays]