Python Forum
Ysignal - WeakRef Signal/Slots
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ysignal - WeakRef Signal/Slots
#3
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.
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


Messages In This Thread
Ysignal - WeakRef Signal/Slots - by Yoriz - Oct-10-2016, 08:36 PM
RE: Ysignal - WeakRef Signal/Slots - by micseydel - Oct-12-2016, 04:17 PM
RE: Ysignal - WeakRef Signal/Slots - by Yoriz - Oct-12-2016, 05:29 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020