У меня есть своя «реализация» отмены/повтора и команды. Я хотел бы получить рекомендации и комментарии к моему коду. Где я ошибаюсь, может быть, дело в чем-то другом?
Что нужно исправить? На данный момент всё работает, но мне кажется, что я просто подкорректировал код под нужный результат, и сделал это не правильно.
import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QLineEdit, QPushButton, QWidget
from PySide6.QtGui import QKeySequence,QUndoStack, QUndoCommand
from PySide6.QtCore import Qt
class Command():
def __init__(self) -> None:
self.commands=[]
self.last_command_executed=-1
def push(self,object,attr,params):
self.commands.append({'object':object,'name_attr':attr,'params':params})
self.last_command_executed+=1
def exec_command(self,number_command):
self.commands[number_command]['object'].blockSignals(True)
getattr(self.commands[number_command]['object'],self.commands[number_command]['name_attr'])(self.commands[number_command]['params'])
self.commands[number_command]['object'].blockSignals(False)
self.last_command_executed=number_command
print('last_command_executed=',self.last_command_executed,'\n')
print('lenght comands=',len(self.commands),'\n')
def undo(self):
if self.last_command_executed!=0:
self.exec_command(self.last_command_executed-1 )
def redo(self):
if self.last_command_executed
Подробнее здесь: https://stackoverflow.com/questions/789 ... ck-signals