Skip to content

Commit 89c132f

Browse files
committed
Apply auto formatting
1 parent 6a10272 commit 89c132f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+7322
-6307
lines changed

accessible_output2/__init__.py

+25-22
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,33 @@
44
import types
55
from platform_utils import paths
66

7+
78
def load_library(libname, cdll=False):
8-
if paths.is_frozen():
9-
libfile = os.path.join(paths.embedded_data_path(), 'accessible_output2', 'lib', libname)
10-
else:
11-
libfile = os.path.join(paths.module_path(), 'lib', libname)
12-
if cdll:
13-
return ctypes.cdll[libfile]
14-
else:
15-
return ctypes.windll[libfile]
9+
if paths.is_frozen():
10+
libfile = os.path.join(paths.embedded_data_path(), 'accessible_output2', 'lib', libname)
11+
else:
12+
libfile = os.path.join(paths.module_path(), 'lib', libname)
13+
if cdll:
14+
return ctypes.cdll[libfile]
15+
else:
16+
return ctypes.windll[libfile]
17+
1618

1719
def get_output_classes():
18-
from . import outputs
19-
module_type = types.ModuleType
20-
classes = [m.output_class for m in outputs.__dict__.values() if type(m) == module_type and hasattr(m, 'output_class')]
21-
return sorted(classes, key=lambda c: c.priority)
20+
from . import outputs
21+
module_type = types.ModuleType
22+
classes = [m.output_class for m in outputs.__dict__.values() if type(m) == module_type and hasattr(m, 'output_class')]
23+
return sorted(classes, key=lambda c: c.priority)
24+
2225

2326
def find_datafiles():
24-
import os
25-
import platform
26-
from glob import glob
27-
import accessible_output2
28-
if platform.system() != 'Windows':
29-
return []
30-
path = os.path.join(accessible_output2.__path__[0], 'lib', '*.dll')
31-
results = glob(path)
32-
dest_dir = os.path.join('accessible_output2', 'lib')
33-
return [(dest_dir, results)]
27+
import os
28+
import platform
29+
from glob import glob
30+
import accessible_output2
31+
if platform.system() != 'Windows':
32+
return []
33+
path = os.path.join(accessible_output2.__path__[0], 'lib', '*.dll')
34+
results = glob(path)
35+
dest_dir = os.path.join('accessible_output2', 'lib')
36+
return [(dest_dir, results)]
+11-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
from __future__ import absolute_import
22
import platform
33
if platform.system() == 'Windows':
4-
from . import nvda
5-
from . import jaws
6-
from . import sapi5
7-
from . import window_eyes
8-
from . import system_access
9-
from . import dolphin
10-
from . import pc_talker
11-
#import sapi4
4+
from . import nvda
5+
from . import jaws
6+
from . import sapi5
7+
from . import window_eyes
8+
from . import system_access
9+
from . import dolphin
10+
from . import pc_talker
11+
#import sapi4
1212

1313
if platform.system() == 'Darwin':
14-
from . import nsSpeechSynth
15-
from . import voiceover
14+
from . import nsSpeechSynth
15+
from . import voiceover
1616

1717
if platform.system() == 'Linux':
18-
from . import e_speak
18+
from . import e_speak
1919

2020
from . import auto

accessible_output2/outputs/auto.py

+41-39
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,46 @@
22
import accessible_output2
33
from .base import Output, OutputError
44

5+
56
class Auto(Output):
67

