def createMap(self): """ Method called when the "Create" button is pressed. The filled values are checked and if they are correct, a map is generated, in a thread """ valid = True try: name = str(self._mapNameField.text()).strip() width = self._mapWidthField.value() height = self._mapHeightField.value() if width <= 0 or height <= 0: self.displayMessage("Positive number expected for the width and the height") valid = False elif name == "": self.displayMessage("A world name must be provided") valid = False except ValueError: self.displayMessage("Positive number expected for the width and the height") valid = False if valid: self._app.setMapName(name) name = config.tempDir + '/' + self._app.escapeName(name) self._app.setMapFileName(name) self.displayMessage("Generating...") self._saveButton.setEnabled(False) self._cancelButton.setEnabled(False) self._thread = worker.generatorThread(self._app, width, height) self._thread.generatorError.connect(self.displayMessage) self._thread.generatorSuccess.connect(self._parent.openMap) self._thread.generatorSuccess.connect(self.close) self._thread.start()
def createMap(self): """ Method called when the "Create" button is pressed. The filled values are checked and if they are correct, a map is generated, in a thread """ valid = True try: name = str(self._mapNameField.text()).strip() width = self._mapWidthField.value() height = self._mapHeightField.value() if width <= 0 or height <= 0: self.displayMessage(_('ERROR_INVALID_WIDTH_HEIGHT_VALUE')) valid = False elif name == "": self.displayMessage(_('ERROR_EMPTY_MAP_NAME')) valid = False except ValueError: self.displayMessage(_('ERROR_INVALID_WIDTH_HEIGHT_VALUE')) valid = False if valid: self._app.setMapName(name) name = config.tempDir + '/' + self._app.escapeName(name) self._app.setMapFileName(name) self.displayMessage(_('LOADING_GENERATION_TEXT')) self._saveButton.setEnabled(False) self._cancelButton.setEnabled(False) self._thread = worker.generatorThread(self._app, width, height) self._thread.generatorError.connect(self.displayMessage) self._thread.generatorSuccess.connect(self._parent.openMap) self._thread.generatorSuccess.connect(self.close) self._thread.start()