def __init__(self): """ :param player: 0 = player one, 1 = player two """ arcade.View.__init__(self) # initialize the threading.Thread parent threading.Thread.__init__(self) # create a threading lock self.the_lock = threading.Lock() # set this thread as a daemon thread self.daemon = True # create a threading event that will allow the start # and stopping of thread processing self.run_the_thread = threading.Event() # initially allow the thread to run self.run_the_thread = True self.start_backplane() # initialize the python-banyan base class parent. # if the backplane_ip_address is == None, then the local IP # address is used. # The process name is just informational for the Banyan header # printed on the console. # The loop_time the amount of idle time in seconds for the # banyan receive_loop to wait to check for the next message # available in its queue. BanyanBase.__init__(self, back_plane_ip_address=None, process_name=PROCESS_NAME, loop_time=.0001) # add banyan subscription topic self.set_subscriber_topic("ip_inserted") self.set_subscriber_topic("result_connection") self.ip_address = self.back_plane_ip_address # Set the working directory (where we expect to find files) to the same # directory this .py file is in. You can leave this out of your own # code, but it is needed to easily run the examples using "python -m" # as mentioned at the top of this program. file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) # start the second thread self.start() self.background = None
def on_click(self): global ip_address_inserted ip_address_inserted = str(self.input_box.text) # initialize the threading.Thread parent threading.Thread.__init__(self) # create a threading lock self.the_lock = threading.Lock() # set this thread as a daemon thread self.daemon = True # create a threading event that will allow the start # and stopping of thread processing self.run_the_thread = threading.Event() # initially allow the thread to run self.run_the_thread = True BanyanBase.__init__(self, back_plane_ip_address=ip_address_inserted, process_name=PROCESS_NAME, loop_time=.0001) # add banyan subscription topic self.set_subscriber_topic("ip_inserted") self.set_subscriber_topic("result_connection") # start the second thread self.start() # send message topic = "ip_inserted" payload = {"ip": ip_address_inserted} self.publish_payload(payload, topic) print("Ip Sent")
def __init__(self, back_plane_ip_address=None, process_name=None, player=0): """ :param back_plane_ip_address: specify if running across multiple computers :param process_name: the name in the banyan header for this process :param player: 0=coins 1=female sprite """ # Call the parent class initializer title = SCREEN_TITLE + str(player) arcade.Window.__init__(self, SCREEN_WIDTH, SCREEN_HEIGHT, title) # Variables that will hold sprite lists self.all_sprites_list = None self.coin_list = None # Set up the player info self.player_sprite = None # save the player for this instance self.player = player # set score to zero self.score = 0 # Don't show the mouse cursor self.set_mouse_visible(False) # flag to start coin movement - change flag state # by pressing the left mouse button self.go = False # initially turn collision detection off. # pressing the right mouse button will enable it. self.run_collision_detection = False # initialize the threading.Thread parent threading.Thread.__init__(self) # create a threading lock self.the_lock = threading.Lock() # set this thread as a daemon thread self.daemon = True # create a threading event that will allow the start # and stopping of thread processing self.run_the_thread = threading.Event() # initially allow the thread to run self.run_the_thread = True # if not backplane address is specified, try to start # the backplane. If an address is specified, the user # is trying to connect to an already running backplane if not back_plane_ip_address: self.start_backplane() # initialize the python-banyan base class parent. # if the backplane_ip_address is == None, then the local IP # address is used. # The process name is just informational for the Banyan header # printed on the console. # The loop_time the amount of idle time in seconds for the # banyan receive_loop to wait to check for the next message # available in its queue. BanyanBase.__init__(self, back_plane_ip_address=back_plane_ip_address, process_name=process_name, loop_time=.0001) # add banyan subscription topics self.set_subscriber_topic('enable_coins') self.set_subscriber_topic('enable_collisions') self.set_subscriber_topic('p1_move') self.set_subscriber_topic('update_coins') self.set_subscriber_topic('remove_coin') arcade.set_background_color(arcade.color.AMAZON) # initialize some things self.setup() # start the second thread self.start() # start the arcade loop try: arcade.run() except KeyboardInterrupt: # stop the thread from further processing self.stop_event = False # we are outta here! sys.exit(0)