diff --git a/relational_gui/compatibility.py b/relational_gui/compatibility.py deleted file mode 100644 index 9cce55e..0000000 --- a/relational_gui/compatibility.py +++ /dev/null @@ -1,43 +0,0 @@ -# -*- coding: utf-8 -*- -# Relational -# Copyright (C) 2011 Salvo "LtWorf" Tomaselli -# -# Relational is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# author Salvo "LtWorf" Tomaselli -# -# Module to unify the use of both pyqt and pyside - -from PyQt5 import QtCore, QtWidgets - - -def get_py_str(a): - '''Returns a python string out of a QString''' - return a - - -def set_utf8_text(component, text): - component.setText(text) - - -def get_filename(filename): - print (filename) - return str(filename.toUtf8()) - - -def add_list_item(l, item): - hitem = QtWidgets.QListWidgetItem(None, 0) - hitem.setText(item) - l.addItem(hitem) - l.setCurrentItem(hitem) diff --git a/relational_gui/creator.py b/relational_gui/creator.py index abf2cf4..ce389ac 100644 --- a/relational_gui/creator.py +++ b/relational_gui/creator.py @@ -19,7 +19,6 @@ from PyQt5 import QtCore, QtGui, QtWidgets -from relational_gui import compatibility from relational_gui import rel_edit from relational import relation @@ -85,8 +84,7 @@ class creatorForm(QtWidgets.QDialog): hlist = [] for i in range(self.table.columnCount()): - hlist.append( - compatibility.get_py_str(self.table.item(0, i).text())) + hlist.append(self.table.item(0, i).text()) try: header = relation.header(hlist) except Exception as e: @@ -100,8 +98,7 @@ class creatorForm(QtWidgets.QDialog): hlist = [] for j in range(self.table.columnCount()): try: - hlist.append( - compatibility.get_py_str(self.table.item(i, j).text())) + hlist.append(self.table.item(i, j).text()) except: QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate( "Form", "Error"), QtWidgets.QApplication.translate("Form", "Unset value in %d,%d!" % (i + 1, j + 1))) diff --git a/relational_gui/guihandler.py b/relational_gui/guihandler.py index 5d0b26a..fe4f745 100644 --- a/relational_gui/guihandler.py +++ b/relational_gui/guihandler.py @@ -28,7 +28,6 @@ from relational_gui import about from relational_gui import survey from relational_gui import surveyForm from relational_gui import maingui -from relational_gui import compatibility class relForm(QtWidgets.QMainWindow): @@ -82,21 +81,21 @@ class relForm(QtWidgets.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()) + query = self.ui.txtQuery.text() try: result = optimizer.optimize_all(query, self.relations) - compatibility.set_utf8_text(self.ui.txtQuery, result) + self.ui.txtQuery.setText(result) except Exception as e: QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate("Form", "Error"), "%s\n%s" % (QtWidgets.QApplication.translate("Form", "Check your query!"), e.__str__())) 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]) + itm = item.text().split(' = ', 1) + self.ui.txtResult.setText(itm[0]) + self.ui.txtQuery.setText(itm[1]) def _run_multiline(self): - query = compatibility.get_py_str(self.ui.txtMultiQuery.toPlainText()) + query = self.ui.txtMultiQuery.toPlainText() self.settings.setValue('multiline/query', query) queries = query.split('\n') @@ -133,9 +132,8 @@ class relForm(QtWidgets.QMainWindow): return self._run_multiline() #Single line query - query = compatibility.get_py_str(self.ui.txtQuery.text()) - res_rel = compatibility.get_py_str( - self.ui.txtResult.text()) # result relation's name + query = self.ui.txtQuery.text() + res_rel = self.ui.txtResult.text() # result relation's name if not rtypes.is_valid_relation_name(res_rel): QtWidgets.QMessageBox.information(self, QtWidgets.QApplication.translate( @@ -161,14 +159,17 @@ class relForm(QtWidgets.QMainWindow): return # Adds to history - item = u'%s = %s' % (compatibility.get_py_str( - self.ui.txtResult.text()), compatibility.get_py_str(self.ui.txtQuery.text())) - # item=item.decode('utf-8')) - compatibility.add_list_item(self.ui.lstHistory, item) + item = u'%s = %s' % ( + self.ui.txtResult.text(), + self.ui.txtQuery.text() + ) + hitem = QtWidgets.QListWidgetItem(None, 0) + hitem.setText(item) + self.ui.lstHistory.addItem(hitem) + self.ui.lstHistory.setCurrentItem(hitem) self.qcounter += 1 - compatibility.set_utf8_text(self.ui.txtResult, u"_last%d" % - self.qcounter) # Sets the result relation name to none + self.ui.txtResult.setText(u"_last%d" % self.qcounter) # Sets the result relation name to none def showRelation(self, rel): '''Shows the selected relation into the table''' @@ -194,13 +195,12 @@ class relForm(QtWidgets.QMainWindow): i) # Must be done in order to avoid too small columns def printRelation(self, item): - self.selectedRelation = self.relations[ - compatibility.get_py_str(item.text())] + self.selectedRelation = self.relations[item.text()] self.showRelation(self.selectedRelation) def showAttributes(self, item): '''Shows the attributes of the selected relation''' - rel = compatibility.get_py_str(item.text()) + rel = item.text() self.ui.lstAttributes.clear() for j in self.relations[rel].header.attributes: self.ui.lstAttributes.addItem(j) @@ -228,16 +228,16 @@ class relForm(QtWidgets.QMainWindow): def unloadRelation(self): for i in self.ui.lstRelations.selectedItems(): - del self.relations[compatibility.get_py_str(i.text())] + del self.relations[i.text()] self.updateRelations() def editRelation(self): from relational_gui import creator for i in self.ui.lstRelations.selectedItems(): result = creator.edit_relation( - self.relations[compatibility.get_py_str(i.text())]) + self.relations[i.text()]) if result != None: - self.relations[compatibility.get_py_str(i.text())] = result + self.relations[i.text()] = result self.updateRelations() def newRelation(self): @@ -256,7 +256,7 @@ class relForm(QtWidgets.QMainWindow): ) if res[1] == False:# or len(res[0]) == 0: return - name = compatibility.get_py_str(res[0]) + name = res[0] if not rtypes.is_valid_relation_name(name): r = QtWidgets.QApplication.translate( diff --git a/relational_gui/surveyForm.py b/relational_gui/surveyForm.py index 6a4812b..4fc7e46 100644 --- a/relational_gui/surveyForm.py +++ b/relational_gui/surveyForm.py @@ -22,7 +22,6 @@ import locale from PyQt5 import QtCore, QtGui, QtWidgets -from relational_gui import compatibility from relational import maintenance @@ -66,14 +65,13 @@ class surveyForm (QtWidgets.QWidget): post = {} post['software'] = "Relational algebra" post["version"] = version - post["system"] = compatibility.get_py_str(self.ui.txtSystem.text()) - post["country"] = compatibility.get_py_str(self.ui.txtCountry.text()) - post["school"] = compatibility.get_py_str(self.ui.txtSchool.text()) - post["age"] = compatibility.get_py_str(self.ui.txtAge.text()) - post["find"] = compatibility.get_py_str(self.ui.txtFind.text()) - post["email"] = compatibility.get_py_str(self.ui.txtEmail.text()) - post["comments"] = compatibility.get_py_str( - self.ui.txtComments.toPlainText()) + post["system"] = self.ui.txtSystem.text() + post["country"] = self.ui.txtCountry.text() + post["school"] = self.ui.txtSchool.text() + post["age"] = self.ui.txtAge.text() + post["find"] = self.ui.txtFind.text() + post["email"] = self.ui.txtEmail.text() + post["comments"] = self.ui.txtComments.toPlainText() # Clears the form self.ui.txtSystem.clear()