class Emulator:
"""Class used to interact with an emulator and type word on a given keyboard.
Args:
@@ -6419,9 +6417,7 @@
"""
screen_data = self.driver.get_screenshot_as_png()
screen = np.asarray(Image.open(io.BytesIO(screen_data)))
- return cv2.resize(
- screen, (self.screen_size["width"], self.screen_size["height"]), interpolation=cv2.INTER_AREA
- )
+ return screen.copy()
def get_predictions(self, lang: str = "en") -> List[str]:
"""Retrieve the predictions displayed by the keyboard.
@@ -7142,7 +7138,9 @@
Source code in kebbie/emulator.py
- 615
+ 613
+614
+615
616
617
618
@@ -7169,9 +7167,7 @@
639
640
641
-642
-643
-644 | def get_predictions(self, lang: str = "en") -> List[str]:
+642
| def get_predictions(self, lang: str = "en") -> List[str]:
"""Retrieve the predictions displayed by the keyboard.
Args:
@@ -7248,7 +7244,9 @@
Source code in kebbie/emulator.py
- 654
+ 652
+653
+654
655
656
657
@@ -7260,9 +7258,7 @@
663
664
665
-666
-667
-668 | def get_text(self) -> str:
+666
| def get_text(self) -> str:
"""Return the text currently contained in the typing field.
This method is just a wrapper around `_get_text()`, making sure the
@@ -7299,7 +7295,9 @@
Source code in kebbie/emulator.py
- 670
+ 668
+669
+670
671
672
673
@@ -7329,9 +7327,7 @@
697
698
699
-700
-701
-702 | def show_keyboards(self):
+700
| def show_keyboards(self):
"""Take a screenshot and overlay the given layout, for debugging the
position of each keys.
"""
@@ -7472,7 +7468,9 @@
Source code in kebbie/emulator.py
- 724
+ 722
+723
+724
725
726
727
@@ -7628,59 +7626,7 @@
877
878
879
-880
-881
-882
-883
-884
-885
-886
-887
-888
-889
-890
-891
-892
-893
-894
-895
-896
-897
-898
-899
-900
-901
-902
-903
-904
-905
-906
-907
-908
-909
-910
-911
-912
-913
-914
-915
-916
-917
-918
-919
-920
-921
-922
-923
-924
-925
-926
-927
-928
-929
-930
-931
-932 | class LayoutDetector:
+880
| class LayoutDetector:
"""Base class for auto-detection of the keyboard layout.
To auto-detect a new keyboard, create a new sub-class, and overwite
@@ -7729,11 +7675,7 @@
# Reset out keyboard to the original layer
self.tap(layout["numbers"]["letters"], layout["keyboard_frame"])
- # Fix the keys' offset compared to the keyboard frame
- if self.android:
- self.layout = self._apply_status_bar_offset(layout)
- else:
- self.layout = layout
+ self.layout = layout
def get_suggestions(self) -> List[str]:
"""Method to retrieve the keyboard suggestions from the XML tree.
@@ -7843,52 +7785,6 @@
return CONTENT_TO_RENAME[content]
else:
return content
-
- def _get_status_bar_bounds(self) -> List[int]:
- """For layout detection, this method retrieve the bounds of the status
- bar from the XML tree.
-
- Returns:
- Bounds of the status bar.
- """
- sb = self.driver.find_element(By.ID, "com.android.systemui:id/status_bar")
- return self._get_frame(sb)
-
- def _apply_status_bar_offset(self, layout: Dict) -> Dict:
- """Method offsetting the given layout to match the screen.
-
- On Android, somehow the detected positions for the keys aren't matching
- what we see on screen. This is because of the status bar, which shift
- everything. So, detect the status bar, and shift back the keys to the
- right position.
-
- Args:
- layout (Dict): Layout to fix.
-
- Returns:
- Fixed layout.
- """
- sb_bounds = self._get_status_bar_bounds()
- dy = sb_bounds[3]
- screen_size = layout["keyboard_frame"][1] + layout["keyboard_frame"][3]
-
- # First of all, offset the keyboard frame
- frame_dy1 = int(dy * (layout["keyboard_frame"][1] / screen_size))
- frame_dy2 = int(dy * ((layout["keyboard_frame"][1] + layout["keyboard_frame"][3]) / screen_size))
- layout["keyboard_frame"][1] -= frame_dy1
- layout["keyboard_frame"][3] -= frame_dy2 - frame_dy1
-
- # Then do the same for each keys of each layouts
- for layer in ["lowercase", "uppercase", "numbers"]:
- for k in layout[layer]:
- dy1 = int(dy * ((layout["keyboard_frame"][1] + layout[layer][k][1]) / screen_size))
- dy2 = int(
- dy * ((layout["keyboard_frame"][1] + layout[layer][k][1] + layout[layer][k][3]) / screen_size)
- )
- layout[layer][k][1] -= dy1 - frame_dy1
- layout[layer][k][3] -= dy2 - dy1
-
- return layout
|
@@ -7969,7 +7865,13 @@
Source code in kebbie/emulator.py
- 779
+ 773
+774
+775
+776
+777
+778
+779
780
781
782
@@ -7977,13 +7879,7 @@
784
785
786
-787
-788
-789
-790
-791
-792
-793 | def get_suggestions(self) -> List[str]:
+787
| def get_suggestions(self) -> List[str]:
"""Method to retrieve the keyboard suggestions from the XML tree.
Note that it's slower to access the XML through methods like
@@ -8033,43 +7929,43 @@
Source code in kebbie/emulator.py
- 935
-936
-937
-938
-939
-940
-941
-942
-943
-944
-945
-946
-947
-948
-949
-950
-951
-952
-953
-954
-955
-956
-957
-958
-959
-960
-961
-962
-963
-964
-965
-966
-967
-968
-969
-970
-971 | class GboardLayoutDetector(LayoutDetector):
+ 883
+884
+885
+886
+887
+888
+889
+890
+891
+892
+893
+894
+895
+896
+897
+898
+899
+900
+901
+902
+903
+904
+905
+906
+907
+908
+909
+910
+911
+912
+913
+914
+915
+916
+917
+918
+919 | class GboardLayoutDetector(LayoutDetector):
"""Layout detector for the Gboard keyboard. See `LayoutDetector` for more
information.
"""
@@ -8159,30 +8055,30 @@
Source code in kebbie/emulator.py
- 948
-949
-950
-951
-952
-953
-954
-955
-956
-957
-958
-959
-960
-961
-962
-963
-964
-965
-966
-967
-968
-969
-970
-971 | def get_suggestions(self) -> List[str]:
+ 896
+897
+898
+899
+900
+901
+902
+903
+904
+905
+906
+907
+908
+909
+910
+911
+912
+913
+914
+915
+916
+917
+918
+919 | def get_suggestions(self) -> List[str]:
"""Method to retrieve the keyboard suggestions from the XML tree.
Returns:
@@ -8241,45 +8137,45 @@
Source code in kebbie/emulator.py
- 974
- 975
- 976
- 977
- 978
- 979
- 980
- 981
- 982
- 983
- 984
- 985
- 986
- 987
- 988
- 989
- 990
- 991
- 992
- 993
- 994
- 995
- 996
- 997
- 998
- 999
-1000
-1001
-1002
-1003
-1004
-1005
-1006
-1007
-1008
-1009
-1010
-1011
-1012 | class IosLayoutDetector(LayoutDetector):
+ 922
+923
+924
+925
+926
+927
+928
+929
+930
+931
+932
+933
+934
+935
+936
+937
+938
+939
+940
+941
+942
+943
+944
+945
+946
+947
+948
+949
+950
+951
+952
+953
+954
+955
+956
+957
+958
+959
+960 | class IosLayoutDetector(LayoutDetector):
"""Layout detector for the iOS default keyboard. See `LayoutDetector` for
more information.
"""
@@ -8371,42 +8267,42 @@
Source code in kebbie/emulator.py
- 988
- 989
- 990
- 991
- 992
- 993
- 994
- 995
- 996
- 997
- 998
- 999
-1000
-1001
-1002
-1003
-1004
-1005
-1006
-1007
-1008
-1009
-1010
-1011
-1012 | def get_suggestions(self) -> List[str]:
- """Method to retrieve the keyboard suggestions from the XML tree.
-
- Returns:
- List of suggestions from the keyboard.
- """
- suggestions = []
-
- sections = [
- data for data in self.driver.page_source.split("<XCUIElementTypeOther") if "name=" in data.split(">")[0]
- ]
- is_typing_predictions_section = False
+ 936
+937
+938
+939
+940
+941
+942
+943
+944
+945
+946
+947
+948
+949
+950
+951
+952
+953
+954
+955
+956
+957
+958
+959
+960 | def get_suggestions(self) -> List[str]:
+ """Method to retrieve the keyboard suggestions from the XML tree.
+
+ Returns:
+ List of suggestions from the keyboard.
+ """
+ suggestions = []
+
+ sections = [
+ data for data in self.driver.page_source.split("<XCUIElementTypeOther") if "name=" in data.split(">")[0]
+ ]
+ is_typing_predictions_section = False
for section in sections:
m = re.search(r"name=\"([^\"]*)\"", section)
if m:
@@ -8455,41 +8351,41 @@
Source code in kebbie/emulator.py
- 1015
-1016
-1017
-1018
-1019
-1020
-1021
-1022
-1023
-1024
-1025
-1026
-1027
-1028
-1029
-1030
-1031
-1032
-1033
-1034
-1035
-1036
-1037
-1038
-1039
-1040
-1041
-1042
-1043
-1044
-1045
-1046
-1047
-1048
-1049 | class KbkitproLayoutDetector(LayoutDetector):
+ 963
+964
+965
+966
+967
+968
+969
+970
+971
+972
+973
+974
+975
+976
+977
+978
+979
+980
+981
+982
+983
+984
+985
+986
+987
+988
+989
+990
+991
+992
+993
+994
+995
+996
+997 | class KbkitproLayoutDetector(LayoutDetector):
"""Layout detector for the KeyboardKit Pro demo keyboard. See
`LayoutDetector` for more information.
"""
@@ -8577,27 +8473,27 @@
Source code in kebbie/emulator.py
- 1029
-1030
-1031
-1032
-1033
-1034
-1035
-1036
-1037
-1038
-1039
-1040
-1041
-1042
-1043
-1044
-1045
-1046
-1047
-1048
-1049 | def get_suggestions(self) -> List[str]:
+ 977
+978
+979
+980
+981
+982
+983
+984
+985
+986
+987
+988
+989
+990
+991
+992
+993
+994
+995
+996
+997 | def get_suggestions(self) -> List[str]:
"""Method to retrieve the keyboard suggestions from the XML tree.
Returns:
@@ -8653,38 +8549,38 @@
Source code in kebbie/emulator.py
- 1052
-1053
-1054
-1055
-1056
-1057
-1058
-1059
-1060
-1061
-1062
-1063
-1064
-1065
-1066
-1067
-1068
-1069
-1070
-1071
-1072
-1073
-1074
-1075
-1076
-1077
-1078
-1079
-1080
-1081
-1082
-1083 | class KbkitossLayoutDetector(LayoutDetector):
+ 1000
+1001
+1002
+1003
+1004
+1005
+1006
+1007
+1008
+1009
+1010
+1011
+1012
+1013
+1014
+1015
+1016
+1017
+1018
+1019
+1020
+1021
+1022
+1023
+1024
+1025
+1026
+1027
+1028
+1029
+1030
+1031 | class KbkitossLayoutDetector(LayoutDetector):
"""Layout detector for the KeyboardKit OSS demo keyboard. See
`LayoutDetector` for more information.
"""
@@ -8769,24 +8665,24 @@
Source code in kebbie/emulator.py
- 1066
-1067
-1068
-1069
-1070
-1071
-1072
-1073
-1074
-1075
-1076
-1077
-1078
-1079
-1080
-1081
-1082
-1083 | def get_suggestions(self) -> List[str]:
+ 1014
+1015
+1016
+1017
+1018
+1019
+1020
+1021
+1022
+1023
+1024
+1025
+1026
+1027
+1028
+1029
+1030
+1031 | def get_suggestions(self) -> List[str]:
"""Method to retrieve the keyboard suggestions from the XML tree.
Returns:
@@ -8839,38 +8735,38 @@
Source code in kebbie/emulator.py
- 1086
-1087
-1088
-1089
-1090
-1091
-1092
-1093
-1094
-1095
-1096
-1097
-1098
-1099
-1100
-1101
-1102
-1103
-1104
-1105
-1106
-1107
-1108
-1109
-1110
-1111
-1112
-1113
-1114
-1115
-1116
-1117 | class SwiftkeyLayoutDetector(LayoutDetector):
+ 1034
+1035
+1036
+1037
+1038
+1039
+1040
+1041
+1042
+1043
+1044
+1045
+1046
+1047
+1048
+1049
+1050
+1051
+1052
+1053
+1054
+1055
+1056
+1057
+1058
+1059
+1060
+1061
+1062
+1063
+1064
+1065 | class SwiftkeyLayoutDetector(LayoutDetector):
"""Layout detector for the Swiftkey keyboard. See `LayoutDetector` for more
information.
"""
@@ -8955,25 +8851,25 @@
Source code in kebbie/emulator.py
- 1099
-1100
-1101
-1102
-1103
-1104
-1105
-1106
-1107
-1108
-1109
-1110
-1111
-1112
-1113
-1114
-1115
-1116
-1117 | def get_suggestions(self) -> List[str]:
+ 1047
+1048
+1049
+1050
+1051
+1052
+1053
+1054
+1055
+1056
+1057
+1058
+1059
+1060
+1061
+1062
+1063
+1064
+1065 | def get_suggestions(self) -> List[str]:
"""Method to retrieve the keyboard suggestions from the XML tree.
Returns:
@@ -9027,39 +8923,39 @@
Source code in kebbie/emulator.py
- 1120
-1121
-1122
-1123
-1124
-1125
-1126
-1127
-1128
-1129
-1130
-1131
-1132
-1133
-1134
-1135
-1136
-1137
-1138
-1139
-1140
-1141
-1142
-1143
-1144
-1145
-1146
-1147
-1148
-1149
-1150
-1151
-1152 | class TappaLayoutDetector(LayoutDetector):
+ 1068
+1069
+1070
+1071
+1072
+1073
+1074
+1075
+1076
+1077
+1078
+1079
+1080
+1081
+1082
+1083
+1084
+1085
+1086
+1087
+1088
+1089
+1090
+1091
+1092
+1093
+1094
+1095
+1096
+1097
+1098
+1099
+1100 | class TappaLayoutDetector(LayoutDetector):
"""Layout detector for the Tappa keyboard. See `LayoutDetector` for more
information.
"""
@@ -9145,26 +9041,26 @@
Source code in kebbie/emulator.py
- 1133
-1134
-1135
-1136
-1137
-1138
-1139
-1140
-1141
-1142
-1143
-1144
-1145
-1146
-1147
-1148
-1149
-1150
-1151
-1152 | def get_suggestions(self) -> List[str]:
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|