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.
master
Salvo 'LtWorf' Tomaselli 2015-06-07 13:37:24 +07:00
parent 54ffbbdc3c
commit 3060a8562f
1 changed files with 23 additions and 23 deletions

@ -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: