(self, event)
| 1104 | self.printOperation(None, Operation.PRESS, keycode) |
| 1105 | |
| 1106 | def onKeyPressed(self, event): |
| 1107 | if DEBUG_KEY: |
| 1108 | print("onKeyPressed(", repr(event), ")", file=sys.stderr) |
| 1109 | print(f' char: type={type(event.char)} len={len(event.char)} repr={repr(event.char)}\n' + |
| 1110 | f' keysym={event.keysym}, keycode={event.keycode}, type={event.type}, state={event.state}', |
| 1111 | file=sys.stderr) |
| 1112 | print(" events disabled:", self.areEventsDisabled, file=sys.stderr) |
| 1113 | if self.areEventsDisabled: |
| 1114 | if DEBUG_KEY: |
| 1115 | print(" ignoring event", file=sys.stderr) |
| 1116 | self.canvas.update_idletasks() |
| 1117 | return |
| 1118 | |
| 1119 | char = event.char |
| 1120 | keysym = event.keysym |
| 1121 | state = event.state |
| 1122 | |
| 1123 | # Manual way to get the modifiers |
| 1124 | # https://stackoverflow.com/a/34482048/236465 |
| 1125 | ctrl = (state & 0x4) != 0 |
| 1126 | alt = (state & 0x8) != 0 or (state & 0x80) != 0 |
| 1127 | shift = (state & 0x1) != 0 |
| 1128 | |
| 1129 | if ctrl: |
| 1130 | try: |
| 1131 | return getattr(self, f'onCtrl{keysym.upper()}')(event) |
| 1132 | except AttributeError: |
| 1133 | pass |
| 1134 | |
| 1135 | if len(char) == 0 and not ( |
| 1136 | keysym in Culebron.KEYSYM_TO_KEYCODE_MAP or keysym in Culebron.KEYSYM_CULEBRON_COMMANDS): |
| 1137 | if DEBUG_KEY: |
| 1138 | print(f' returning because len(char) == 0 keysym={keysym}', file=sys.stderr) |
| 1139 | return |
| 1140 | |
| 1141 | ### |
| 1142 | ### internal commands: no output to generated script |
| 1143 | ### |
| 1144 | if keysym == 'F1': |
| 1145 | self.showHelp() |
| 1146 | return |
| 1147 | elif keysym == 'F5': |
| 1148 | self.refresh() |
| 1149 | return |
| 1150 | elif keysym == 'F8': |
| 1151 | self.printGridInfo() |
| 1152 | return |
| 1153 | elif keysym == 'Alt_L': |
| 1154 | return |
| 1155 | elif keysym == 'Control_L': |
| 1156 | return |
| 1157 | elif keysym == 'Escape': |
| 1158 | # we cannot send Escape to the device, but I think it's fine |
| 1159 | self.cancelOperation() |
| 1160 | return |
| 1161 | |
| 1162 | ### empty char (modifier) ### |
| 1163 | # here does not process events like Home where char is '' |
nothing calls this directly
no test coverage detected