Error is passed to GuiConfiguration if there is Invalid config value

Window reappears correctly after entering invalid data.
This commit is contained in:
Uriziel 2013-06-05 19:25:24 +02:00
parent 1a69efeef9
commit 51cbddf325
2 changed files with 12 additions and 8 deletions

View File

@ -101,7 +101,7 @@ class ConfigurationGetter(object):
if(hostNotValid or portNotValid): if(hostNotValid or portNotValid):
raise InvalidConfigValue("Hostname can't be empty") raise InvalidConfigValue("Hostname can't be empty")
elif(self._config[key] == "" or self._config[key] is None): elif(self._config[key] == "" or self._config[key] is None):
raise InvalidConfigValue("{} can't be empty".format(key)) raise InvalidConfigValue("{} can't be empty".format(key.capitalize()))
def _overrideConfigWithArgs(self, args): def _overrideConfigWithArgs(self, args):
for key, val in vars(args).items(): for key, val in vars(args).items():
@ -156,20 +156,20 @@ class ConfigurationGetter(object):
def _checkConfig(self): def _checkConfig(self):
try: try:
self._validateArguments() self._validateArguments()
except InvalidConfigValue: except InvalidConfigValue as e:
try: try:
for key, value in self._promptForMissingArguments().items(): for key, value in self._promptForMissingArguments(e.message).items():
self._config[key] = value self._config[key] = value
self._checkConfig() self._checkConfig()
except: except:
sys.exit() sys.exit()
def _promptForMissingArguments(self): def _promptForMissingArguments(self, error = None):
if(self._config['noGui']): if(self._config['noGui']):
print getMessage("en", "missing-arguments-error") print getMessage("en", "missing-arguments-error")
sys.exit() sys.exit()
elif(GuiConfiguration): elif(GuiConfiguration):
gc = GuiConfiguration(self._config) gc = GuiConfiguration(self._config, error = error)
gc.setAvailablePaths(self._playerFactory.getAvailablePlayerPaths()) gc.setAvailablePaths(self._playerFactory.getAvailablePlayerPaths())
gc.run() gc.run()
return gc.getProcessedConfiguration() return gc.getProcessedConfiguration()

View File

@ -7,12 +7,16 @@ import sys
from syncplay.messages import getMessage from syncplay.messages import getMessage
class GuiConfiguration: class GuiConfiguration:
def __init__(self, config): def __init__(self, config, error = None):
self.config = config self.config = config
self._availablePlayerPaths = [] self._availablePlayerPaths = []
self.error = error
def run(self): def run(self):
try:
self.app = QtGui.QApplication(sys.argv) self.app = QtGui.QApplication(sys.argv)
except:
pass
dialog = ConfigDialog(self.config, self._availablePlayerPaths) dialog = ConfigDialog(self.config, self._availablePlayerPaths)
dialog.exec_() dialog.exec_()