The class has a variable flag isChanged , which is True / False . This variable changes its state to истину when some changes have been made to the project, and to ложь when the project has been saved. Is it possible to somehow track the moment when the value of this variable changes, depending on its value, to make buttons (for example, save) active or not. Maybe you can somehow generate an event?
|
1 answer
You can wrap the property in getter / setter methods and perform some additional actions in them:
# Класс с обычным свойством class Foo: def __init__(self): self.is_changed = False # Класс с свойством с использованием getter/setter методов class Foo2: def __init__(self): self.__is_changed = False def set_is_changed(self, value): print('set is_changed. new value: {}, old: {}'.format(value, self.__is_changed)) self.__is_changed = value def get_is_changed(self): return self.__is_changed is_changed = property(get_is_changed, set_is_changed) f1 = Foo() f1.is_changed = True f2 = Foo2() f2.is_changed = True f2.is_changed = False Console:
set is_changed. new value: True, old: False set is_changed. new value: False, old: True |
Bool, and mb is setter / getter described by@property:) - gil9red