From 5f5341f96d029b84cdd2c33f225abaada021b56f Mon Sep 17 00:00:00 2001 From: Dpeta <69427753+Dpeta@users.noreply.github.com> Date: Sun, 4 Oct 2020 18:28:43 +0000 Subject: [PATCH] Moved server promt to main thread This is also not a perfect or very pretty solution, especially as configparser is now a dependency. But this is still an improvement over how it was before, as this doesn't seem to cause crashes. --- pesterchum.py | 34 +++++++++++++++++++++++++++++++++- profile.py | 35 ++++++----------------------------- server.ini | 2 ++ 3 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 server.ini diff --git a/pesterchum.py b/pesterchum.py index 5824eb2..673afff 100644 --- a/pesterchum.py +++ b/pesterchum.py @@ -1,5 +1,6 @@ # pesterchum import os, shutil, sys, getopt +import configparser if os.path.dirname(sys.argv[0]): os.chdir(os.path.dirname(sys.argv[0])) import logging @@ -136,7 +137,6 @@ BOTNAMES.extend(CUSTOMBOTS) _CONSOLE_ENV = AttrDict() _CONSOLE_ENV.PAPP = None - class waitingMessageHolder(object): def __init__(self, mainwindow, **msgfuncs): self.mainwindow = mainwindow @@ -3043,6 +3043,38 @@ class MainProgram(QtCore.QObject): options = self.oppts(sys.argv[1:]) + # Choose a server by qt message box. + # Writes the result to server.ini + + msgBox = QtGui.QMessageBox() + msgBox.setIcon(QtGui.QMessageBox.Information) + msgBox.setWindowTitle("Choose a server.") + msgBox.setText("Which server do you want to connect to?") + msgBox.addButton(QtGui.QPushButton("ghostDunk's server (Official)"), QtGui.QMessageBox.YesRole) + msgBox.addButton(QtGui.QPushButton("turntechCatnip's server"), QtGui.QMessageBox.NoRole) + msgBox.addButton(QtGui.QPushButton('kaliope.ddns.net'), QtGui.QMessageBox.RejectRole) + ret = msgBox.exec_() + reply = msgBox.buttonRole(msgBox.clickedButton()) + + config = configparser.ConfigParser() + config.read('server.ini') + + if (reply==QtGui.QMessageBox.YesRole): + print("Server is: irc.mindfang.org") + config['SERVER']['server'] = 'irc.mindfang.org' + if (reply==QtGui.QMessageBox.NoRole): + print("Server is: 178.84.124.125") + config['SERVER']['server'] = '178.84.124.125' + if (reply==QtGui.QMessageBox.RejectRole): + print("Server is: kaliope.ddns.net") + config['SERVER']['server'] = 'kaliope.ddns.net' + + #Write result to server.ini + with open('server.ini', 'w') as configfile: + config.write(configfile) + + + def doSoundInit(): # TODO: Make this more uniform, adapt it into a general function. if pygame and pygame.mixer: diff --git a/profile.py b/profile.py index f4cbd25..b8e4a17 100644 --- a/profile.py +++ b/profile.py @@ -14,6 +14,8 @@ from mood import Mood from dataobjs import PesterProfile, pesterQuirk, pesterQuirks from parsetools import convertTags, addTimeInitial, themeChecker, ThemeException +import configparser # For loading server.ini + _datadir = ostools.getDataDir() class PesterLog(object): @@ -285,35 +287,10 @@ class userConfig(object): def server(self): if hasattr(self.parent, 'serverOverride'): return self.parent.serverOverride - # Okay, so I tried to use qt to promt the user to choose a server via a message box. - # It seems to ...work... but I know that this isn't the proper way to implement something like this at all. - # But, uh, I have no clue how to properly use qt. - # If anyone knows how to actually implement something like this please feel free to fix this. - # HOPEFULLY this is a temporary solution - - msgBox = QtGui.QMessageBox() - msgBox.setIcon(QtGui.QMessageBox.Information) - msgBox.setWindowTitle("Choose a server.") - msgBox.setText("Which server do you want to connect to?") - msgBox.addButton(QtGui.QPushButton("ghostDunk's server (Official)"), QtGui.QMessageBox.YesRole) - msgBox.addButton(QtGui.QPushButton("turntechCatnip's server"), QtGui.QMessageBox.NoRole) - msgBox.addButton(QtGui.QPushButton('kaliope.ddns.net'), QtGui.QMessageBox.RejectRole) - ret = msgBox.exec_() - #pressed_button = msgBox.clickedButton() - reply = msgBox.buttonRole(msgBox.clickedButton()) - - if (reply==QtGui.QMessageBox.YesRole): - print("Server is: irc.mindfang.org") - return self.config.get('server', 'irc.mindfang.org') - if (reply==QtGui.QMessageBox.NoRole): - print("Server is: 178.84.124.125") - return self.config.get('server', '178.84.124.125') - if (reply==QtGui.QMessageBox.RejectRole): - print("Server is: kaliope.ddns.net") - return self.config.get('server', 'kaliope.ddns.net') - - #print(reply) - #return self.config.get('server', 'irc.mindfang.org') + # Get chosen server from server.ini + config = configparser.ConfigParser() + config.read('server.ini') + return self.config.get('server', config['SERVER']['server']) def port(self): if hasattr(self.parent, 'portOverride'): return self.parent.portOverride diff --git a/server.ini b/server.ini new file mode 100644 index 0000000..82b0c28 --- /dev/null +++ b/server.ini @@ -0,0 +1,2 @@ +[SERVER] +server = 178.84.124.125