I’m trying to add a Listener to a topic, where the Listener is a curried function (has one parameter), and it seems like it should work - but it doesn’t.
from functools import partial
def new_game_msg(*args):
pub.sendMessage(topicName='game.new', some_data='this is a test message')
def MakeStatusBar(top_frame):
statusbar = top_frame.CreateStatusBar()
statusbar.SetFieldsCount(3)
statusbar.SetStatusWidths([200, 200, -2])
status_func = partial(got_status_msg, statusbar)
status_func(some_data='Directly testing function currying') # Works
pub.subscribe(listener=status_func, topicName='game.new') # Breaks
# pub.subscribe(listener=got_msg, topicName='game.new') # Works, when alone
return statusbar
def got_status_msg(status_bar, some_data):
print(f"*** got_status_msg, args = {some_data}\n")
status_bar.SetStatusText(some_data, 0)
def got_msg(some_data):
print(f"*** got_msg: data = {some_data}\n")
I’d like the Listener to have a pointer to a StatusBar, for posting messages. (Note this is just experimentation-code, learning WxPython.) The error is:
Traceback (most recent call last):
File "/Code/wxpy/hex_test/src/wx/menu_bar.py", line 11, in new_game_msg
pub.sendMessage(topicName='game.new', some_data='this is a test message')
raise SenderUnknownMsgDataError(self.topicNameTuple,
pubsub.core.topicargspec.SenderUnknownMsgDataError:
Some optional args unknown in call to sendMessage('('game', 'new')', some_data): some_data
The Listener, as I understood it, can be any Callable - so is there a way of making this work? Thanks.