diff --git a/CHANGELOG b/CHANGELOG index e95fd4b..5c7d04f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -91,4 +91,5 @@ 0.11 - Font is set only on windows (Rev 206) -- Improved futile_union_intersection_subtraction in case of A-A, when A is a sub-query (Rev 208) \ No newline at end of file +- Improved futile_union_intersection_subtraction in case of A-A, when A is a sub-query (Rev 208) +- Can load relations specified in command line (Rev 209) \ No newline at end of file diff --git a/relational.1 b/relational.1 index f95244a..2f4c4f2 100644 --- a/relational.1 +++ b/relational.1 @@ -4,6 +4,8 @@ relational \(em Python implementation of Relational algebra. .SH "SYNOPSIS" .PP \fBrelational\fR [\-v\fR\fP] +.br +\fBrelational\fR [ FILE .\|.\|.] .SH "DESCRIPTION" .PP diff --git a/relational_gui.py b/relational_gui.py index 5f8cdc5..c71f10c 100755 --- a/relational_gui.py +++ b/relational_gui.py @@ -48,6 +48,16 @@ if __name__ == "__main__": ui = maingui.Ui_Form() ui.setupUi(Form) + + for i in range(1,len(sys.argv)): + f=sys.argv[i].split('/') + defname=f[len(f)-1].lower() + if (defname.endswith(".csv") or defname.endswith(".tlb")): #removes the extension + defname=defname[:-4] + print 'Loading file "%s" with name "%s"' % (sys.argv[i],defname) + ui.loadRelation(sys.argv[i],defname) + + Form.show() sys.exit(app.exec_()) diff --git a/relational_gui/maingui.py b/relational_gui/maingui.py index 37c781d..546d597 100644 --- a/relational_gui/maingui.py +++ b/relational_gui/maingui.py @@ -157,13 +157,21 @@ class Ui_Form(object): ui.setupUi(self.About) self.About.show() - def loadRelation(self): + def loadRelation(self,filename=None,name=None): + '''Loads a relation. Without parameters it will ask the user which relation to load, + otherwise it will load filename, giving it name''' #Asking for file to load - filename = QtGui.QFileDialog.getOpenFileName(None,QtGui.QApplication.translate("Form", "Load Relation"),"",QtGui.QApplication.translate("Form", "Relations (*.csv);;Old Relations (*.tlb);;Text Files (*.txt);;All Files (*)")) + if filename==None: + filename = QtGui.QFileDialog.getOpenFileName(None,QtGui.QApplication.translate("Form", "Load Relation"),"",QtGui.QApplication.translate("Form", "Relations (*.csv);;Old Relations (*.tlb);;Text Files (*.txt);;All Files (*)")) + + #Default relation's name + f=str(filename.toUtf8()).split('/') #Split the full path + defname=f[len(f)-1].lower() #Takes only the lowercase filename + + else: + f=filename.split('/') #Split the full path + defname=f[len(f)-1].lower() #Takes only the lowercase filename - #Default relation's name - f=str(filename.toUtf8()).split('/') #Split the full path - defname=f[len(f)-1].lower() #Takes only the lowercase filename if len(defname)==0: return use_csv=True @@ -172,16 +180,18 @@ class Ui_Form(object): defname=defname[:-4] use_csv=False #Old format, not using csv - if (defname.endswith(".csv")): #removes the extension defname=defname[:-4] - res=QtGui.QInputDialog.getText(self.Form, QtGui.QApplication.translate("Form", "New relation"),QtGui.QApplication.translate("Form", "Insert the name for the new relation"), - QtGui.QLineEdit.Normal,defname) - if res[1]==False: - return - - self.relations[str(res[0].toUtf8())]=relation.relation(filename,use_csv) + if name==None: + res=QtGui.QInputDialog.getText(self.Form, QtGui.QApplication.translate("Form", "New relation"),QtGui.QApplication.translate("Form", "Insert the name for the new relation"), + QtGui.QLineEdit.Normal,defname) + if res[1]==False or len(res[0])==0: + return + self.relations[str(res[0].toUtf8())]=relation.relation(filename,use_csv) + else: + self.relations[name]=relation.relation(filename,use_csv) + self.updateRelations() def insertTuple(self): '''Shows an input dialog and inserts the inserted tuple into the selected relation'''