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 __init__(self, *args, **kwargs): if not os.path.exists(self.INPUT_CONFIG_PATH): self.createDefaultInput() data = InputManager().serialize() if not os.path.exists(os.path.dirname(self.INPUT_CONFIG_PATH)): os.makedirs(os.path.dirname(self.INPUT_CONFIG_PATH)) with open(self.INPUT_CONFIG_PATH, "w") as f: json.dump(data, f) else: with open(self.INPUT_CONFIG_PATH, "r") as f: data = json.load(f) InputManager().loadFromData(data)
def onShow(self, settings): clearLayout(self.layout) properties = PropertiesWidget() properties.setLockCheckBoxVisible(False) properties.setTearOffCopyVisible(False) groupActions = defaultdict(list) for actionName, variants in InputManager().getData().items(): for action in variants: groupActions[action.group].append(action) for groupName, variants in groupActions.items(): category = CollapsibleFormWidget(headName=groupName) for inputActionVariant in variants: actionWidget = InputActionWidget( inputActionRef=inputActionVariant) actionWidget.setAction(inputActionVariant) category.addWidget(label=inputActionVariant.getName(), widget=actionWidget, maxLabelWidth=150) properties.addWidget(category) category.setCollapsed(True) self.layout.addWidget(properties) spacerItem = QSpacerItem(10, 10, QSizePolicy.Minimum, QSizePolicy.Expanding) self.layout.addItem(spacerItem)
def __init__(self, *args, **kwargs): self.registerConfigFile("PREFS", os.path.join(self.CONFIGS_DIR, "prefs.ini")) self.registerConfigFile("APP_STATE", os.path.join(self.CONFIGS_DIR, "config.ini")) if not os.path.exists(self.INPUT_CONFIG_PATH): self.createDefaultInput() data = InputManager().serialize() if not os.path.exists(os.path.dirname(self.INPUT_CONFIG_PATH)): os.makedirs(os.path.dirname(self.INPUT_CONFIG_PATH)) with open(self.INPUT_CONFIG_PATH, "w") as f: json.dump(data, f) else: with open(self.INPUT_CONFIG_PATH, "r") as f: data = json.load(f) InputManager().loadFromData(data)
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 serialize(self, settings): data = InputManager().serialize() with open(ConfigManager().INPUT_CONFIG_PATH, "w") as f: json.dump(data, f, indent=4)
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))