From c5af23d05c72ccf397a6e3daf314ac6f8e6239c0 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Sat, 8 Oct 2011 22:35:24 +0000 Subject: [PATCH] - apparently it works, needs further testing git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@319 014f5005-505e-4b48-8d0a-63407b615a7c --- CHANGELOG | 1 + relational_gui/compatibility.py | 19 ++++++++++-- relational_gui/guihandler.py | 53 +++++++-------------------------- relational_gui/survey.py | 2 +- relational_pyside/survey.py | 2 +- 5 files changed, 29 insertions(+), 48 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c0ce8ca..0fd44f6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ - Can send email in survey - Can check for new version online - Can use both PySide and PyQt +- Removed buttons for adding and deleting tuples 1.0 - Adds history in the GUI diff --git a/relational_gui/compatibility.py b/relational_gui/compatibility.py index be432a9..0886143 100644 --- a/relational_gui/compatibility.py +++ b/relational_gui/compatibility.py @@ -32,14 +32,27 @@ def get_py_str(a): '''Returns a python string out of a QString''' if pyqt: return str(a.toUtf8()) - return a #Already a python string in PySide + return str(a.encode("utf-8")) #Already a python string in PySide def set_utf8_text(component,text): - if pyqt: + if not pyqt: component.setText(text.decode("utf-8")) else: component.setText(QtCore.QString.fromUtf8(text)) def get_filename(filename): if pyqt: return str(filename.toUtf8()) - return filename[0] \ No newline at end of file + return filename[0] +def add_list_item(l,item): + if pyqt: + history_item=QtCore.QString() + history_item.append(item) + hitem=QtGui.QListWidgetItem(None,0) + hitem.setText(history_item) + l.addItem (hitem) + l.setCurrentItem(hitem) + else: + hitem=QtGui.QListWidgetItem(None,0) + hitem.setText(item) + l.addItem (hitem) + l.setCurrentItem(hitem) \ No newline at end of file diff --git a/relational_gui/guihandler.py b/relational_gui/guihandler.py index 1922754..50bbfbd 100644 --- a/relational_gui/guihandler.py +++ b/relational_gui/guihandler.py @@ -68,27 +68,26 @@ class relForm(QtGui.QMainWindow): '''Performs all the possible optimizations on the query''' self.undo=self.ui.txtQuery.text() #Storing the query in undo list - - query=compatibility.get_py_str(self.ui.txtQuery.text()).encode("utf-8") + query=compatibility.get_py_str(self.ui.txtQuery.text()) result=optimizer.optimize_all(query,self.relations) - compatibility.set_utf8_text(self.ui.TxtQuery,result) + compatibility.set_utf8_text(self.ui.txtQuery,result) def resumeHistory(self,item): itm=compatibility.get_py_str(item.text()).split(' = ',1) compatibility.set_utf8_text(self.ui.txtResult,itm[0]) - compatibility.set_utf8_text(self.ui.txtQuery,itm[1]) - + compatibility.set_utf8_text(self.ui.txtQuery,itm[1]) def execute(self): '''Executes the query''' query=compatibility.get_py_str(self.ui.txtQuery.text()) + res_rel=compatibility.get_py_str(self.ui.txtResult.text())#result relation's name if not rtypes.is_valid_relation_name(res_rel): QtGui.QMessageBox.information(self,QtGui.QApplication.translate("Form", "Error"),QtGui.QApplication.translate("Form", "Wrong name for destination relation.")) return - + try: #Converting string to utf8 and then from qstring to normal string expr=parser.parse(query)#Converting expression to python code @@ -103,16 +102,11 @@ class relForm(QtGui.QMainWindow): print e QtGui.QMessageBox.information(None,QtGui.QApplication.translate("Form", "Error"),"%s\n%s" % (QtGui.QApplication.translate("Form", "Check your query!"),e.__str__()) ) return - #Query was executed normally - #TODO fix THAT - #history_item=QtCore.QString() - #history_item.append(self.ui.txtResult.text()) - #history_item.append(u' = ') - #history_item.append(self.ui.txtQuery.text()) - #hitem=QtGui.QListWidgetItem(None,0) - #hitem.setText(history_item) - #self.ui.lstHistory.addItem (hitem) - #self.ui.lstHistory.setCurrentItem(hitem) + + #Adds to history + item='%s = %s' % (compatibility.get_py_str(self.ui.txtResult.text()),compatibility.get_py_str(self.ui.txtQuery.text())) + item=unicode(item.decode('utf-8')) + compatibility.add_list_item(self.ui.lstHistory,item) self.qcounter+=1 compatibility.set_utf8_text(self.ui.txtResult,u"_last%d"% self.qcounter) #Sets the result relation name to none @@ -226,33 +220,6 @@ class relForm(QtGui.QMainWindow): self.updateRelations() - def insertTuple(self): - '''Shows an input dialog and inserts the inserted tuple into the selected relation''' - res=QtGui.QInputDialog.getText(self, QtGui.QApplication.translate("Form", "New relation"),QtGui.QApplication.translate("Form", "Insert the values, comma separated"), - QtGui.QLineEdit.Normal,"") - if res[1]==False: - return - - t=[] - for i in str(res[0].toUtf8()).split(","): - t.append(i.strip()) - - if self.selectedRelation!=None and self.selectedRelation.insert(t) > 0: - self.showRelation(self.selectedRelation) - - return - def deleteTuple(self): - '''Shows an input dialog and removes the tuples corresponding to the condition.''' - res=QtGui.QInputDialog.getText(self, QtGui.QApplication.translate("Form", "New relation"),QtGui.QApplication.translate("Form", "Remove tuples: insert where condition"), - QtGui.QLineEdit.Normal,"") - if res[1]==False: - return - - if self.selectedRelation!=None and self.selectedRelation.delete(str(res[0].toUtf8())) > 0: - self.showRelation(self.selectedRelation) - - return - def addProduct(self): self.addSymbolInQuery(u"*") def addDifference(self): diff --git a/relational_gui/survey.py b/relational_gui/survey.py index 5050ec3..6f5565f 100644 --- a/relational_gui/survey.py +++ b/relational_gui/survey.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'relational_gui/survey.ui' # -# Created: Sat Oct 8 20:14:44 2011 +# Created: Sun Oct 9 00:27:00 2011 # by: PyQt4 UI code generator 4.8.3 # # WARNING! All changes made in this file will be lost! diff --git a/relational_pyside/survey.py b/relational_pyside/survey.py index 316c9cc..de94f6c 100644 --- a/relational_pyside/survey.py +++ b/relational_pyside/survey.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'relational_pyside/survey.ui' # -# Created: Sat Oct 8 20:14:44 2011 +# Created: Sun Oct 9 00:27:00 2011 # by: pyside-uic 0.2.13 running on PySide 1.0.7 # # WARNING! All changes made in this file will be lost!