I'm creating a launcher, and I have a combobox that has two items with specific functions/method calls, trying to have checks if one of the items is checked and to call a method if so.
I tried using the combobox currentTextChanged and currentIndexChanged methods, but I don't see any new results from using the method.
from PySide2 import QtWidgets
import subprocess
import os
from ui import main, serverMenu
# Initates the basic UI elements
class MyApp(main.Ui_MainWindow, QtWidgets.QMainWindow):
def __init__(self):
super(MyApp, self).__init__()
self.setupUi(self)
# Sets the combobox item value to a blank item
self.option.setCurrentIndex(-1)
# Captures the string from the gamemode combobox
text = str(self.option.currentText())
# Checks if local game is set, only allows user to input username and hit the play button
if(self.option.currentTextChanged == "Local"):
self.option.setCurrentIndex(1)
print("I'm in local!")
self.IP.setText("127.0.0.1")
self.IP.setReadOnly(True)
if not self.name.text:
QtWidgets.QMessageBox.about(self, "IP address", "Hey! \nYou need a name in order to launch the game\n")
self.playButton.clicked.connect(self.localHost)
# Checks if server is selected, and blanks out all the details... will also pop up the favorite server details to add servers.
elif (text == "Server"):
print("I'm now in server")
self.IP.setText("")
if not self.IP.text:
QtWidgets.QMessageBox.about(self, "IP address", "Hey! \nYou need an IP address in order to launch the game!\n")
if not self.name.text:
QtWidgets.QMessageBox.about(self, "IP address", "Hey! \nYou need a name in order to launch the game\n")
self.playButton.clicked.connect(self.serverHost)
print("Current text is: " + text)
# Code to log onto a server that has already been started
def serverHost(self):
# Grabs the server text and IP to pass into panda
username = self.name.text()
IP_Address = self.IP.text()
# Sets up enviroment variables needed to launch the game
os.environ['input'] = '1'
os.environ['TTS_GAMESERVER'] = IP_Address
os.environ['TTS_PLAYCOOKIE'] = username
#os.environ['PANDADIRECTORY'] =
subprocess.Popen("C:/Panda3D-1.10.0/python/ppython.exe -m toontown.toonbase.ToontownStart", shell = False)
self.close()
# Code to start local host(DEFAULT OPTION)
def localHost(self):
backendDir = os.chdir("dev/backend/")
username = self.name.text()
# Check to prevent a blank user
if not username:
QtWidgets.QMessageBox.about(self, "Name required", "Hey! \nYou need a username before we can start!\n")
return
SW_HIDE = 0
info = subprocess.STARTUPINFO()
info.dwFlags = subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = SW_HIDE
subprocess.Popen(r"start-astron-cluster.bat", startupinfo = info)
subprocess.Popen(r"start-ai-server.bat", startupinfo = info)
subprocess.Popen(r"start-uberdog-server.bat", startupinfo = info)
returnDir = os.chdir("../../")
os.environ['input'] = '1'
input = os.environ['input']
os.environ['TTS_GAMESERVER'] = "127.0.0.1"
TTS_GAMESERVER = os.environ['TTS_GAMESERVER']
os.environ['TTS_PLAYCOOKIE'] = username
#os.environ['PANDADIRECTORY'] =
subprocess.Popen("C:\Panda3D-1.10.0\python\ppython.exe -m toontown.toonbase.ToontownStart", shell = False)
self.close()
if __name__ == "__main__":
app = QtWidgets.QApplication()
qt_app = MyApp()
qt_app.show()
app.exec_()
If I just check for text == Local, it'll call localhost and ignores server and launches localhost even if server is selected. I want it to be if localhost is selected, then it'll fill the details for local, but if the server is selected, it'll clear the the IP text and let the user pick it.