-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import subprocess | ||
import tkinter as tk | ||
from subprocess import CREATE_NEW_CONSOLE, Popen | ||
import os | ||
import signal | ||
|
||
|
||
|
||
|
||
process = None | ||
|
||
|
||
class ServerManager(tk.Tk): | ||
def __init__(self): | ||
super().__init__() | ||
self.initUI() | ||
process = None | ||
def initUI(self): | ||
global max_players_field | ||
global port_field | ||
global passwd_field | ||
# Create buttons to execute, stop, and restart the executable file | ||
execute_btn = tk.Button(self, text='Execute', command=self.execute) | ||
stop_btn = tk.Button(self, text='Stop', command=self.stop) | ||
restart_btn = tk.Button(self, text='Restart', command=self.restart) | ||
max_players_label = tk.Label(text="Max Players:") | ||
max_players_label.pack() | ||
max_players_field = tk.Entry() | ||
max_players_field.pack() | ||
|
||
port_label = tk.Label(text="Port:") | ||
port_label.pack() | ||
port_field = tk.Entry() | ||
port_field.pack() | ||
passwd_label = tk.Label(text="Password:") | ||
passwd_label.pack() | ||
passwd_field = tk.Entry() | ||
passwd_field.pack() | ||
|
||
|
||
|
||
|
||
|
||
|
||
# Set up the layout | ||
execute_btn.pack(side='top', fill='x') | ||
stop_btn.pack(side='top', fill='x') | ||
restart_btn.pack(side='top', fill='x') | ||
process = None | ||
def execute(self): | ||
print("su2") | ||
max_players = max_players_field.get() | ||
port = port_field.get() | ||
passwd = passwd_field.get() | ||
global process | ||
global pid | ||
# Replace "path/to/executable" with the actual path to the executable file | ||
process = subprocess.Popen(f'AMP_Server.exe {port} {max_players} {passwd}', creationflags=CREATE_NEW_CONSOLE) | ||
|
||
|
||
|
||
|
||
|
||
|
||
def stop(self): | ||
global process | ||
global pid | ||
print("su1") | ||
# Terminate the subprocess | ||
os.kill((process.pid), signal.SIGTERM) | ||
|
||
|
||
def restart(self): | ||
print("su3") | ||
# Restart the executable by stopping it and then starting it again | ||
self.stop() | ||
self.execute() | ||
|
||
|
||
if __name__ == '__main__': | ||
server_manager = ServerManager() | ||
server_manager.mainloop() |