Removed useless compatibility module from UI

It was originally created to support both PyQt and PySide but
at this point is useless
This commit is contained in:
Salvo 'LtWorf' Tomaselli 2015-06-02 14:56:44 +02:00
parent 36a2c192a8
commit 62c51ab150
4 changed files with 32 additions and 80 deletions

View File

@ -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 <http://www.gnu.org/licenses/>.
#
# author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
#
# 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)

View File

@ -19,7 +19,6 @@
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
from relational_gui import compatibility
from relational_gui import rel_edit from relational_gui import rel_edit
from relational import relation from relational import relation
@ -85,8 +84,7 @@ class creatorForm(QtWidgets.QDialog):
hlist = [] hlist = []
for i in range(self.table.columnCount()): for i in range(self.table.columnCount()):
hlist.append( hlist.append(self.table.item(0, i).text())
compatibility.get_py_str(self.table.item(0, i).text()))
try: try:
header = relation.header(hlist) header = relation.header(hlist)
except Exception as e: except Exception as e:
@ -100,8 +98,7 @@ class creatorForm(QtWidgets.QDialog):
hlist = [] hlist = []
for j in range(self.table.columnCount()): for j in range(self.table.columnCount()):
try: try:
hlist.append( hlist.append(self.table.item(i, j).text())
compatibility.get_py_str(self.table.item(i, j).text()))
except: except:
QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate( QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate(
"Form", "Error"), QtWidgets.QApplication.translate("Form", "Unset value in %d,%d!" % (i + 1, j + 1))) "Form", "Error"), QtWidgets.QApplication.translate("Form", "Unset value in %d,%d!" % (i + 1, j + 1)))

View File

