def unitTest12(ip, address): topics = { 1: 'animals', 2: 'countries', 3: 'foods', 4: 'countries', 5: 'phones', 6: 'universities', 7: 'phones', 8: 'laptops', 9: 'foods', 10: 'laptops', 11: 'laptops', 12: 'animals' } topic = topics[random.randint(1, 12)] publisher = Publisher(ip, address, '5556', '6002', topic) publisher.register()
def main(): pub = Publisher(['lunch', 'dinner']) bob = Subscriber('Bob') alice = Subscriber('Alice') john = Subscriber('John') pub.register("lunch", bob) pub.register("dinner", alice) pub.register("lunch", john) pub.register("dinner", john) pub.dispatch("lunch", "It's lunchtime!") pub.dispatch("dinner", "Dinner is served")
from Tkinter import Label, PhotoImage, Frame from threading import Thread from Publisher import Publisher from Subscriber import Subscriber import time # Creating the observer (that is connected to a channel) pub = Publisher(["channel1"]) sub1 = Subscriber('SUB1') pub.register("channel1", sub1) # Class GUI which inherts from Thread (to obtained multithreading) class GUI(Thread): def __init__(self, master, mw, mh): # Basic settings of display self.root = master self.w, self.h = mw, mh self.root.overrideredirect(1) self.root.geometry("%dx%d+0+0" % (self.w, self.h)) self.root.configure(background='black') master.title("DISPLAY") self.frameLeftTop = Frame(master, bg="black", width=self.w / 6, height=self.h / 6) self.frameMiddleTop = Frame(master, bg="black",