7-
def __init__(self):
8-
output_classes = accessible_output2.get_output_classes()
9-
self.outputs = []
10-
for output in output_classes:
11-
try:
12-
self.outputs.append(output())
13-
except OutputError:
14-
pass
15-
16-
def get_first_available_output(self):
17-
for output in self.outputs:
18-
if output.is_active():
19-
return output
20-
return None
21-
22-
def speak(self, *args, **kwargs):
23-
output = self.get_first_available_output()
24-
if output:
25-
output.speak(*args, **kwargs)
26-
27-
def silence(self):
28-
output = self.get_first_available_output()
29-
if output:
30-
if output.silence: output.silence()
31-
32-
def braille(self, *args, **kwargs):
33-
output = self.get_first_available_output()
34-
if output:
35-
output.braille(*args, **kwargs)
36-
37-
def output(self, *args, **kwargs):
38-
output = self.get_first_available_output()
39-
if output:
40-
output.speak(*args, **kwargs)
41-
42-
def is_system_output(self):
43-
output = self.get_first_available_output()
44-
if output:
45-
return output.is_system_output()
8+
def __init__(self):
9+
output_classes = accessible_output2.get_output_classes()
10+
self.outputs = []
11+
for output in output_classes:
12+
try:
13+
self.outputs.append(output())
14+
except OutputError:
15+
pass
16+
17+
def get_first_available_output(self):
18+
for output in self.outputs:
19+
if output.is_active():
20+
return output
21+
return None
22+
23+
def speak(self, *args, **kwargs):
24+
output = self.get_first_available_output()
25+
if output:
26+
output.speak(*args, **kwargs)
27+
28+
def silence(self):
29+
output = self.get_first_available_output()
30+
if output:
31+
if output.silence:
32+
output.silence()
33+
34+
def braille(self, *args, **kwargs):
35+
output = self.get_first_available_output()
36+
if output:
37+
output.braille(*args, **kwargs)
38+
39+
def output(self, *args, **kwargs):
40+
output = self.get_first_available_output()
41+
if output:
42+
output.speak(*args, **kwargs)
43+
44+
def is_system_output(self):
45+
output = self.get_first_available_output()
46+
if output:
47+
return output.is_system_output()

accessible_output2/outputs/base.py

+43-41
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
11
from accessible_output2 import load_library
22
import platform
33

4+
45
class OutputError(Exception):
5-
pass
6+
pass
7+
68

79
class Output(object):
8-
name = "Unnamed Output"
9-
lib32 = None
10-
lib64 = None
11-
argtypes = {}
12-
cdll = False
13-
priority = 100
14-
system_output = False
15-
16-
def __init__(self):
17-
self.is_32bit = platform.architecture()[0] == "32bit"
18-
if self.lib32 and self.is_32bit:
19-
self.lib = load_library(self.lib32, cdll=self.cdll)
20-
elif self.lib64:
21-
self.lib = load_library(self.lib64, cdll=self.cdll)
22-
else:
23-
self.lib = None
24-
if self.lib is not None:
25-
for func in self.argtypes:
26-
try:
27-
getattr(self.lib, func).argtypes = self.argtypes[func]
28-
except AttributeError:
29-
pass
30-
31-
def output(self, text, **options):
32-
output = False
33-
if self.speak(text, **options):
34-
output = True
35-
if self.braille(text, **options):
36-
output = True
37-
if not output:
38-
raise RuntimeError("Output %r does not have any method defined to output" % self)
39-
40-
def is_system_output(self):
41-
return self.system_output
42-
43-
def speak(self, text, **options):
44-
return False
45-
46-
def braille(self, text, **options):
47-
return False
10+
name = "Unnamed Output"
11+
lib32 = None
12+
lib64 = None
13+
argtypes = {}
14+
cdll = False
15+
priority = 100
16+
system_output = False
17+
18+
def __init__(self):
19+
self.is_32bit = platform.architecture()[0] == "32bit"
20+
if self.lib32 and self.is_32bit:
21+
self.lib = load_library(self.lib32, cdll=self.cdll)
22+
elif self.lib64:
23+
self.lib = load_library(self.lib64, cdll=self.cdll)
24+
else:
25+
self.lib = None
26+
if self.lib is not None:
27+
for func in self.argtypes:
28+
try:
29+
getattr(self.lib, func).argtypes = self.argtypes[func]
30+
except AttributeError:
31+
pass
32+
33+
def output(self, text, **options):
34+
output = False
35+
if self.speak(text, **options):
36+
output = True
37+
if self.braille(text, **options):
38+
output = True
39+
if not output:
40+
raise RuntimeError("Output %r does not have any method defined to output" % self)
41+
42+
def is_system_output(self):
43+
return self.system_output
44+
45+
def speak(self, text, **options):
46+
return False
47+
48+
def braille(self, text, **options):
49+
return False

