From 3060a8562f755495f83c38121a1aba7eb6382c55 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Sun, 7 Jun 2015 13:37:24 +0200 Subject: [PATCH] Ask for relation name if filename is not valid By default when loading a file, a relation with the same name is created. Now, if the filename is not a valid relation name, the user will be prompted to manually insert a relation name. De-duplicated code for doing this when a new relation is created. --- relational_gui/guihandler.py | 46 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/relational_gui/guihandler.py b/relational_gui/guihandler.py index 909af66..70bac46 100644 --- a/relational_gui/guihandler.py +++ b/relational_gui/guihandler.py @@ -240,12 +240,7 @@ class relForm(QtWidgets.QMainWindow): self.relations[i.text()] = result self.updateRelations() - def newRelation(self): - from relational_gui import creator - result = creator.edit_relation() - - if result == None: - return + def promptRelationName(self): while True: res = QtWidgets.QInputDialog.getText( self, @@ -255,9 +250,8 @@ class relForm(QtWidgets.QMainWindow): QtWidgets.QLineEdit.Normal, '' ) if res[1] == False:# or len(res[0]) == 0: - return + return None name = res[0] - if not rtypes.is_valid_relation_name(name): r = QtWidgets.QApplication.translate( "Form", str("Wrong name for destination relation: %s." % name) @@ -266,16 +260,25 @@ class relForm(QtWidgets.QMainWindow): self, QtWidgets.QApplication.translate("Form", "Error"), r ) continue + return name - try: - self.relations[name] = result - self.updateRelations() - except Exception as e: - print (e) - QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate("Form", "Error"), "%s\n%s" % - (QtWidgets.QApplication.translate("Form", "Check your query!"), e.__str__())) - finally: - return + def newRelation(self): + from relational_gui import creator + result = creator.edit_relation() + + if result == None: + return + name = self.promptRelationName() + + try: + self.relations[name] = result + self.updateRelations() + except Exception as e: + print (e) + QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate("Form", "Error"), "%s\n%s" % + (QtWidgets.QApplication.translate("Form", "Check your query!"), e.__str__())) + finally: + return def closeEvent(self, event): self.save_settings() @@ -330,14 +333,11 @@ class relForm(QtWidgets.QMainWindow): if (name.endswith(".csv")): # removes the extension name = name[:-4] - else: - name.replace('.','') if not rtypes.is_valid_relation_name(name): - r = QtWidgets.QApplication.translate( - "Form", str("Wrong name for destination relation: %s." % name)) - QtWidgets.QMessageBox.information( - self, QtWidgets.QApplication.translate("Form", "Error"), r) + name = self.promptRelationName() + + if name is None: continue try: