- simplified linegui checking if query is an assignment
- Reports missing GUI modules - Will not load relations if given name is not valid - Will not execute if relation dest name is not valid git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@283 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
parent
e563972436
commit
8065f65d2d
@ -17,6 +17,7 @@
|
|||||||
- Parsing of strings representing dates is now cached, eliminating the need for double parse
|
- Parsing of strings representing dates is now cached, eliminating the need for double parse
|
||||||
- Restyle of the GUI
|
- Restyle of the GUI
|
||||||
- Adds history in the GUI
|
- Adds history in the GUI
|
||||||
|
- Checks if given name to relations are valid
|
||||||
|
|
||||||
0.11
|
0.11
|
||||||
- Font is set only on windows (Rev 206)
|
- Font is set only on windows (Rev 206)
|
||||||
|
@ -109,3 +109,11 @@ class rdate (object):
|
|||||||
def __sub__ (self,other):
|
def __sub__ (self,other):
|
||||||
return (self.intdate-other.intdate).days
|
return (self.intdate-other.intdate).days
|
||||||
|
|
||||||
|
|
||||||
|
def is_valid_relation_name(name):
|
||||||
|
'''Checks if a name is valid for a relation.
|
||||||
|
Returns boolean'''
|
||||||
|
if re.match(r'^[_a-zA-Z]+[_a-zA-Z0-9]*$',name)==None:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
@ -83,7 +83,13 @@ if __name__ == "__main__":
|
|||||||
if x11:
|
if x11:
|
||||||
import sip
|
import sip
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from relational_gui import maingui,guihandler, about, surveyForm
|
|
||||||
|
try:
|
||||||
|
from relational_gui import maingui,guihandler, about, surveyForm
|
||||||
|
except:
|
||||||
|
print >> sys.stderr, "Module relational_gui is missing.\nPlease install relational package."
|
||||||
|
sys.exit(3)
|
||||||
|
|
||||||
about.version=version
|
about.version=version
|
||||||
surveyForm.version=version
|
surveyForm.version=version
|
||||||
|
|
||||||
@ -113,6 +119,10 @@ if __name__ == "__main__":
|
|||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
else:
|
else:
|
||||||
printver(False)
|
printver(False)
|
||||||
import relational_readline.linegui
|
try:
|
||||||
|
import relational_readline.linegui
|
||||||
|
except:
|
||||||
|
print >> sys.stderr, "Module relational_readline is missing.\nPlease install relational-cli package."
|
||||||
|
sys.exit(3)
|
||||||
relational_readline.linegui.main(files)
|
relational_readline.linegui.main(files)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#
|
#
|
||||||
# author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
|
# author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from relational import relation, parser, optimizer
|
from relational import relation, parser, optimizer,rtypes
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import about
|
import about
|
||||||
@ -53,7 +53,6 @@ class relForm(QtGui.QMainWindow):
|
|||||||
result=optimizer.optimize_all(str(self.ui.txtQuery.text().toUtf8()),self.relations)
|
result=optimizer.optimize_all(str(self.ui.txtQuery.text().toUtf8()),self.relations)
|
||||||
self.ui.txtQuery.setText(QtCore.QString.fromUtf8(result))
|
self.ui.txtQuery.setText(QtCore.QString.fromUtf8(result))
|
||||||
|
|
||||||
#self.txtQuery.setText(result)
|
|
||||||
def resumeHistory(self,item):
|
def resumeHistory(self,item):
|
||||||
itm=str(item.text().toUtf8()).split(' = ',1)
|
itm=str(item.text().toUtf8()).split(' = ',1)
|
||||||
self.ui.txtResult.setText(QtCore.QString.fromUtf8(itm[0]))
|
self.ui.txtResult.setText(QtCore.QString.fromUtf8(itm[0]))
|
||||||
@ -65,10 +64,11 @@ class relForm(QtGui.QMainWindow):
|
|||||||
|
|
||||||
query=str(self.ui.txtQuery.text().toUtf8())
|
query=str(self.ui.txtQuery.text().toUtf8())
|
||||||
res_rel=str(self.ui.txtResult.text())#result relation's name
|
res_rel=str(self.ui.txtResult.text())#result relation's name
|
||||||
if len(res_rel)==0: #If no name is set use the default last_
|
|
||||||
QtGui.QMessageBox.information(self,QtGui.QApplication.translate("Form", "Error"),QtGui.QApplication.translate("Form", "Missing destination relation."))
|
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
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
#Converting string to utf8 and then from qstring to normal string
|
#Converting string to utf8 and then from qstring to normal string
|
||||||
expr=parser.parse(query)#Converting expression to python code
|
expr=parser.parse(query)#Converting expression to python code
|
||||||
@ -172,11 +172,10 @@ class relForm(QtGui.QMainWindow):
|
|||||||
|
|
||||||
#Default relation's name
|
#Default relation's name
|
||||||
f=str(filename.toUtf8()).split('/') #Split the full path
|
f=str(filename.toUtf8()).split('/') #Split the full path
|
||||||
defname=f[len(f)-1].lower() #Takes only the lowercase filename
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
f=filename.split('/') #Split the full path
|
f=filename.split('/') #Split the full path
|
||||||
defname=f[len(f)-1].lower() #Takes only the lowercase filename
|
|
||||||
|
defname=f[len(f)-1].lower() #Takes only the lowercase filename
|
||||||
|
|
||||||
if len(defname)==0:
|
if len(defname)==0:
|
||||||
return
|
return
|
||||||
@ -191,11 +190,14 @@ class relForm(QtGui.QMainWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
#Patch provided by Angelo 'Havoc' Puglisi
|
#Patch provided by Angelo 'Havoc' Puglisi
|
||||||
self.relations[str(res[0].toUtf8())]=relation.relation(str(filename.toUtf8()))
|
name=str(res[0].toUtf8())
|
||||||
else: #name was decided by caller
|
filename=str(filename.toUtf8())
|
||||||
|
|
||||||
|
if rtypes.is_valid_relation_name(name):
|
||||||
self.relations[name]=relation.relation(filename)
|
self.relations[name]=relation.relation(filename)
|
||||||
|
self.updateRelations()
|
||||||
self.updateRelations()
|
else:
|
||||||
|
QtGui.QMessageBox.information(self,QtGui.QApplication.translate("Form", "Error"),QtGui.QApplication.translate("Form", "Wrong name for destination relation: %s." % name))
|
||||||
def insertTuple(self):
|
def insertTuple(self):
|
||||||
'''Shows an input dialog and inserts the inserted tuple into the selected relation'''
|
'''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"),
|
res=QtGui.QInputDialog.getText(self, QtGui.QApplication.translate("Form", "New relation"),QtGui.QApplication.translate("Form", "Insert the values, comma separated"),
|
||||||
@ -253,16 +255,4 @@ class relForm(QtGui.QMainWindow):
|
|||||||
def addSymbolInQuery(self,symbol):
|
def addSymbolInQuery(self,symbol):
|
||||||
self.ui.txtQuery.insert(symbol)
|
self.ui.txtQuery.insert(symbol)
|
||||||
self.ui.txtQuery.setFocus()
|
self.ui.txtQuery.setFocus()
|
||||||
|
|
||||||
def q_main():
|
|
||||||
import sys
|
|
||||||
app = QtGui.QApplication(sys.argv)
|
|
||||||
Form = RelForm()
|
|
||||||
ui = maingui.Ui_MainWindow()
|
|
||||||
ui.setupUi(Form)
|
|
||||||
Form.setupUi(ui)
|
|
||||||
Form.show()
|
|
||||||
sys.exit(app.exec_())
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
q_main()
|
|
@ -25,7 +25,7 @@ import os.path
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from relational import relation, parser, optimizer
|
from relational import relation, parser, rtypes
|
||||||
|
|
||||||
class SimpleCompleter(object):
|
class SimpleCompleter(object):
|
||||||
'''Handles completion'''
|
'''Handles completion'''
|
||||||
@ -103,7 +103,10 @@ def load_relation(filename,defname=None):
|
|||||||
defname=f[len(f)-1].lower()
|
defname=f[len(f)-1].lower()
|
||||||
if defname.endswith(".csv"): #removes the extension
|
if defname.endswith(".csv"): #removes the extension
|
||||||
defname=defname[:-4]
|
defname=defname[:-4]
|
||||||
|
|
||||||
|
if not rtypes.is_valid_relation_name(defname):
|
||||||
|
print >> sys.stderr, "%s is not a valid relation name" % defname
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
relations[defname]=relation.relation(filename)
|
relations[defname]=relation.relation(filename)
|
||||||
|
|
||||||
@ -234,18 +237,9 @@ def exec_query(command):
|
|||||||
#Finds the name in where to save the query
|
#Finds the name in where to save the query
|
||||||
parts=command.split('=',1)
|
parts=command.split('=',1)
|
||||||
|
|
||||||
if len(parts)>1:
|
if len(parts)>1 and rtypes.is_valid_relation_name(parts[0]):
|
||||||
assignment=True
|
relname=parts[0]
|
||||||
for i in parser.op_functions:
|
query=parts[1]
|
||||||
if i in parts[0]:
|
|
||||||
#If we are here, there is no explicit assignment
|
|
||||||
assignment=False
|
|
||||||
if assignment:
|
|
||||||
relname=parts[0]
|
|
||||||
query=parts[1]
|
|
||||||
else:
|
|
||||||
relname='last_'
|
|
||||||
query=command
|
|
||||||
else:
|
else:
|
||||||
relname='last_'
|
relname='last_'
|
||||||
query=command
|
query=command
|
||||||
|
Loading…
x
Reference in New Issue
Block a user