From 690b69b2f45d63262e86ef3016fb0c8fadd98296 Mon Sep 17 00:00:00 2001 From: ndyer Date: Tue, 20 Dec 2022 12:36:54 -0500 Subject: [PATCH 1/2] added file to help get interface information --- pypong/networking/__init__.py | 0 pypong/networking/host.py | 36 +++++++++++++++++++++++++++++++++++ requirements.txt | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 pypong/networking/__init__.py create mode 100644 pypong/networking/host.py diff --git a/pypong/networking/__init__.py b/pypong/networking/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pypong/networking/host.py b/pypong/networking/host.py new file mode 100644 index 0000000..3ba7be4 --- /dev/null +++ b/pypong/networking/host.py @@ -0,0 +1,36 @@ +import psutil + + +class InterfaceInfo: + """ + Class used for storing interface information to make it easier to use + """ + def __init__(self, interface_name, address, subnet_mask): + self.interface_name = interface_name + self.address = address + self.subnet_mask = subnet_mask + + def __str__(self): + return '(Interface:{0}, Address:{1}, Subnet Mask:{2})'.format(self.interface_name, + self.address, self.subnet_mask) + + def __repr__(self): + return '(Interface:{0}, Address:{1}, Subnet Mask:{2})'.format(self.interface_name, + self.address, self.subnet_mask) + + +def main(): + raw_interface_data = psutil.net_if_addrs() + interface_data = [] + + # Extract needed information from psutil and put it into a InterfaceInfo object + for interface in raw_interface_data: + address = (raw_interface_data.get(interface)[0]).address + subnet_mask = (raw_interface_data.get(interface)[0]).netmask + interface_data.append(InterfaceInfo(interface, address, subnet_mask)) + + print(interface_data) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt index 1581372..fd1045c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -pygame~=2.1.2 \ No newline at end of file +pygame~=2.1.2 +psutil~=5.9.4 \ No newline at end of file From 10ce4f159534db70a95431834b0799049db95114 Mon Sep 17 00:00:00 2001 From: ndyer Date: Tue, 20 Dec 2022 18:17:47 -0500 Subject: [PATCH 2/2] added launcher gui --- pypong/networking/gui.py | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 pypong/networking/gui.py diff --git a/pypong/networking/gui.py b/pypong/networking/gui.py new file mode 100644 index 0000000..118077c --- /dev/null +++ b/pypong/networking/gui.py @@ -0,0 +1,66 @@ +""" +Starting launcher of the game. This is where you host new games or join other ones. +""" +import tkinter as tk + +global running + + +def main(): + """ + Runs the game launcher. + """ + main_window = tk.Tk() + main_window.title('PyPong Launcher') + main_window.resizable(width=False, height=False) + + main_window.geometry('500x250') + + def quit_launcher(): + """ + Quits the main menu. + """ + global running + running = False + + def get_games(): + """ + Refresh the games list. + """ + listbox.delete(0, tk.END) + listbox.insert(0, 'Searching for games...') + # Networking code will go here eventually + + # Create the top title label + title_label = tk.Label(text='PyPong Launcher', fg='white', bg='#000040', padx=1, pady=20) + title_label.pack(side=tk.TOP, fill=tk.BOTH) + + # Create the list of games + listbox = tk.Listbox(main_window) + listbox.pack(side=tk.LEFT, expand=True, fill=tk.BOTH) + # Add scrollbar + scrollbar = tk.Scrollbar(main_window) + scrollbar.pack(side=tk.LEFT, fill=tk.Y) + # Link scrollbar to list of games + listbox.config(yscrollcommand=scrollbar.set) + scrollbar.config(command=listbox.yview) + + # Create buttons + button_frame = tk.Frame(main_window) + tk.Button(button_frame, text='Host a Game', height=3, width=30).pack() + tk.Button(button_frame, text='Join Selected Game', height=3, width=30).pack() + tk.Button(button_frame, text='Refresh Game List', height=2, width=20, command=get_games).pack() + button_frame.pack(side=tk.RIGHT) + + # Set it so that if the X is pressed the application quits + main_window.protocol('WM_DELETE_WINDOW', quit_launcher) + + global running + running = True + + while running: + main_window.update() + + +if __name__ == '__main__': + main()