Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of _resumeDetection method on the braille handler #2

Merged
merged 4 commits into from Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions source/bdDetect.py
Expand Up @@ -172,8 +172,9 @@ def __init__(self, usb=True, bluetooth=True, limitToDevices=None):
self._stopEvent = threading.Event()
self._queuedScanLock = threading.Lock()
self._scanQueued = False
self._detectUsb = False
self._detectBluetooth = False
self._detectUsb = usb
self._detectBluetooth = bluetooth
self._limitToDevices = limitToDevices
self._runningApcLock = threading.Lock()
# Perform initial scan.
self._startBgScan(usb=usb, bluetooth=bluetooth, limitToDevices=limitToDevices)
Expand Down Expand Up @@ -268,15 +269,18 @@ def rescan(self, usb=True, bluetooth=True, limitToDevices=None):

def handleWindowMessage(self, msg=None, wParam=None):
if msg == WM_DEVICECHANGE and wParam == DBT_DEVNODES_CHANGED:
self.rescan()
self.rescan(bluetooth=self._detectBluetooth, limitToDevices=self._limitToDevices)

def pollBluetoothDevices(self):
"""Poll bluetooth devices that might be in range.
This does not cancel the current scan."""
if not self._detectBluetooth:
# Do not poll bluetooth devices at all when bluetooth is disabled.
return
with self._btDevsLock:
if not self._btDevs:
return
self._startBgScan(bluetooth=True)
self._startBgScan(bluetooth=self._detectBluetooth, limitToDevices=self._limitToDevices)

def terminate(self):
appModuleHandler.post_appSwitch.unregister(self.pollBluetoothDevices)
Expand Down
18 changes: 7 additions & 11 deletions source/braille.py
Expand Up @@ -1669,8 +1669,11 @@ def setDisplayByName(self, name, isFallback=False, detected=None):
self.display = newDisplay
self.displaySize = newDisplay.numCells
self.enabled = bool(self.displaySize)
if isFallback:
self._resumeDetection()
if isFallback and self._detectionEnabled:
# As this is the fallback display, which is usually noBraille,
# we can keep the current display when enabling detection.
# Note that in this case, L{_detectionEnabled} is set by L{handleDisplayUnavailable}
self.__enableDetection(keepCurrentDisplay=True)
elif not detected:
config.conf["braille"]["display"] = name
else: # detected:
Expand All @@ -1684,7 +1687,7 @@ def setDisplayByName(self, name, isFallback=False, detected=None):
# We should handle this more gracefully, since this is no reason
# to stop a display from loading successfully.
log.debugWarning("Error in initial display after display load", exc_info=True)
if detected and detected.type in (bdDetect.KEY_SERIAL, bdDetect.KEY_HID,) and 'bluetoothName' in detected.deviceInfo:
if detected and and 'bluetoothName' in detected.deviceInfo:
self._enableDetection(bluetooth=False, keepCurrentDisplay=True, limitToDevices=[name])
return True
except:
Expand Down Expand Up @@ -1996,6 +1999,7 @@ def handleDisplayUnavailable(self):
def _enableDetection(self, usb=True, bluetooth=True, keepCurrentDisplay=False, limitToDevices=None):
"""Enables automatic detection of braille displays.
When auto detection is already active, this will force a rescan for devices.
This should also be executed when auto detection should be resumed due to loss of display connectivity.
"""
if self._detectionEnabled and self._detector:
self._detector.rescan(usb=usb, bluetooth=bluetooth, limitToDevices=limitToDevices)
Expand All @@ -2016,14 +2020,6 @@ def _disableDetection(self):
self._detector = None
self._detectionEnabled = False

def _resumeDetection(self):
"""Resumes automatic detection of braille displays.
This is executed when auto detection should be resumed due to loss of display connectivity.
"""
if not self._detectionEnabled or self._detector:
return
self._detector = bdDetect.Detector()

class _BgThread:
"""A singleton background thread used for background writes and raw braille display I/O.
"""
Expand Down