Optimized saving of relations
git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@51 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
parent
278036081f
commit
863289d29c
@ -40,3 +40,4 @@
|
|||||||
- Expressions between quotes aren't parsed anymore
|
- Expressions between quotes aren't parsed anymore
|
||||||
- When adding a relation, the file must be choosen 1st, and then the default relation's name is the same as the filename
|
- When adding a relation, the file must be choosen 1st, and then the default relation's name is the same as the filename
|
||||||
- Changed internal rename method. Now uses a dictionary
|
- Changed internal rename method. Now uses a dictionary
|
||||||
|
- Optimized saving of relations
|
22
maingui.py
22
maingui.py
@ -31,39 +31,41 @@ class Ui_Form(object):
|
|||||||
try:
|
try:
|
||||||
#Converting string to utf8 and then from qstring to normal string
|
#Converting string to utf8 and then from qstring to normal string
|
||||||
query=str(self.txtQuery.text().toUtf8())
|
query=str(self.txtQuery.text().toUtf8())
|
||||||
expr=parser.parse(query)
|
expr=parser.parse(query)#Converting expression to python code
|
||||||
print query,"-->" , expr
|
print query,"-->" , expr #Printing debug
|
||||||
result=eval(expr,self.relations)
|
result=eval(expr,self.relations) #Evaluating the expression
|
||||||
|
|
||||||
res_rel=str(self.txtResult.text())#result relation's name
|
res_rel=str(self.txtResult.text())#result relation's name
|
||||||
self.txtResult.setText("")
|
self.txtResult.setText("") #Sets the result relation name to none
|
||||||
if len(res_rel)==0:
|
if len(res_rel)==0: #If no name is set use the default last_
|
||||||
res_rel="last_"
|
res_rel="last_"
|
||||||
|
|
||||||
self.relations[res_rel]=result
|
self.relations[res_rel]=result #Add the relation to the dictionary
|
||||||
self.updateRelations()
|
self.updateRelations() #update the list
|
||||||
|
|
||||||
self.showRelation(result)
|
self.showRelation(result) #Show the result in the table
|
||||||
except:
|
except:
|
||||||
QtGui.QMessageBox.information(None,QtGui.QApplication.translate("Form", "Error"),QtGui.QApplication.translate("Form", "Check your query!") )
|
QtGui.QMessageBox.information(None,QtGui.QApplication.translate("Form", "Error"),QtGui.QApplication.translate("Form", "Check your query!") )
|
||||||
def showRelation(self,rel):
|
def showRelation(self,rel):
|
||||||
self.table.clear()
|
self.table.clear()
|
||||||
|
|
||||||
if rel==None:
|
if rel==None: #No relation to show
|
||||||
self.table.setColumnCount(1)
|
self.table.setColumnCount(1)
|
||||||
self.table.headerItem().setText(0,"Empty relation")
|
self.table.headerItem().setText(0,"Empty relation")
|
||||||
return
|
return
|
||||||
self.table.setColumnCount(len(rel.header.attributes))
|
self.table.setColumnCount(len(rel.header.attributes))
|
||||||
|
|
||||||
|
#Set content
|
||||||
for i in rel.content:
|
for i in rel.content:
|
||||||
item = QtGui.QTreeWidgetItem()
|
item = QtGui.QTreeWidgetItem()
|
||||||
for j in range(len(i)):
|
for j in range(len(i)):
|
||||||
item.setText(j, i[j])
|
item.setText(j, i[j])
|
||||||
self.table.addTopLevelItem(item)
|
self.table.addTopLevelItem(item)
|
||||||
|
|
||||||
|
#Sets columns
|
||||||
for i in range(len(rel.header.attributes)):
|
for i in range(len(rel.header.attributes)):
|
||||||
self.table.headerItem().setText(i,rel.header.attributes[i])
|
self.table.headerItem().setText(i,rel.header.attributes[i])
|
||||||
self.table.resizeColumnToContents(i)
|
self.table.resizeColumnToContents(i) #Must be done in order to avoid too small columns
|
||||||
|
|
||||||
|
|
||||||
def printRelation(self,*rel):
|
def printRelation(self,*rel):
|
||||||
|
@ -45,14 +45,11 @@ class relation (object):
|
|||||||
def save(self,filename):
|
def save(self,filename):
|
||||||
'''Saves the relation in a file'''
|
'''Saves the relation in a file'''
|
||||||
res=""
|
res=""
|
||||||
for f in self.header.attributes:
|
res+=" ".join(self.header.attributes)
|
||||||
res+="%s "%(f)
|
|
||||||
|
|
||||||
|
|
||||||
for r in self.content:
|
for r in self.content:
|
||||||
res+="\n"
|
res+="\n"
|
||||||
for i in r:
|
res+=" ".join(r)
|
||||||
res+="%s "% (i)
|
|
||||||
fp=file(filename,'w')
|
fp=file(filename,'w')
|
||||||
fp.write(res)
|
fp.write(res)
|
||||||
fp.close()
|
fp.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user