accessible_output2/outputs/dolphin.py

+26-24
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,32 @@
44

55
from .base import Output
66

7+
78
class Dolphin (Output):
8-
"""Supports dolphin products."""
9-
10-
name = 'Dolphin'
11-
lib32 = 'dolapi.dll'
12-
argtypes = {
13-
'DolAccess_Command': (ctypes.c_wchar_p, ctypes.c_int, ctypes.c_int),
14-
'DolAccess_Action': (ctypes.c_int,),
15-
}
16-
17-
def speak(self, text, interrupt=0):
18-
if interrupt:
19-
self.silence()
20-
#If we don't call this, the API won't let us speak.
21-
if self.is_active():
22-
self.lib.DolAccess_Command(text, (len(text)*2)+2, 1)
23-
24-
def silence(self):
25-
self.lib.DolAccess_Action(141)
26-
27-
def is_active(self):
28-
try:
29-
return self.lib.DolAccess_GetSystem() in (1, 4, 8)
30-
except:
31-
return False
9+
"""Supports dolphin products."""
10+
11+
name = 'Dolphin'
12+
lib32 = 'dolapi.dll'
13+
argtypes = {
14+
'DolAccess_Command': (ctypes.c_wchar_p, ctypes.c_int, ctypes.c_int),
15+
'DolAccess_Action': (ctypes.c_int,),
16+
}
17+
18+
def speak(self, text, interrupt=0):
19+
if interrupt:
20+
self.silence()
21+
# If we don't call this, the API won't let us speak.
22+
if self.is_active():
23+
self.lib.DolAccess_Command(text, (len(text) * 2) + 2, 1)
24+
25+
def silence(self):
26+
self.lib.DolAccess_Action(141)
27+
28+
def is_active(self):
29+
try:
30+
return self.lib.DolAccess_GetSystem() in (1, 4, 8)
31+
except BaseException:
32+
return False
33+
3234

3335
output_class = Dolphin

accessible_output2/outputs/e_speak.py

+26-23
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,33 @@
22
from .base import Output
33

44
try:
5-
import espeak.core
6-
except:
7-
raise RuntimeError("Cannot find espeak.core. Please install python-espeak")
5+
import espeak.core
6+
except BaseException:
7+
raise RuntimeError("Cannot find espeak.core. Please install python-espeak")
8+
89

910
class ESpeak(Output):
10-
"""Speech output supporting ESpeak on Linux
11-
Note this requires python-espeak to be installed
12-
This can be done on Debian distros by using apt-get install python-espeak
13-
Or through this tarball: https://launchpad.net/python-espeak
14-
"""
15-
name = "Linux ESpeak"
16-
17-
def is_active(self):
18-
try:
19-
import espeak.core
20-
except:
21-
return False
22-
return True
23-
24-
def speak(self, text, interrupt = 0):
25-
if interrupt:
26-
self.silence()
27-
espeak.core.synth(text)
28-
def silence(self):
29-
espeak.core.cancel()
11+
"""Speech output supporting ESpeak on Linux
12+
Note this requires python-espeak to be installed
13+
This can be done on Debian distros by using apt-get install python-espeak
14+
Or through this tarball: https://launchpad.net/python-espeak
15+
"""
16+
name = "Linux ESpeak"
17+
18+
def is_active(self):
19+
try:
20+
import espeak.core
21+
except BaseException:
22+
return False
23+
return True
24+
25+
def speak(self, text, interrupt=0):
26+
if interrupt:
27+
self.silence()
28+
espeak.core.synth(text)
29+
30+
def silence(self):
31+
espeak.core.cancel()
32+
3033

3134
output_class = ESpeak

0 commit comments

Comments
 (0)