@ -28,7 +28,6 @@ from relational_gui import about
from relational_gui import survey from relational_gui import survey
from relational_gui import surveyForm from relational_gui import surveyForm
from relational_gui import maingui from relational_gui import maingui
from relational_gui import compatibility
class relForm(QtWidgets.QMainWindow): class relForm(QtWidgets.QMainWindow):
@ -82,21 +81,21 @@ class relForm(QtWidgets.QMainWindow):
'''Performs all the possible optimizations on the query''' '''Performs all the possible optimizations on the query'''
self.undo = self.ui.txtQuery.text() # Storing the query in undo list 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: try:
result = optimizer.optimize_all(query, self.relations) result = optimizer.optimize_all(query, self.relations)
compatibility.set_utf8_text(self.ui.txtQuery, result) self.ui.txtQuery.setText(result)
except Exception as e: except Exception as e:
QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate("Form", "Error"), "%s\n%s" % QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate("Form", "Error"), "%s\n%s" %
(QtWidgets.QApplication.translate("Form", "Check your query!"), e.__str__())) (QtWidgets.QApplication.translate("Form", "Check your query!"), e.__str__()))
def resumeHistory(self, item): def resumeHistory(self, item):
itm = compatibility.get_py_str(item.text()).split(' = ', 1) itm = item.text().split(' = ', 1)
compatibility.set_utf8_text(self.ui.txtResult, itm[0]) self.ui.txtResult.setText(itm[0])
compatibility.set_utf8_text(self.ui.txtQuery, itm[1]) self.ui.txtQuery.setText(itm[1])
def _run_multiline(self): def _run_multiline(self):
query = compatibility.get_py_str(self.ui.txtMultiQuery.toPlainText()) query = self.ui.txtMultiQuery.toPlainText()
self.settings.setValue('multiline/query', query) self.settings.setValue('multiline/query', query)
queries = query.split('\n') queries = query.split('\n')
@ -133,9 +132,8 @@ class relForm(QtWidgets.QMainWindow):
return self._run_multiline() return self._run_multiline()
#Single line query #Single line query
query = compatibility.get_py_str(self.ui.txtQuery.text()) query = self.ui.txtQuery.text()
res_rel = compatibility.get_py_str( res_rel = self.ui.txtResult.text() # result relation's name
self.ui.txtResult.text()) # result relation's name
if not rtypes.is_valid_relation_name(res_rel): if not rtypes.is_valid_relation_name(res_rel):
QtWidgets.QMessageBox.information(self, QtWidgets.QApplication.translate( QtWidgets.QMessageBox.information(self, QtWidgets.QApplication.translate(
@ -161,14 +159,17 @@ class relForm(QtWidgets.QMainWindow):
return return
# Adds to history # Adds to history
item = u'%s = %s' % (compatibility.get_py_str( item = u'%s = %s' % (
self.ui.txtResult.text()), compatibility.get_py_str(self.ui.txtQuery.text())) self.ui.txtResult.text(),
# item=item.decode('utf-8')) self.ui.txtQuery.text()
compatibility.add_list_item(self.ui.lstHistory, item) )
hitem = QtWidgets.QListWidgetItem(None, 0)
hitem.setText(item)
self.ui.lstHistory.addItem(hitem)
self.ui.lstHistory.setCurrentItem(hitem)
self.qcounter += 1 self.qcounter += 1
compatibility.set_utf8_text(self.ui.txtResult, u"_last%d" % self.ui.txtResult.setText(u"_last%d" % self.qcounter) # Sets the result relation name to none
self.qcounter) # Sets the result relation name to none
def showRelation(self, rel): def showRelation(self, rel):
'''Shows the selected relation into the table''' '''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 i) # Must be done in order to avoid too small columns
def printRelation(self, item): def printRelation(self, item):
self.selectedRelation = self.relations[ self.selectedRelation = self.relations[item.text()]
compatibility.get_py_str(item.text())]
self.showRelation(self.selectedRelation) self.showRelation(self.selectedRelation)
def showAttributes(self, item): def showAttributes(self, item):
'''Shows the attributes of the selected relation''' '''Shows the attributes of the selected relation'''
rel = compatibility.get_py_str(item.text()) rel = item.text()
self.ui.lstAttributes.clear() self.ui.lstAttributes.clear()
for j in self.relations[rel].header.attributes: for j in self.relations[rel].header.attributes:
self.ui.lstAttributes.addItem(j) self.ui.lstAttributes.addItem(j)
@ -228,16 +228,16 @@ class relForm(QtWidgets.QMainWindow):
def unloadRelation(self): def unloadRelation(self):
for i in self.ui.lstRelations.selectedItems(): for i in self.ui.lstRelations.selectedItems():
del self.relations[compatibility.get_py_str(i.text())] del self.relations[i.text()]
self.updateRelations() self.updateRelations()
def editRelation(self): def editRelation(self):
from relational_gui import creator from relational_gui import creator
for i in self.ui.lstRelations.selectedItems(): for i in self.ui.lstRelations.selectedItems():
result = creator.edit_relation( result = creator.edit_relation(
self.relations[compatibility.get_py_str(i.text())]) self.relations[i.text()])
if result != None: if result != None:
self.relations[compatibility.get_py_str(i.text())] = result self.relations[i.text()] = result
self.updateRelations() self.updateRelations()
def newRelation(self): def newRelation(self):
@ -256,7 +256,7 @@ class relForm(QtWidgets.QMainWindow):
) )
if res[1] == False:# or len(res[0]) == 0: if res[1] == False:# or len(res[0]) == 0:
return return
name = compatibility.get_py_str(res[0]) name = res[0]
if not rtypes.is_valid_relation_name(name): if not rtypes.is_valid_relation_name(name):
r = QtWidgets.QApplication.translate( r = QtWidgets.QApplication.translate(

View File

@ -22,7 +22,6 @@ import locale
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
from relational_gui import compatibility
from relational import maintenance from relational import maintenance
@ -66,14 +65,13 @@ class surveyForm (QtWidgets.QWidget):
post = {} post = {}
post['software'] = "Relational algebra" post['software'] = "Relational algebra"
post["version"] = version post["version"] = version
post["system"] = compatibility.get_py_str(self.ui.txtSystem.text()) post["system"] = self.ui.txtSystem.text()
post["country"] = compatibility.get_py_str(self.ui.txtCountry.text()) post["country"] = self.ui.txtCountry.text()
post["school"] = compatibility.get_py_str(self.ui.txtSchool.text()) post["school"] = self.ui.txtSchool.text()
post["age"] = compatibility.get_py_str(self.ui.txtAge.text()) post["age"] = self.ui.txtAge.text()
post["find"] = compatibility.get_py_str(self.ui.txtFind.text()) post["find"] = self.ui.txtFind.text()
post["email"] = compatibility.get_py_str(self.ui.txtEmail.text()) post["email"] = self.ui.txtEmail.text()
post["comments"] = compatibility.get_py_str( post["comments"] = self.ui.txtComments.toPlainText()
self.ui.txtComments.toPlainText())
# Clears the form # Clears the form
self.ui.txtSystem.clear() self.ui.txtSystem.clear()