I am writing a program that has a panel of buttons on the right hand side, that successfully binds a method to each, dependant on user input/actions. My issues is that I cannot unbind()
the method explicitely, as the method bound is dynamic.
Consider;
i = 1
while i <= 8:
string = "action" + str(i)
#Buttons named 'action1, action1, ..., action8'
ref = self.ids[string]
ref.text = ""
observers = ref.get_property_observers('on_release')
print observers
ref.unbind()
ref.bind(on_release=partial(self.BlankMethod, arg1))
i += 1
The lines;
observers = ref.get_property_observers('on_release')
print observers
Show that I have an increasing list of weakmethods bound, every time the method is called, but the unbind function does not unbind the method.
Although my code example does not show it, the bound method changes regularly, and the self.BlankMethod
was meant to override the original binding. This is not the case, and the Button
's bound methods increase.
[<kivy.weakmethod.WeakMethod object at 0x7f8cc826a810>]
[<kivy.weakmethod.WeakMethod object at 0x7f8cc826a850>, <kivy.weakmethod.WeakMethod object at 0x7f8cc826acd0>]
I have tried;
observers = ref.get_property_observers('on_release')
if observers != []:
for observer in observers:
ref.unbind(observer)
ref.bind(on_release=partial(self.Blank))
But I am returned the error;
TypeError: unbind() takes exactly 0 positional arguments (1 given)
I had a look at using funbind()
function but subsequently given;
AttributeError: 'Button' object has no attribute 'funbind'
Trying to use fbind()
prior to funbind()
also gives the same error, but with respect to the button not having an fbind()
attribute.
How can I list all bound methods of an object, and subsequently unbind them?