def record_callback(self, reply): check_valid_event(reply) data = reply.data while len(data): event, data = get_event_data(data) self.capture_event.emit(event)
def record_callback(self, reply): global press_ctrl global press_shift check_valid_event(reply) data = reply.data while len(data): event, data = get_event_data(data) if event.type == X.KeyPress: keyname = get_keyname(event) if keyname not in ["Control_L", "Control_R"]: self.try_stop_timer(self.press_ctrl_timer) if keyname in ["Control_L", "Control_R"]: press_ctrl = True if not setting_config.get_trayicon_config("pause"): if not self.view.isVisible() or not self.view.in_translate_area(): self.press_ctrl_timer = Timer(self.press_ctrl_delay, self.emit_press_ctrl) self.press_ctrl_timer.start() elif keyname in ["Shift_L", "Shift_R"]: press_shift = True elif keyname in ["Escape"]: self.press_esc.emit() elif event.type == X.KeyRelease: keyname = get_keyname(event) if keyname in ["Control_L", "Control_R"]: press_ctrl = False self.release_ctrl.emit() elif keyname in ["Shift_L", "Shift_R"]: press_shift = False elif event.type == X.ButtonPress: if event.detail == 1: self.left_button_press.emit(event.root_x, event.root_y, event.time) elif event.detail == 3: self.right_button_press.emit(event.root_x, event.root_y, event.time) elif event.detail == 5: self.wheel_press.emit() elif event.type == X.ButtonRelease: if not self.view.isVisible() or not self.view.in_translate_area(): if not setting_config.get_trayicon_config("pause"): if not setting_config.get_trayicon_config("key_trigger_select") or press_shift: selection_content = commands.getoutput("xsel -p -o") delete_selection() if len(selection_content) > 1 and not selection_content.isspace(): self.translate_selection.emit(event.root_x, event.root_y, selection_content) # Delete clipboard selection if user selection in visible area to avoid next time to translate those selection content. elif self.view.isVisible() and self.view.in_translate_area(): delete_selection() elif event.type == X.MotionNotify: self.try_stop_timer(self.stop_timer) if not setting_config.get_trayicon_config("pause"): self.stop_timer = Timer(self.stop_delay, lambda : self.emit_cursor_stop(event.root_x, event.root_y)) self.stop_timer.start()