It is my implementation of the Observer pattern, I don't generally use it directly but import it into another script which is my implementation of the Model–view–controller pattern.
Which is then used with my GUI programming.
Here is an example of it in action using a forum thread subscription example.
Which is then used with my GUI programming.
Here is an example of it in action using a forum thread subscription example.
import ysignal class ForumThread: def __init__(self): self.ysignal = ysignal.Ysignal() def post_to_thread(self, post): self.ysignal.emit(post) def subscribe_to_thread(self, slot): self.ysignal.bind(slot) class Forum: def update_forum_on_new_post(self, post): print('The forum updated its new post list: {}'.format(post)) def forum_dweller(post): print('forum_dweller got the post: {}'.format(post)) def another_forum_dweller(post): print('another_forum_dweller got the post: {}'.format(post)) forum = Forum() forum_thread = ForumThread() forum_thread.subscribe_to_thread(forum.update_forum_on_new_post) forum_thread.subscribe_to_thread(forum_dweller) forum_thread.subscribe_to_thread(another_forum_dweller) forum_thread.post_to_thread('someone posted something') del forum_dweller # this forum dweller got banned forum_thread.post_to_thread('something else was posted')
Output:forum_dweller got the post: someone posted something
another_forum_dweller got the post: someone posted something
The forum updated its new post list: someone posted something
another_forum_dweller got the post: something else was posted
The forum updated its new post list: something else was posted