From 4d7854044014ad5c007a51de3cba6f2cbeb60b2d Mon Sep 17 00:00:00 2001 From: LtWorf Date: Sun, 20 Mar 2011 21:49:02 +0000 Subject: [PATCH] - Relation list is sorted - Selects last item of history (so it scrolls) - Fixes saving relations - Simplified code, removing useless iterations git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@281 014f5005-505e-4b48-8d0a-63407b615a7c --- CHANGELOG | 2 ++ relational_gui/guihandler.py | 49 ++++++++++++++++-------------------- relational_gui/maingui.py | 9 +++++-- relational_gui/maingui.ui | 19 +++++++++++--- 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 84754b1..715bb93 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,8 @@ - Float type recognition is more robust, now handled using a regexp - Date type recognition is more robust, now using a combination of regexp plus date object - Parsing of strings representing dates is now cached, eliminating the need for double parse +- Restyle of the GUI +- Adds history in the GUI 0.11 - Font is set only on windows (Rev 206) diff --git a/relational_gui/guihandler.py b/relational_gui/guihandler.py index 83fbc54..da81064 100644 --- a/relational_gui/guihandler.py +++ b/relational_gui/guihandler.py @@ -85,7 +85,10 @@ class relForm(QtGui.QMainWindow): history_item.append(self.ui.txtResult.text()) history_item.append(u' = ') history_item.append(self.ui.txtQuery.text()) - self.ui.lstHistory.addItem (history_item) + hitem=QtGui.QListWidgetItem(None,0) + hitem.setText(history_item) + self.ui.lstHistory.addItem (hitem) + self.ui.lstHistory.setCurrentItem(hitem) self.qcounter+=1 self.ui.txtResult.setText(QtCore.QString(u"_last%d"% self.qcounter)) #Sets the result relation name to none @@ -113,18 +116,16 @@ class relForm(QtGui.QMainWindow): self.ui.table.resizeColumnToContents(i) #Must be done in order to avoid too small columns - def printRelation(self,*rel): - for i in rel: - self.selectedRelation=self.relations[str(i.text().toUtf8())] - self.showRelation(self.selectedRelation) + def printRelation(self,item): + self.selectedRelation=self.relations[str(item.text().toUtf8())] + self.showRelation(self.selectedRelation) - def showAttributes(self,*other): + def showAttributes(self,item): '''Shows the attributes of the selected relation''' - for i in other: - rel=str(i.text().toUtf8()) - self.ui.lstAttributes.clear() - for j in self.relations[rel].header.attributes: - self.ui.lstAttributes.addItem (j) + rel=str(item.text().toUtf8()) + self.ui.lstAttributes.clear() + for j in self.relations[rel].header.attributes: + self.ui.lstAttributes.addItem (j) def updateRelations(self): self.ui.lstRelations.clear() @@ -132,17 +133,16 @@ class relForm(QtGui.QMainWindow): if i != "__builtins__": self.ui.lstRelations.addItem(i) def saveRelation(self): - filename = QtGui.QFileDialog.getSaveFileName(self,QtGui.QApplication.translate("Form", "Save Relation"),"",QtGui.QApplication.translate("Form", "Relations (*.csv)")) + filename = QtGui.QFileDialog.getSaveFileName(self,QtGui.QApplication.translate("Form", "Save Relation"),"",QtGui.QApplication.translate("Form", "Relations (*.csv)")) - filename=str(filename.toUtf8()) #Converts QString to string - if (len(filename)==0):#Returns if no file was selected + filename=str(filename.toUtf8()) #Converts QString to string + if (len(filename)==0):#Returns if no file was selected + return + #if (not filename.endswith(".csv")):#Adds extension if needed + # filename+=".csv" + self.selectedRelation.save(filename) + #self.relations[str(self.ui.lstRelations.selectedItems()[0].text().toUtf8())].save(filename) return - if (not filename.endswith(".csv")):#Adds extension if needed - filename+=".csv" - - for i in self.ui.lstRelations.selectedItems(): - self.ui.relations[str(i.text().toUtf8())].save(filename) - return def unloadRelation(self): for i in self.ui.lstRelations.selectedItems(): del self.relations[str(i.text().toUtf8())] @@ -180,12 +180,7 @@ class relForm(QtGui.QMainWindow): if len(defname)==0: return - use_csv=True - - if defname.endswith(".tlb"): - defname=defname[:-4] - use_csv=False #Old format, not using csv - + if (defname.endswith(".csv")): #removes the extension defname=defname[:-4] @@ -196,7 +191,7 @@ class relForm(QtGui.QMainWindow): return #Patch provided by Angelo 'Havoc' Puglisi - self.relations[str(res[0].toUtf8())]=relation.relation(str(filename.toUtf8()),use_csv) + self.relations[str(res[0].toUtf8())]=relation.relation(str(filename.toUtf8())) else: #name was decided by caller self.relations[name]=relation.relation(filename) diff --git a/relational_gui/maingui.py b/relational_gui/maingui.py index a592f36..b1a5b6d 100644 --- a/relational_gui/maingui.py +++ b/relational_gui/maingui.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file 'relational_gui/maingui.ui' +# Form implementation generated from reading ui file 'maingui.ui' # -# Created: Sun Mar 20 21:59:01 2011 +# Created: Sun Mar 20 22:33:26 2011 # by: PyQt4 UI code generator 4.8.3 # # WARNING! All changes made in this file will be lost! @@ -96,6 +96,7 @@ class Ui_MainWindow(object): self.table = QtGui.QTreeWidget(self.splitter_2) self.table.setMinimumSize(QtCore.QSize(450, 400)) self.table.setSizeIncrement(QtCore.QSize(0, 0)) + self.table.setRootIsDecorated(False) self.table.setObjectName(_fromUtf8("table")) self.table.headerItem().setText(0, _fromUtf8("Empty relation")) self.layoutWidget1 = QtGui.QWidget(self.splitter_2) @@ -122,6 +123,9 @@ class Ui_MainWindow(object): self.lstHistory.setSizePolicy(sizePolicy) self.lstHistory.setMaximumSize(QtCore.QSize(16777215, 16777215)) self.lstHistory.setBaseSize(QtCore.QSize(0, 0)) + font = QtGui.QFont() + font.setStrikeOut(False) + self.lstHistory.setFont(font) self.lstHistory.setObjectName(_fromUtf8("lstHistory")) self.verticalLayout_6.addWidget(self.lstHistory) self.horizontalLayout_3 = QtGui.QHBoxLayout() @@ -301,6 +305,7 @@ class Ui_MainWindow(object): self.cmdUndoOptimize.setText(QtGui.QApplication.translate("MainWindow", "Undo optimize", None, QtGui.QApplication.UnicodeUTF8)) self.cmdClearHistory.setText(QtGui.QApplication.translate("MainWindow", "Clear history", None, QtGui.QApplication.UnicodeUTF8)) self.groupBox.setTitle(QtGui.QApplication.translate("MainWindow", "Relations", None, QtGui.QApplication.UnicodeUTF8)) + self.lstRelations.setSortingEnabled(True) self.cmdLoad.setText(QtGui.QApplication.translate("MainWindow", "Load relation", None, QtGui.QApplication.UnicodeUTF8)) self.cmdSave.setText(QtGui.QApplication.translate("MainWindow", "Save relation", None, QtGui.QApplication.UnicodeUTF8)) self.cmdUnload.setText(QtGui.QApplication.translate("MainWindow", "Unload relation", None, QtGui.QApplication.UnicodeUTF8)) diff --git a/relational_gui/maingui.ui b/relational_gui/maingui.ui index 209a1ef..6e3420e 100644 --- a/relational_gui/maingui.ui +++ b/relational_gui/maingui.ui @@ -182,6 +182,9 @@ 0 + + false + Empty relation @@ -234,6 +237,11 @@ 0 + + + false + + @@ -299,6 +307,9 @@ 16777215 + + true + @@ -892,7 +903,7 @@ lstRelations itemDoubleClicked(QListWidgetItem*) MainWindow - printRelation() + printRelation(QListWidgetItem*) 708 @@ -908,7 +919,7 @@ lstRelations itemClicked(QListWidgetItem*) MainWindow - showAttributes() + showAttributes(QListWidgetItem*) 615 @@ -977,8 +988,8 @@ saveRelation() insertTuple() deleteTuple() - printRelation() - showAttributes() + printRelation(QListWidgetItem*) + showAttributes(QListWidgetItem*) loadQuery() resumeHistory(QListWidgetItem*)