/usr/share/pyshared/relational_gui/guihandler.py is in relational 1.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | # -*- coding: utf-8 -*-
# Relational
# Copyright (C) 2008 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>
import sys
import os
import pickle
try:
from PyQt4 import QtCore, QtGui
except:
from PySide import QtCore, QtGui
from relational import relation, parser, optimizer, rtypes
import about
import survey
import surveyForm
import maingui
import compatibility
class relForm(QtGui.QMainWindow):
def __init__(self, ui):
QtGui.QMainWindow.__init__(self)
self.About = None
self.Survey = None
self.relations = {} # Dictionary for relations
self.undo = None # UndoQueue for queries
self.selectedRelation = None
self.ui = ui
self.qcounter = 1 # Query counter
self.settings = QtCore.QSettings()
def checkVersion(self):
from relational import maintenance
online = maintenance.check_latest_version()
if online > version:
r = QtGui.QApplication.translate(
"Form", "New version available online: %s." % online)
elif online == version:
r = QtGui.QApplication.translate(
"Form", "Latest version installed.")
else:
r = QtGui.QApplication.translate(
"Form", "You are using an unstable version.")
QtGui.QMessageBox.information(
self, QtGui.QApplication.translate("Form", "Version"), r)
def load_query(self, *index):
self.ui.txtQuery.setText(self.savedQ.itemData(index[0]).toString())
def undoOptimize(self):
'''Undoes the optimization on the query, popping one item from the undo list'''
if self.undo != None:
self.ui.txtQuery.setText(self.undo)
def optimize(self):
'''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())
try:
result = optimizer.optimize_all(query, self.relations)
compatibility.set_utf8_text(self.ui.txtQuery, result)
except Exception, e:
QtGui.QMessageBox.information(None, QtGui.QApplication.translate("Form", "Error"), "%s\n%s" %
(QtGui.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])
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
print query, "-->", expr # Printing debug
result = eval(expr, self.relations) # Evaluating the expression
self.relations[
res_rel] = result # Add the relation to the dictionary
self.updateRelations() # update the list
self.selectedRelation = result
self.showRelation(self.selectedRelation)
# Show the result in the table
except Exception, e:
print e.__unicode__()
QtGui.QMessageBox.information(None, QtGui.QApplication.translate("Form", "Error"), u"%s\n%s" %
(QtGui.QApplication.translate("Form", "Check your query!"), e.__unicode__()))
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)
self.qcounter += 1
compatibility.set_utf8_text(self.ui.txtResult, u"_last%d" %
self.qcounter) # Sets the result relation name to none
def showRelation(self, rel):
'''Shows the selected relation into the table'''
self.ui.table.clear()
if rel == None: # No relation to show
self.ui.table.setColumnCount(1)
self.ui.table.headerItem().setText(0, "Empty relation")
return
self.ui.table.setColumnCount(len(rel.header.attributes))
# Set content
for i in rel.content:
item = QtGui.QTreeWidgetItem()
for j in range(len(i)):
item.setText(j, i[j])
self.ui.table.addTopLevelItem(item)
# Sets columns
for i in range(len(rel.header.attributes)):
self.ui.table.headerItem().setText(i, rel.header.attributes[i])
self.ui.table.resizeColumnToContents(
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.showRelation(self.selectedRelation)
def showAttributes(self, item):
'''Shows the attributes of the selected relation'''
rel = compatibility.get_py_str(item.text())
self.ui.lstAttributes.clear()
for j in self.relations[rel].header.attributes:
self.ui.lstAttributes.addItem(j)
def updateRelations(self):
self.ui.lstRelations.clear()
for i in self.relations:
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 = compatibility.get_filename(filename)
if (len(filename) == 0): # Returns if no file was selected
return
self.selectedRelation.save(filename)
return
def unloadRelation(self):
for i in self.ui.lstRelations.selectedItems():
del self.relations[compatibility.get_py_str(i.text())]
self.updateRelations()
def editRelation(self):
import creator
for i in self.ui.lstRelations.selectedItems():
result = creator.edit_relation(
self.relations[compatibility.get_py_str(i.text())])
if result != None:
self.relations[compatibility.get_py_str(i.text())] = result
self.updateRelations()
def newRelation(self):
import creator
result = creator.edit_relation()
if result == None:
return
res = QtGui.QInputDialog.getText(
self,
QtGui.QApplication.translate("Form", "New relation"),
QtGui.QApplication.translate(
"Form", "Insert the name for the new relation"),
QtGui.QLineEdit.Normal, '')
if res[1] == False or len(res[0]) == 0:
return
# Patch provided by Angelo 'Havoc' Puglisi
name = compatibility.get_py_str(res[0])
if not rtypes.is_valid_relation_name(name):
r = QtGui.QApplication.translate(
"Form", str("Wrong name for destination relation: %s." % name))
QtGui.QMessageBox.information(
self, QtGui.QApplication.translate("Form", "Error"), r)
return
try:
self.relations[name] = result
except Exception, e:
print e
QtGui.QMessageBox.information(None, QtGui.QApplication.translate("Form", "Error"), "%s\n%s" %
(QtGui.QApplication.translate("Form", "Check your query!"), e.__str__()))
return
self.updateRelations()
def closeEvent(self, event):
self.save_settings()
event.accept()
def save_settings(self):
# self.settings.setValue("width",)
pass
def restore_settings(self):
# self.settings.value('session_name','default').toString()
pass
def showSurvey(self):
if self.Survey == None:
self.Survey = surveyForm.surveyForm()
ui = survey.Ui_Form()
self.Survey.setUi(ui)
ui.setupUi(self.Survey)
self.Survey.setDefaultValues()
self.Survey.show()
def showAbout(self):
if self.About == None:
self.About = QtGui.QDialog()
ui = about.Ui_Dialog()
ui.setupUi(self.About)
self.About.show()
def loadRelation(self, filename=None, name=None):
'''Loads a relation. Without parameters it will ask the user which relation to load,
otherwise it will load filename, giving it name.
It shouldn't be called giving filename but not giving name.'''
# Asking for file to load
if filename == None:
filename = QtGui.QFileDialog.getOpenFileName(self, QtGui.QApplication.translate(
"Form", "Load Relation"), "", QtGui.QApplication.translate("Form", "Relations (*.csv);;Text Files (*.txt);;All Files (*)"))
filename = compatibility.get_filename(filename)
# Default relation's name
f = filename.split('/') # Split the full path
defname = f[len(f) - 1].lower() # Takes only the lowercase filename
if len(defname) == 0:
return
if (defname.endswith(".csv")): # removes the extension
defname = defname[:-4]
if name == None: # Prompt dialog to insert name for the relation
res = QtGui.QInputDialog.getText(
self, QtGui.QApplication.translate("Form", "New relation"), QtGui.QApplication.translate(
"Form", "Insert the name for the new relation"),
QtGui.QLineEdit.Normal, defname)
if res[1] == False or len(res[0]) == 0:
return
# Patch provided by Angelo 'Havoc' Puglisi
name = compatibility.get_py_str(res[0])
if not rtypes.is_valid_relation_name(name):
r = QtGui.QApplication.translate(
"Form", str("Wrong name for destination relation: %s." % name))
QtGui.QMessageBox.information(
self, QtGui.QApplication.translate("Form", "Error"), r)
return
try:
self.relations[name] = relation.relation(filename)
except Exception, e:
print e
QtGui.QMessageBox.information(None, QtGui.QApplication.translate("Form", "Error"), "%s\n%s" %
(QtGui.QApplication.translate("Form", "Check your query!"), e.__str__()))
return
self.updateRelations()
def addProduct(self):
self.addSymbolInQuery(u"*")
def addDifference(self):
self.addSymbolInQuery(u"-")
def addUnion(self):
self.addSymbolInQuery(u"ᑌ")
def addIntersection(self):
self.addSymbolInQuery(u"ᑎ")
def addDivision(self):
self.addSymbolInQuery(u"÷")
def addOLeft(self):
self.addSymbolInQuery(u"ᐅLEFTᐊ")
def addJoin(self):
self.addSymbolInQuery(u"ᐅᐊ")
def addORight(self):
self.addSymbolInQuery(u"ᐅRIGHTᐊ")
def addOuter(self):
self.addSymbolInQuery(u"ᐅFULLᐊ")
def addProjection(self):
self.addSymbolInQuery(u"π")
def addSelection(self):
self.addSymbolInQuery(u"σ")
def addRename(self):
self.addSymbolInQuery(u"ρ")
def addArrow(self):
self.addSymbolInQuery(u"➡")
def addSymbolInQuery(self, symbol):
self.ui.txtQuery.insert(symbol)
self.ui.txtQuery.setFocus()
|