Error in list processing??
Class Diagram:
Here's the problem:
if I have a straight list:
Version of python is 3.9.5 running on MS-Windows (the PyCharm IDE, if that matters)
Anyone see anything obvious that I'm messing up?
Class Diagram:
Bindable (my class) list (built in)
\ /
+------------+----------+
|
V
BindableList
class Bindable:
def __init__(self):
super().__init__()
self._binds = {}
def bind(self, event, callback):
if event not in self._binds.keys:
self._binds[event] = []
self._binds[event].append(callback)
def event_generate(self, event_id, *params):
for callback in self._binds[event_id]:
callback(event_id, self, *params)
class BindableList(Bindable, list):
def __init__(self):
super().__init__()
def append(self, __object) -> None:
super().append(__object)
self.event_generate(BindableList.ITEM_APPENDED, __object)
def insert(self, index, __object) -> None:
super().insert(index, __object)
self.event_generate(BindableList.ITEM_INSERTED, index, __object)
def remove(self, __object) -> None:
super().remove(__object)
self.event_generate(BindableList.ITEM_REMOVED, __object)The purpose of BindableList is to keep a tkinter.ttk.Treeview synchronized with the various lists, even if the list is modified directly by someone else (i.e. a variation on the observer design pattern).Here's the problem:
if I have a straight list:
my_list = list() my_list.append(object1) my_list.append(object2) my_list.append(object3) my_list.remove(object2)all works fine. The resulting list only has object1 and object3 in it. HOWEVER, if I do:
my_list = BindableList() my_list.append(object1) my_list.append(object2) my_list.append(object3) my_list.remove(object2)then my_list always removed the first item in the list - i.e. the result of the above code is that my_list contains object2 and object3
Version of python is 3.9.5 running on MS-Windows (the PyCharm IDE, if that matters)
Anyone see anything obvious that I'm messing up?
