MCPcopy Index your code
hub / github.com/SLiCAP/SLiCAP_python / keyPressEvent

Method keyPressEvent

SLiCAP/schematic/canvas.py:2841–2924  ·  view source on GitHub ↗
(self, event)

Source from the content-addressed store, hash-verified

2839 # ── keyboard ─────────────────────────────────────────────────────────────
2840
2841 def keyPressEvent(self, event):
2842 scene = self.scene()
2843
2844 # While a text item is actively being edited, let Qt dispatch
2845 # the event normally — don't intercept Backspace, R, Ctrl+C/V, etc.
2846 focused = scene.focusItem()
2847 from PySide6.QtWidgets import QGraphicsTextItem
2848 if (isinstance(focused, QGraphicsTextItem)
2849 and focused.textInteractionFlags() != Qt.NoTextInteraction):
2850 super().keyPressEvent(event)
2851 return
2852
2853 key = event.key()
2854 mods = event.modifiers()
2855
2856 if key == Qt.Key_Escape:
2857 if scene._mode == _Mode.DRAWING_LINE:
2858 # Commit if we have a valid line; otherwise just cancel
2859 if len(scene._draw_pts) >= 2:
2860 scene._commit_shape(scene._draw_pts[-1])
2861 else:
2862 scene._cancel_draw()
2863 elif scene._mode in (_Mode.DRAWING_RECT, _Mode.DRAWING_CIRCLE):
2864 scene._cancel_draw()
2865 elif scene._mode == _Mode.WIRING:
2866 scene.finish_wire()
2867 else:
2868 scene.cancel_placement()
2869 elif key in (Qt.Key_Return, Qt.Key_Enter):
2870 if scene._mode == _Mode.DRAWING_LINE and len(scene._draw_pts) >= 2:
2871 scene._commit_shape(scene._draw_pts[-1])
2872 else:
2873 scene.finish_wire()
2874 elif key == Qt.Key_Slash:
2875 scene.toggle_elbow()
2876 elif key == Qt.Key_Z and mods & Qt.ControlModifier:
2877 if mods & Qt.ShiftModifier:
2878 scene.redo()
2879 else:
2880 scene.undo()
2881 elif key == Qt.Key_Y and mods & Qt.ControlModifier:
2882 scene.redo()
2883 elif key == Qt.Key_R:
2884 if scene.selectedItems():
2885 scene._push_undo()
2886 for item in scene.selectedItems():
2887 item.setRotation(item.rotation() + 90)
2888 elif key == Qt.Key_M:
2889 sel = [i for i in scene.selectedItems() if isinstance(i, ComponentItem)]
2890 if sel:
2891 scene._push_undo()
2892 for item in sel:
2893 item.h_flip = not item.h_flip
2894 item.apply_transform()
2895 scene._sync_junctions()
2896 elif key in (Qt.Key_Delete, Qt.Key_Backspace):
2897 if scene.selectedItems():
2898 scene._push_undo()

Callers

nothing calls this directly

Calls 13

_commit_shapeMethod · 0.80
_cancel_drawMethod · 0.80
finish_wireMethod · 0.80
cancel_placementMethod · 0.80
toggle_elbowMethod · 0.80
redoMethod · 0.80
undoMethod · 0.80
_push_undoMethod · 0.80
apply_transformMethod · 0.80
_sync_junctionsMethod · 0.80
update_labelMethod · 0.80
_copy_selectionMethod · 0.80

Tested by

no test coverage detected