commit/windows7magnifier: josephsl: Refactor: huge refactor ot correct startup problem and to make inversion run on a different thread.

  • From: commits-noreply@xxxxxxxxxxxxx
  • To: nvda-addons-commits@xxxxxxxxxxxxx
  • Date: Sun, 16 Nov 2014 03:19:59 -0000

1 new commit in windows7magnifier:

https://bitbucket.org/nvdaaddonteam/windows7magnifier/commits/5df213e38807/
Changeset:   5df213e38807
Branch:      refactor
User:        josephsl
Date:        2014-11-16 03:19:11+00:00
Summary:     Refactor: huge refactor ot correct startup problem and to make 
inversion run on a different thread.
It turns out the add-on was calling start magnifier three times when starting. 
To prevent this from happening, the add-on will now check for handle to 
Magnifier before firing startup routine.

Affected #:  1 file

diff --git a/addon/globalPlugins/Windows7Magnifier/__init__.py 
b/addon/globalPlugins/Windows7Magnifier/__init__.py
index 01153e6..c424e97 100644
--- a/addon/globalPlugins/Windows7Magnifier/__init__.py
+++ b/addon/globalPlugins/Windows7Magnifier/__init__.py
@@ -116,7 +116,7 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
                # Launch the magnifier if it's configured to start w/ NVDA
                if Windows7MagnifierConfig.conf["magnifier"]["startWithNVDA"]:
                        self.configuring = True
-                       self.startMagnifier()
+                       self.startMagnifier(block=True)
                        self.configuring = False
                        ui.message(_("Magnifier launched"))
                self.configuring = False
@@ -138,11 +138,10 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
 
        def script_toggleMagnifier(self, gesture):
                if self.isMagnifierRunning():
+                       self.closeMagnifier()
                        # Translators: message presented when the magnifier is 
been closed.
                        ui.message(_("Closing magnifier"))
-                       # Pause so the speech can complete uninterrupted
                        time.sleep(1)
-                       self.closeMagnifier()
                else:
                        # Run start magnifier in a different thread so commands 
will not be blocked.
                        t = threading.Thread(target=self.startMagnifier)
@@ -180,7 +179,8 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
                # Windows does not automatically launch the magnifier for color
                # inversion, so we need to start it
                if not self.isMagnifierRunning():
-                       self.startMagnifier()
+                       t = threading.Thread(target = self.startMagnifier)
+                       t.start()
                # Simulate the Windows (built-in) hotkey for color inversion
                self._pressKey([winUser.VK_CONTROL, winUser.VK_MENU, 'i'])
                # Toggle in the config
@@ -263,7 +263,8 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
                                all are False
                """
                self.configuring = True
-               self.startMagnifier(block=True, applyConfig=False)
+               if not self._waitForMagnifierWindow():
+                       self.startMagnifier(block=True, applyConfig=False)
                if mode not in [self.detectCurrentMode(), None]:
                        hwnd = self._waitForMagnifierWindow()
                        if mode == "Fullscreen":
@@ -334,7 +335,8 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
                        (relevant) control in that window
                """
                # make sure the magnifier is running
-               self.startMagnifier(block=True, applyConfig=False)
+               if self.isMagnifierRunning():
+                       self.startMagnifier(block=True, applyConfig=False)
                # So... find the window
                mainWindow = self._waitForMagnifierWindow()
                self._showWindow(mainWindow, True)
@@ -446,8 +448,7 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
                                window
                        @param delayBetweenChecks: how long to pause between 
checks
                """
-               mainWindow = self._waitForWindow(windowClass="MagUIClass", 
windowName=None, maxChecks=maxChecks, delayBetweenChecks=delayBetweenChecks)
-               return mainWindow
+               return self._waitForWindow(windowClass="MagUIClass", 
maxChecks=maxChecks, delayBetweenChecks=delayBetweenChecks)
 
        def _waitForWindow(self, windowClass=None, windowName=None, 
maxChecks=100, delayBetweenChecks=0.1):
                """ Block until a given window is available
@@ -457,22 +458,23 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
                                window
                        @param delayBetweenChecks: how long to pause between 
checks
                """
-               if not windowClass:
+               if windowClass:
                        windowClass = windowClass.encode("ascii", "ignore")
-               if not windowName:
+               if windowName :
                        windowName = windowName.encode("ascii", "ignore")
                log.debug("Waiting for window '%s', '%s'" % (windowClass, 
windowName))
-               hwnd = 0
-               for i in range(maxChecks):
+               hwnd = winUser.user32.FindWindowA(windowClass, windowName)
+               if hwnd:
+                       return hwnd
+               for i in xrange(maxChecks):
                        # Play progress tones while magnifier is loading.
                        if i%10 == 0: tones.beep(440, 100)
-                       if hwnd == 0:
-                               hwnd = winUser.user32.FindWindowA(windowClass, 
windowName)
-                       if hwnd != 0:
-                               break
+                       hwnd = winUser.user32.FindWindowA(windowClass, 
windowName)
+                       if hwnd:
+                               return hwnd
                        else:
                                time.sleep(delayBetweenChecks)
-               return hwnd
+               return 0
 
        def _virtualizeKeys(self, keyCodes):
                """ Convert chars to their Virtual Key equivalents

Repository URL: https://bitbucket.org/nvdaaddonteam/windows7magnifier/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.

Other related posts:

  • » commit/windows7magnifier: josephsl: Refactor: huge refactor ot correct startup problem and to make inversion run on a different thread. - commits-noreply