def keyPressEvent(self, event): modifiers = event.modifiers() currentInputAction = InputAction(name="temp", actionType=InputActionType.Keyboard, key=event.key(), modifiers=modifiers) actionSaveVariants = InputManager()["App.Save"] actionNewFileVariants = InputManager()["App.NewFile"] actionLoadVariants = InputManager()["App.Load"] actionSaveAsVariants = InputManager()["App.SaveAs"] if currentInputAction in actionNewFileVariants: EditorHistory().clear() historyTools = self.getRegisteredTools( classNameFilters=["HistoryTool"]) for historyTools in historyTools: historyTools.onClear() self.newFile() EditorHistory().saveState("New file") if currentInputAction in actionSaveVariants: self.save() if currentInputAction in actionLoadVariants: EditorHistory().clear() self.load() if currentInputAction in actionSaveAsVariants: self.save(True)
def keyPressEvent(self, event): modifiers = event.modifiers() currentInputAction = InputAction(name="temp", actionType=InputActionType.Keyboard, key=event.key(), modifiers=modifiers) actionSaveVariants = InputManager()["App.Save"] actionNewFileVariants = InputManager()["App.NewFile"] actionLoadVariants = InputManager()["App.Load"] actionSaveAsVariants = InputManager()["App.SaveAs"] if currentInputAction in actionNewFileVariants: self.newFile() if currentInputAction in actionSaveVariants: self.save() if currentInputAction in actionLoadVariants: self.load() if currentInputAction in actionSaveAsVariants: self.save_as()
def keyPressEvent(self, event): modifiers = event.modifiers() currentInputAction = InputAction(name="temp", actionType=InputActionType.Keyboard, key=event.key(), modifiers=modifiers) actionSaveVariants = InputManager()["App.Save"] actionNewFileVariants = InputManager()["App.NewFile"] actionLoadVariants = InputManager()["App.Load"] actionSaveAsVariants = InputManager()["App.SaveAs"] if currentInputAction in actionNewFileVariants: shouldSave = self.shouldSave() if shouldSave == QMessageBox.Yes: self.save() elif shouldSave == QMessageBox.Discard: return EditorHistory().clear() historyTools = self.getRegisteredTools( classNameFilters=["HistoryTool"]) for historyTools in historyTools: historyTools.onClear() self.newFile() EditorHistory().saveState("New file") self.currentFileName = None self.modified = False self.updateLabel() if currentInputAction in actionSaveVariants: self.save() if currentInputAction in actionLoadVariants: shouldSave = self.shouldSave() if shouldSave == QMessageBox.Yes: self.save() elif shouldSave == QMessageBox.Discard: return self.load() if currentInputAction in actionSaveAsVariants: self.save(True)
def test_input_action(self): a1 = InputAction("a1", "g1", QtCore.Qt.MouseButton.LeftButton, [], QtCore.Qt.ControlModifier | QtCore.Qt.AltModifier) a2 = InputAction("a1", "g1", QtCore.Qt.MouseButton.LeftButton, [], QtCore.Qt.ControlModifier | QtCore.Qt.AltModifier) self.assertEqual(a1, a2) a2.setModifiers(QtCore.Qt.ControlModifier) self.assertNotEqual(a1, a2) a1jsn = a1.toJson() a1Restored = InputAction("a1Restored") a1Restored.fromJson(a1jsn) self.assertEqual(a1, a1Restored)
def createDefaultInput(self): InputManager().registerAction( InputAction(name="Canvas.Pan", actionType=InputActionType.Mouse, group="Navigation", mouse=QtCore.Qt.MouseButton.MiddleButton)) InputManager().registerAction( InputAction(name="Canvas.Pan", actionType=InputActionType.Mouse, group="Navigation", mouse=QtCore.Qt.MouseButton.LeftButton, modifiers=QtCore.Qt.AltModifier)) InputManager().registerAction( InputAction(name="Canvas.Zoom", actionType=InputActionType.Mouse, group="Navigation", mouse=QtCore.Qt.MouseButton.RightButton)) InputManager().registerAction( InputAction(name="Canvas.FrameSelected", actionType=InputActionType.Keyboard, group="Navigation", key=QtCore.Qt.Key_F)) InputManager().registerAction( InputAction(name="Canvas.FrameAll", actionType=InputActionType.Keyboard, group="Navigation", key=QtCore.Qt.Key_H)) InputManager().registerAction( InputAction(name="Canvas.ZoomIn", actionType=InputActionType.Keyboard, group="Navigation", key=QtCore.Qt.Key_Equal, modifiers=QtCore.Qt.ControlModifier)) InputManager().registerAction( InputAction(name="Canvas.ZoomOut", actionType=InputActionType.Keyboard, group="Navigation", key=QtCore.Qt.Key_Minus, modifiers=QtCore.Qt.ControlModifier)) InputManager().registerAction( InputAction(name="Canvas.ResetScale", actionType=InputActionType.Keyboard, group="Navigation", key=QtCore.Qt.Key_R, modifiers=QtCore.Qt.ControlModifier)) InputManager().registerAction( InputAction(name="Canvas.AlignLeft", actionType=InputActionType.Keyboard, group="Refactoring", modifiers=QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier, key=QtCore.Qt.Key_Left)) InputManager().registerAction( InputAction(name="Canvas.AlignTop", actionType=InputActionType.Keyboard, group="Refactoring", modifiers=QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier, key=QtCore.Qt.Key_Up)) InputManager().registerAction( InputAction(name="Canvas.AlignRight", actionType=InputActionType.Keyboard, group="Refactoring", modifiers=QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier, key=QtCore.Qt.Key_Right)) InputManager().registerAction( InputAction(name="Canvas.AlignBottom", actionType=InputActionType.Keyboard, group="Refactoring", modifiers=QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier, key=QtCore.Qt.Key_Down)) InputManager().registerAction( InputAction(name="Canvas.Undo", actionType=InputActionType.Keyboard, group="Editing", modifiers=QtCore.Qt.ControlModifier, key=QtCore.Qt.Key_Z)) InputManager().registerAction( InputAction(name="Canvas.Redo", actionType=InputActionType.Keyboard, group="Editing", modifiers=QtCore.Qt.ControlModifier, key=QtCore.Qt.Key_Y)) InputManager().registerAction( InputAction(name="Canvas.KillSelected", actionType=InputActionType.Keyboard, group="Editing", key=QtCore.Qt.Key_Delete)) InputManager().registerAction( InputAction(name="Canvas.CopyNodes", actionType=InputActionType.Keyboard, group="Editing", key=QtCore.Qt.Key_C, modifiers=QtCore.Qt.ControlModifier)) InputManager().registerAction( InputAction(name="Canvas.CutNodes", actionType=InputActionType.Keyboard, group="Editing", key=QtCore.Qt.Key_X, modifiers=QtCore.Qt.ControlModifier)) InputManager().registerAction( InputAction(name="Canvas.DragCopyNodes", actionType=InputActionType.Mouse, group="Editing", mouse=QtCore.Qt.MouseButton.LeftButton, modifiers=QtCore.Qt.AltModifier)) InputManager().registerAction( InputAction(name="Canvas.DragCopyNodes", actionType=InputActionType.Mouse, group="Editing", mouse=QtCore.Qt.MouseButton.MiddleButton, modifiers=QtCore.Qt.AltModifier)) InputManager().registerAction( InputAction(name="Canvas.DragNodes", actionType=InputActionType.Mouse, group="Editing", mouse=QtCore.Qt.MouseButton.MiddleButton)) InputManager().registerAction( InputAction(name="Canvas.DragNodes", actionType=InputActionType.Mouse, group="Editing", mouse=QtCore.Qt.MouseButton.LeftButton)) InputManager().registerAction( InputAction(name="Canvas.DragChainedNodes", actionType=InputActionType.Mouse, group="Editing", mouse=QtCore.Qt.MouseButton.MiddleButton)) InputManager().registerAction( InputAction(name="Canvas.PasteNodes", actionType=InputActionType.Keyboard, group="Editing", key=QtCore.Qt.Key_V, modifiers=QtCore.Qt.ControlModifier)) InputManager().registerAction( InputAction(name="Canvas.DuplicateNodes", actionType=InputActionType.Keyboard, group="Editing", key=QtCore.Qt.Key_D, modifiers=QtCore.Qt.ControlModifier)) InputManager().registerAction( InputAction(name="Canvas.DisconnectPin", actionType=InputActionType.Mouse, group="Editing", mouse=QtCore.Qt.MouseButton.LeftButton, modifiers=QtCore.Qt.AltModifier)) InputManager().registerAction( InputAction(name="App.NewFile", actionType=InputActionType.Keyboard, group="IO", key=QtCore.Qt.Key_N, modifiers=QtCore.Qt.ControlModifier)) InputManager().registerAction( InputAction(name="App.Save", actionType=InputActionType.Keyboard, group="IO", key=QtCore.Qt.Key_S, modifiers=QtCore.Qt.ControlModifier)) InputManager().registerAction( InputAction(name="App.SaveAs", actionType=InputActionType.Keyboard, group="IO", key=QtCore.Qt.Key_S, modifiers=QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier)) InputManager().registerAction( InputAction(name="App.Load", actionType=InputActionType.Keyboard, group="IO", key=QtCore.Qt.Key_O, modifiers=QtCore.Qt.ControlModifier))