Fixed and changed semantic of open relation

Now relations are always named with the default name.

Multiple relations can be opened at once from the GUI.

Removed redundant code to select the default name for a relation.

Using system dependant splitter to determine the default name for a relation.
This commit is contained in:
Salvo 'LtWorf' Tomaselli 2015-06-02 12:35:47 +02:00
parent 9d4284d624
commit 8102dbe959
2 changed files with 31 additions and 45 deletions

View File

@ -23,6 +23,7 @@ import sys
import os import os
import os.path import os.path
import getopt import getopt
from relational import relation, parser from relational import relation, parser
version = "2.0" version = "2.0"
@ -85,8 +86,6 @@ if __name__ == "__main__":
import sip # needed on windows import sip # needed on windows
from PyQt5 import QtGui, QtWidgets from PyQt5 import QtGui, QtWidgets
#FIXME remove this
from relational_gui import maingui, guihandler, about, surveyForm
try: try:
from relational_gui import maingui, guihandler, about, surveyForm from relational_gui import maingui, guihandler, about, surveyForm
except: except:
@ -108,16 +107,13 @@ if __name__ == "__main__":
ui.setupUi(form) ui.setupUi(form)
form.restore_settings() form.restore_settings()
for i in range(len(files)): m = enumerate(map(os.path.isfile, files))
if not os.path.isfile(files[i]): invalid = ' '.join((files[i[0]] for i in (filter(lambda x: not x[1], m))))
print ("%s is not a file" % files[i],file=sys.stderr) if invalid:
printhelp(12) print ("%s: not a file" % invalid,file=sys.stderr)
f = files[i].split('/') printhelp(12)
defname = f[len(f) - 1].lower() if len(files):
if defname.endswith(".csv"): # removes the extension form.loadRelation(files)
defname = defname[:-4]
print ('Loading file "%s" with name "%s"' % (files[i], defname))
form.loadRelation(files[i], defname)
form.show() form.show()
sys.exit(app.exec_()) sys.exit(app.exec_())

View File

@ -18,6 +18,7 @@
# author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it> # author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
import sys import sys
import os import os
import os.path
from PyQt5 import QtCore, QtWidgets, QtWidgets from PyQt5 import QtCore, QtWidgets, QtWidgets
@ -276,7 +277,6 @@ class relForm(QtWidgets.QMainWindow):
event.accept() event.accept()
def save_settings(self): def save_settings(self):
print('save')
self.settings.setValue('maingui/geometry', self.saveGeometry()) self.settings.setValue('maingui/geometry', self.saveGeometry())
self.settings.setValue('maingui/windowState', self.saveState()) self.settings.setValue('maingui/windowState', self.saveState())
@ -306,50 +306,40 @@ class relForm(QtWidgets.QMainWindow):
ui.setupUi(self.About) ui.setupUi(self.About)
self.About.show() self.About.show()
def loadRelation(self, filename=None, name=None): def loadRelation(self, filenames=None):
'''Loads a relation. Without parameters it will ask the user which relation to load, '''Loads a relation. Without parameters it will ask the user which relation to load,
otherwise it will load filename, giving it name. otherwise it will load filename, giving it name.
It shouldn't be called giving filename but not giving name.''' It shouldn't be called giving filename but not giving name.'''
# Asking for file to load # Asking for file to load
if filename == None: if not filenames:
filename = QtWidgets.QFileDialog.getOpenFileName(self, QtWidgets.QApplication.translate( f = QtWidgets.QFileDialog.getOpenFileNames(self, QtWidgets.QApplication.translate(
"Form", "Load Relation"), "", QtWidgets.QApplication.translate("Form", "Relations (*.csv);;Text Files (*.txt);;All Files (*)")) "Form", "Load Relation"), "", QtWidgets.QApplication.translate("Form", "Relations (*.csv);;Text Files (*.txt);;All Files (*)"))
filename = compatibility.get_filename(filename) filenames = f[0]
# Default relation's name for f in filenames:
f = filename.split('/') # Split the full path # Default relation's name
defname = f[len(f) - 1].lower() # Takes only the lowercase filename name = os.path.basename(f).lower()
if len(defname) == 0: if len(name) == 0:
return
if (defname.endswith(".csv")): # removes the extension
defname = defname[:-4]
if name == None: # Prompt dialog to insert name for the relation
res = QtWidgets.QInputDialog.getText(
self, QtWidgets.QApplication.translate("Form", "New relation"), QtWidgets.QApplication.translate(
"Form", "Insert the name for the new relation"),
QtWidgets.QLineEdit.Normal, defname)
if res[1] == False or len(res[0]) == 0:
return return
name = compatibility.get_py_str(res[0]) if (name.endswith(".csv")): # removes the extension
name = name[:-4]
if not rtypes.is_valid_relation_name(name): if not rtypes.is_valid_relation_name(name):
r = QtWidgets.QApplication.translate( r = QtWidgets.QApplication.translate(
"Form", str("Wrong name for destination relation: %s." % name)) "Form", str("Wrong name for destination relation: %s." % name))
QtWidgets.QMessageBox.information( QtWidgets.QMessageBox.information(
self, QtWidgets.QApplication.translate("Form", "Error"), r) self, QtWidgets.QApplication.translate("Form", "Error"), r)
return continue
try: try:
self.relations[name] = relation.relation(filename) self.relations[name] = relation.relation(f)
except Exception as e: except Exception as e:
print (e) print (e)
QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate("Form", "Error"), "%s\n%s" % QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate("Form", "Error"), "%s\n%s" %
(QtWidgets.QApplication.translate("Form", "Check your query!"), e.__str__())) (QtWidgets.QApplication.translate("Form", "Check your query!"), e.__str__()))
return continue
self.updateRelations() self.updateRelations()