2011-03-20 14:31:50 +07:00
|
|
|
# Relational
|
|
|
|
# Copyright (C) 2008 Salvo "LtWorf" Tomaselli
|
2013-12-26 17:16:12 +07:00
|
|
|
#
|
2011-03-20 14:31:50 +07:00
|
|
|
# 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.
|
2013-12-26 17:16:12 +07:00
|
|
|
#
|
2011-03-20 14:31:50 +07:00
|
|
|
# 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.
|
2013-12-26 17:16:12 +07:00
|
|
|
#
|
2011-03-20 14:31:50 +07:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-12-26 17:16:12 +07:00
|
|
|
#
|
2011-03-20 14:31:50 +07:00
|
|
|
# author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
|
2015-09-29 05:47:20 +07:00
|
|
|
import sys
|
|
|
|
|
2015-11-11 10:01:52 +07:00
|
|
|
from PyQt5 import QtCore, QtWidgets, QtGui
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2015-11-11 10:01:52 +07:00
|
|
|
from relational import parser, optimizer, rtypes
|
2015-07-14 08:39:35 +07:00
|
|
|
from relational.maintenance import UserInterface
|
2011-03-20 14:31:50 +07:00
|
|
|
|
2015-02-19 07:00:47 +07:00
|
|
|
from relational_gui import about
|
|
|
|
from relational_gui import survey
|
|
|
|
from relational_gui import surveyForm
|
|
|
|
from relational_gui import maingui
|
2011-03-20 14:31:50 +07:00
|
|
|
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2015-02-19 07:00:47 +07:00
|
|
|
class relForm(QtWidgets.QMainWindow):
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2015-09-29 05:47:20 +07:00
|
|
|
def __init__(self):
|
2015-02-19 07:00:47 +07:00
|
|
|
QtWidgets.QMainWindow.__init__(self)
|
2013-12-26 17:31:43 +07:00
|
|
|
self.About = None
|
|
|
|
self.Survey = None
|
|
|
|
self.undo = None # UndoQueue for queries
|
|
|
|
self.selectedRelation = None
|
2015-09-29 05:47:20 +07:00
|
|
|
self.ui = maingui.Ui_MainWindow()
|
2015-07-14 08:39:35 +07:00
|
|
|
self.user_interface = UserInterface()
|
2016-01-02 05:36:28 +07:00
|
|
|
self.history_current_line = None
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2015-09-29 05:47:20 +07:00
|
|
|
# Creates the UI
|
|
|
|
self.ui.setupUi(self)
|
|
|
|
|
|
|
|
#Setting fonts for symbols
|
|
|
|
f = QtGui.QFont()
|
|
|
|
size = f.pointSize()
|
|
|
|
if sys.platform.startswith('win'):
|
|
|
|
winFont = 'Cambria'
|
|
|
|
symbolFont = 'Segoe UI Symbol'
|
|
|
|
increment = 4
|
|
|
|
else:
|
|
|
|
winFont = f.family()
|
|
|
|
symbolFont = f.family()
|
|
|
|
increment = 2
|
|
|
|
font = QtGui.QFont(winFont, size + increment)
|
|
|
|
sfont = QtGui.QFont(symbolFont)
|
|
|
|
self.ui.lstHistory.setFont(font)
|
|
|
|
self.ui.txtMultiQuery.setFont(font)
|
|
|
|
self.ui.txtQuery.setFont(font)
|
|
|
|
self.ui.groupOperators.setFont(font)
|
|
|
|
self.ui.cmdClearMultilineQuery.setFont(sfont)
|
|
|
|
self.ui.cmdClearQuery.setFont(sfont)
|
|
|
|
|
2013-12-26 17:16:12 +07:00
|
|
|
self.settings = QtCore.QSettings()
|
2015-09-29 05:47:20 +07:00
|
|
|
self._restore_settings()
|
|
|
|
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2015-12-31 07:29:12 +07:00
|
|
|
# Shortcuts
|
|
|
|
shortcuts = (
|
|
|
|
(self.ui.lstRelations, QtGui.QKeySequence.Delete, self.unloadRelation),
|
2016-01-02 09:24:15 +07:00
|
|
|
(self.ui.lstRelations, 'Space', lambda: self.printRelation(self.ui.lstRelations.currentItem())),
|
2016-01-02 05:36:28 +07:00
|
|
|
(self.ui.txtQuery, QtGui.QKeySequence.MoveToNextLine, self.next_history),
|
|
|
|
(self.ui.txtQuery, QtGui.QKeySequence.MoveToPreviousLine, self.prev_history),
|
2015-12-31 07:29:12 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
self.add_shortcuts(shortcuts)
|
|
|
|
|
2016-01-02 05:36:28 +07:00
|
|
|
def next_history(self):
|
|
|
|
if self.ui.lstHistory.currentRow() + 1 == self.ui.lstHistory.count() and self.history_current_line:
|
2016-01-02 08:28:17 +07:00
|
|
|
self.ui.txtQuery.setText(self.history_current_line)
|
2016-01-02 05:36:28 +07:00
|
|
|
self.history_current_line = None
|
|
|
|
elif self.history_current_line:
|
|
|
|
self.ui.lstHistory.setCurrentRow(self.ui.lstHistory.currentRow()+1)
|
|
|
|
self.resumeHistory(self.ui.lstHistory.currentItem())
|
|
|
|
|
|
|
|
def prev_history(self):
|
|
|
|
if self.history_current_line is None:
|
2016-01-02 08:28:17 +07:00
|
|
|
self.history_current_line = self.ui.txtQuery.text()
|
|
|
|
|
2016-01-02 08:59:02 +07:00
|
|
|
if self.ui.lstHistory.currentItem() is None:
|
|
|
|
return
|
2016-01-02 08:28:17 +07:00
|
|
|
if not self.ui.lstHistory.currentItem().text() != self.ui.txtQuery.text():
|
|
|
|
self.ui.lstHistory.setCurrentRow(self.ui.lstHistory.currentRow()-1)
|
2016-01-02 05:36:28 +07:00
|
|
|
elif self.ui.lstHistory.currentRow() > 0:
|
|
|
|
self.ui.lstHistory.setCurrentRow(self.ui.lstHistory.currentRow()-1)
|
2016-01-02 08:28:17 +07:00
|
|
|
self.resumeHistory(self.ui.lstHistory.currentItem())
|
2016-01-02 05:36:28 +07:00
|
|
|
|
2015-12-31 07:29:12 +07:00
|
|
|
def add_shortcuts(self, shortcuts):
|
|
|
|
for widget,shortcut,slot in shortcuts:
|
|
|
|
action = QtWidgets.QAction(self)
|
|
|
|
action.triggered.connect(slot)
|
|
|
|
action.setShortcut(QtGui.QKeySequence(shortcut))
|
|
|
|
# I couldn't find the constant
|
|
|
|
action.setShortcutContext(0)
|
|
|
|
widget.addAction(action)
|
|
|
|
|
|
|
|
|
2011-06-14 11:21:15 +07:00
|
|
|
def checkVersion(self):
|
|
|
|
from relational import maintenance
|
2013-12-26 17:31:43 +07:00
|
|
|
online = maintenance.check_latest_version()
|
|
|
|
|
|
|
|
if online > version:
|
2015-02-19 07:00:47 +07:00
|
|
|
r = QtWidgets.QApplication.translate(
|
2013-12-26 17:31:43 +07:00
|
|
|
"Form", "New version available online: %s." % online)
|
|
|
|
elif online == version:
|
2015-02-19 07:00:47 +07:00
|
|
|
r = QtWidgets.QApplication.translate(
|
2013-12-26 17:31:43 +07:00
|
|
|
"Form", "Latest version installed.")
|
2011-06-14 11:21:15 +07:00
|
|
|
else:
|
2015-02-19 07:00:47 +07:00
|
|
|
r = QtWidgets.QApplication.translate(
|
2013-12-26 17:31:43 +07:00
|
|
|
"Form", "You are using an unstable version.")
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2015-02-19 07:00:47 +07:00
|
|
|
QtWidgets.QMessageBox.information(
|
|
|
|
self, QtWidgets.QApplication.translate("Form", "Version"), r)
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2016-01-02 09:11:20 +07:00
|
|
|
def setHistoryShown(self, history_shown):
|
|
|
|
self.history_shown = history_shown
|
|
|
|
self.settings.setValue('history_shown', history_shown)
|
|
|
|
self.ui.lstHistory.setVisible(history_shown)
|
|
|
|
self.ui.actionShow_history.setChecked(history_shown)
|
|
|
|
|
2015-05-31 17:00:59 +07:00
|
|
|
def setMultiline(self, multiline):
|
|
|
|
self.multiline = multiline
|
|
|
|
self.settings.setValue('multiline', multiline)
|
2015-11-20 10:06:59 +07:00
|
|
|
if multiline:
|
|
|
|
index = 0
|
|
|
|
else:
|
|
|
|
index = 1
|
|
|
|
self.ui.stackedWidget.setCurrentIndex(index)
|
2015-05-31 17:00:59 +07:00
|
|
|
self.ui.actionMulti_line_mode.setChecked(multiline)
|
|
|
|
|
2013-12-26 17:31:43 +07:00
|
|
|
def load_query(self, *index):
|
2011-03-20 14:31:50 +07:00
|
|
|
self.ui.txtQuery.setText(self.savedQ.itemData(index[0]).toString())
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def undoOptimize(self):
|
|
|
|
'''Undoes the optimization on the query, popping one item from the undo list'''
|
2013-12-26 17:31:43 +07:00
|
|
|
if self.undo != None:
|
2011-03-20 14:31:50 +07:00
|
|
|
self.ui.txtQuery.setText(self.undo)
|
|
|
|
|
|
|
|
def optimize(self):
|
|
|
|
'''Performs all the possible optimizations on the query'''
|
2013-12-26 17:31:43 +07:00
|
|
|
self.undo = self.ui.txtQuery.text() # Storing the query in undo list
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2016-01-02 08:28:17 +07:00
|
|
|
res_rel,query = self.user_interface.split_query(self.ui.txtQuery.text(),None)
|
2011-10-15 17:30:31 +07:00
|
|
|
try:
|
2015-07-14 04:01:35 +07:00
|
|
|
result = optimizer.optimize_all(
|
|
|
|
query, self.user_interface.relations)
|
2016-01-02 08:28:17 +07:00
|
|
|
if res_rel:
|
|
|
|
result = '%s = %s' % (res_rel, result)
|
2015-06-02 07:56:44 +07:00
|
|
|
self.ui.txtQuery.setText(result)
|
2015-02-19 07:00:47 +07:00
|
|
|
except Exception as e:
|
2015-06-16 06:22:58 +07:00
|
|
|
self.error(e)
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2013-12-26 17:31:43 +07:00
|
|
|
def resumeHistory(self, item):
|
2016-01-02 05:36:28 +07:00
|
|
|
if item is None:
|
|
|
|
return
|
2016-01-02 08:28:17 +07:00
|
|
|
itm = item.text()
|
|
|
|
self.ui.txtQuery.setText(itm)
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def execute(self):
|
2015-05-31 17:00:59 +07:00
|
|
|
|
2016-01-03 02:18:31 +07:00
|
|
|
# Show the 'Processing' frame
|
2015-12-31 11:07:23 +07:00
|
|
|
self.ui.stackedWidget.setCurrentIndex(2)
|
2015-12-20 17:54:05 +07:00
|
|
|
QtCore.QCoreApplication.processEvents()
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
try:
|
2015-12-20 17:54:05 +07:00
|
|
|
'''Executes the query'''
|
|
|
|
if self.multiline:
|
2016-01-03 02:18:31 +07:00
|
|
|
query = self.ui.txtMultiQuery.toPlainText()
|
|
|
|
self.settings.setValue('multiline/query', query)
|
|
|
|
else:
|
|
|
|
query = self.ui.txtQuery.text()
|
2015-12-20 17:54:05 +07:00
|
|
|
|
|
|
|
try:
|
2016-01-03 02:18:31 +07:00
|
|
|
self.selectedRelation = self.user_interface.multi_execute(query)
|
2015-12-20 17:54:05 +07:00
|
|
|
except Exception as e:
|
|
|
|
return self.error(e)
|
2016-01-03 02:18:31 +07:00
|
|
|
finally:
|
|
|
|
self.updateRelations() # update the list
|
|
|
|
self.showRelation(self.selectedRelation)
|
2015-12-20 17:54:05 +07:00
|
|
|
|
2016-01-03 02:18:31 +07:00
|
|
|
if not self.multiline:
|
|
|
|
# Adds to history
|
|
|
|
hitem = QtWidgets.QListWidgetItem(None, 0)
|
|
|
|
hitem.setText(query)
|
|
|
|
self.ui.lstHistory.addItem(hitem)
|
|
|
|
self.ui.lstHistory.setCurrentItem(hitem)
|
2015-12-20 17:54:05 +07:00
|
|
|
finally:
|
2016-01-03 02:18:31 +07:00
|
|
|
# Restore the normal frame
|
2015-12-31 11:07:23 +07:00
|
|
|
self.setMultiline(self.multiline)
|
2011-10-08 17:35:24 +07:00
|
|
|
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2013-12-26 17:31:43 +07:00
|
|
|
def showRelation(self, rel):
|
2011-03-20 14:31:50 +07:00
|
|
|
'''Shows the selected relation into the table'''
|
|
|
|
self.ui.table.clear()
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2013-12-26 17:31:43 +07:00
|
|
|
if rel == None: # No relation to show
|
2011-03-20 14:31:50 +07:00
|
|
|
self.ui.table.setColumnCount(1)
|
2013-12-26 17:31:43 +07:00
|
|
|
self.ui.table.headerItem().setText(0, "Empty relation")
|
2011-03-20 14:31:50 +07:00
|
|
|
return
|
2015-06-06 08:27:11 +07:00
|
|
|
self.ui.table.setColumnCount(len(rel.header))
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2013-12-26 17:31:43 +07:00
|
|
|
# Set content
|
2011-03-20 14:31:50 +07:00
|
|
|
for i in rel.content:
|
2015-02-19 07:00:47 +07:00
|
|
|
item = QtWidgets.QTreeWidgetItem()
|
2011-03-20 14:31:50 +07:00
|
|
|
for j in range(len(i)):
|
|
|
|
item.setText(j, i[j])
|
|
|
|
self.ui.table.addTopLevelItem(item)
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2013-12-26 17:31:43 +07:00
|
|
|
# Sets columns
|
2015-07-14 04:01:35 +07:00
|
|
|
for i, attr in enumerate(rel.header):
|
2015-06-06 08:27:11 +07:00
|
|
|
self.ui.table.headerItem().setText(i, attr)
|
2013-12-26 17:31:43 +07:00
|
|
|
self.ui.table.resizeColumnToContents(
|
|
|
|
i) # Must be done in order to avoid too small columns
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2013-12-26 17:31:43 +07:00
|
|
|
def printRelation(self, item):
|
2015-06-16 06:22:58 +07:00
|
|
|
self.selectedRelation = self.user_interface.relations[item.text()]
|
2011-03-20 16:49:02 +07:00
|
|
|
self.showRelation(self.selectedRelation)
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2013-12-26 17:31:43 +07:00
|
|
|
def showAttributes(self, item):
|
2011-03-20 14:31:50 +07:00
|
|
|
'''Shows the attributes of the selected relation'''
|
2015-06-02 07:56:44 +07:00
|
|
|
rel = item.text()
|
2011-03-20 16:49:02 +07:00
|
|
|
self.ui.lstAttributes.clear()
|
2015-06-16 06:22:58 +07:00
|
|
|
for j in self.user_interface.relations[rel].header:
|
2013-12-26 17:31:43 +07:00
|
|
|
self.ui.lstAttributes.addItem(j)
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def updateRelations(self):
|
|
|
|
self.ui.lstRelations.clear()
|
2015-06-16 06:22:58 +07:00
|
|
|
for i in self.user_interface.relations:
|
2011-03-20 14:31:50 +07:00
|
|
|
if i != "__builtins__":
|
|
|
|
self.ui.lstRelations.addItem(i)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def saveRelation(self):
|
2015-06-02 07:41:41 +07:00
|
|
|
if self.selectedRelation is None:
|
|
|
|
r = QtWidgets.QApplication.translate(
|
|
|
|
"Form", "Select a relation first."
|
|
|
|
)
|
|
|
|
QtWidgets.QMessageBox.information(
|
|
|
|
self, QtWidgets.QApplication.translate("Form", "Error"), r
|
|
|
|
)
|
|
|
|
return
|
2015-02-19 07:00:47 +07:00
|
|
|
filename = QtWidgets.QFileDialog.getSaveFileName(self, QtWidgets.QApplication.translate(
|
2015-06-02 07:41:41 +07:00
|
|
|
"Form", "Save Relation"), "", QtWidgets.QApplication.translate("Form", "Relations (*.csv)"))[0]
|
2013-12-26 17:31:43 +07:00
|
|
|
if (len(filename) == 0): # Returns if no file was selected
|
2011-03-20 16:49:02 +07:00
|
|
|
return
|
|
|
|
self.selectedRelation.save(filename)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def unloadRelation(self):
|
|
|
|
for i in self.ui.lstRelations.selectedItems():
|
2015-06-16 06:22:58 +07:00
|
|
|
del self.user_interface.relations[i.text()]
|
2011-03-20 14:31:50 +07:00
|
|
|
self.updateRelations()
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2015-09-09 05:38:54 +07:00
|
|
|
def newSession(self):
|
|
|
|
self.user_interface.session_reset()
|
|
|
|
self.updateRelations()
|
|
|
|
|
2011-10-13 12:06:24 +07:00
|
|
|
def editRelation(self):
|
2015-02-19 07:00:47 +07:00
|
|
|
from relational_gui import creator
|
2011-10-13 12:06:24 +07:00
|
|
|
for i in self.ui.lstRelations.selectedItems():
|
2013-12-26 17:31:43 +07:00
|
|
|
result = creator.edit_relation(
|
2015-06-16 06:22:58 +07:00
|
|
|
self.user_interface.get_relation(i.text())
|
|
|
|
)
|
2013-12-26 17:31:43 +07:00
|
|
|
if result != None:
|
2015-06-16 06:22:58 +07:00
|
|
|
self.user_interface.set_relation(i.text(), result)
|
2011-10-13 12:06:24 +07:00
|
|
|
self.updateRelations()
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2015-07-14 04:01:35 +07:00
|
|
|
def error(self, exception):
|
2015-06-16 06:22:58 +07:00
|
|
|
print (exception)
|
|
|
|
QtWidgets.QMessageBox.information(
|
|
|
|
None, QtWidgets.QApplication.translate("Form", "Error"),
|
|
|
|
str(exception)
|
|
|
|
)
|
|
|
|
|
2015-06-07 06:37:24 +07:00
|
|
|
def promptRelationName(self):
|
2015-02-23 07:19:28 +07:00
|
|
|
while True:
|
|
|
|
res = QtWidgets.QInputDialog.getText(
|
|
|
|
self,
|
|
|
|
QtWidgets.QApplication.translate("Form", "New relation"),
|
|
|
|
QtWidgets.QApplication.translate(
|
|
|
|
"Form", "Insert the name for the new relation"),
|
|
|
|
QtWidgets.QLineEdit.Normal, ''
|
|
|
|
)
|
2015-07-14 04:01:35 +07:00
|
|
|
if res[1] == False: # or len(res[0]) == 0:
|
2015-06-07 06:37:24 +07:00
|
|
|
return None
|
2015-06-02 07:56:44 +07:00
|
|
|
name = res[0]
|
2015-02-23 07:19:28 +07:00
|
|
|
if not rtypes.is_valid_relation_name(name):
|
|
|
|
r = QtWidgets.QApplication.translate(
|
2015-07-14 04:01:35 +07:00
|
|
|
"Form", str(
|
|
|
|
"Wrong name for destination relation: %s." % name)
|
2015-02-23 07:19:28 +07:00
|
|
|
)
|
|
|
|
QtWidgets.QMessageBox.information(
|
|
|
|
self, QtWidgets.QApplication.translate("Form", "Error"), r
|
|
|
|
)
|
|
|
|
continue
|
2015-06-07 06:37:24 +07:00
|
|
|
return name
|
2015-02-23 07:19:28 +07:00
|
|
|
|
2015-06-07 06:37:24 +07:00
|
|
|
def newRelation(self):
|
|
|
|
from relational_gui import creator
|
|
|
|
result = creator.edit_relation()
|
|
|
|
|
|
|
|
if result == None:
|
|
|
|
return
|
|
|
|
name = self.promptRelationName()
|
|
|
|
|
|
|
|
try:
|
2015-06-16 06:22:58 +07:00
|
|
|
self.user_interface.relations[name] = result
|
2015-06-07 06:37:24 +07:00
|
|
|
self.updateRelations()
|
|
|
|
except Exception as e:
|
2015-06-16 06:22:58 +07:00
|
|
|
self.error(e)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2013-12-26 17:16:12 +07:00
|
|
|
def closeEvent(self, event):
|
|
|
|
self.save_settings()
|
|
|
|
event.accept()
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2013-12-26 17:16:12 +07:00
|
|
|
def save_settings(self):
|
2015-06-01 07:20:29 +07:00
|
|
|
self.settings.setValue('maingui/geometry', self.saveGeometry())
|
|
|
|
self.settings.setValue('maingui/windowState', self.saveState())
|
2015-09-11 05:41:33 +07:00
|
|
|
self.settings.setValue('maingui/splitter', self.ui.splitter.saveState())
|
2015-08-03 08:58:11 +07:00
|
|
|
self.settings.setValue('maingui/relations', self.user_interface.session_dump())
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2015-09-29 05:47:20 +07:00
|
|
|
def _restore_settings(self):
|
2015-08-03 08:58:11 +07:00
|
|
|
self.user_interface.session_restore(self.settings.value('maingui/relations'))
|
|
|
|
self.updateRelations()
|
|
|
|
|
2015-07-14 04:01:35 +07:00
|
|
|
self.setMultiline(self.settings.value('multiline', 'false') == 'true')
|
2016-01-02 09:11:20 +07:00
|
|
|
self.setHistoryShown(self.settings.value('history_shown', 'true') == 'true')
|
2015-07-14 04:01:35 +07:00
|
|
|
self.ui.txtMultiQuery.setPlainText(
|
|
|
|
self.settings.value('multiline/query', ''))
|
2015-06-01 07:20:29 +07:00
|
|
|
try:
|
|
|
|
self.restoreGeometry(self.settings.value('maingui/geometry'))
|
|
|
|
self.restoreState(self.settings.value('maingui/windowState'))
|
2015-09-11 05:41:33 +07:00
|
|
|
self.ui.splitter.restoreState(self.settings.value('maingui/splitter'))
|
2015-06-01 07:20:29 +07:00
|
|
|
except:
|
|
|
|
pass
|
2011-10-13 13:44:20 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def showSurvey(self):
|
2013-12-26 17:31:43 +07:00
|
|
|
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()
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def showAbout(self):
|
2013-12-26 17:31:43 +07:00
|
|
|
if self.About == None:
|
2015-02-19 07:00:47 +07:00
|
|
|
self.About = QtWidgets.QDialog()
|
2011-03-20 14:31:50 +07:00
|
|
|
ui = about.Ui_Dialog()
|
|
|
|
ui.setupUi(self.About)
|
|
|
|
self.About.show()
|
|
|
|
|
2015-06-02 05:35:47 +07:00
|
|
|
def loadRelation(self, filenames=None):
|
2011-03-20 14:31:50 +07:00
|
|
|
'''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.'''
|
2013-12-26 17:31:43 +07:00
|
|
|
# Asking for file to load
|
2015-06-02 05:35:47 +07:00
|
|
|
if not filenames:
|
|
|
|
f = QtWidgets.QFileDialog.getOpenFileNames(self, QtWidgets.QApplication.translate(
|
2015-02-19 07:00:47 +07:00
|
|
|
"Form", "Load Relation"), "", QtWidgets.QApplication.translate("Form", "Relations (*.csv);;Text Files (*.txt);;All Files (*)"))
|
2015-06-02 05:35:47 +07:00
|
|
|
filenames = f[0]
|
2011-03-21 02:43:57 +07:00
|
|
|
|
2015-06-02 05:35:47 +07:00
|
|
|
for f in filenames:
|
|
|
|
# Default relation's name
|
2015-06-17 09:35:14 +07:00
|
|
|
name = self.user_interface.suggest_name(f)
|
|
|
|
if name is None:
|
2015-06-07 06:37:24 +07:00
|
|
|
name = self.promptRelationName()
|
|
|
|
if name is None:
|
2015-06-02 05:35:47 +07:00
|
|
|
continue
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2015-06-02 05:35:47 +07:00
|
|
|
try:
|
2015-07-14 04:01:35 +07:00
|
|
|
self.user_interface.load(f, name)
|
2015-06-02 05:35:47 +07:00
|
|
|
except Exception as e:
|
2015-06-16 06:22:58 +07:00
|
|
|
self.error(e)
|
2015-06-02 05:35:47 +07:00
|
|
|
continue
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2011-04-01 02:06:08 +07:00
|
|
|
self.updateRelations()
|
2011-03-21 11:10:22 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addProduct(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.PRODUCT)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addDifference(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.DIFFERENCE)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addUnion(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.UNION)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addIntersection(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.INTERSECTION)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addDivision(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.DIVISION)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addOLeft(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.JOIN_LEFT)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addJoin(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.JOIN)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addORight(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.JOIN_RIGHT)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addOuter(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.JOIN_FULL)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addProjection(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.PROJECTION)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addSelection(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.SELECTION)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addRename(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.RENAME)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
def addArrow(self):
|
2015-05-31 12:03:17 +07:00
|
|
|
self.addSymbolInQuery(parser.ARROW)
|
2013-12-26 17:16:12 +07:00
|
|
|
|
2013-12-26 17:31:43 +07:00
|
|
|
def addSymbolInQuery(self, symbol):
|
2015-05-31 17:00:59 +07:00
|
|
|
if self.multiline:
|
|
|
|
self.ui.txtMultiQuery.insertPlainText(symbol)
|
|
|
|
self.ui.txtMultiQuery.setFocus()
|
|
|
|
else:
|
|
|
|
self.ui.txtQuery.insert(symbol)
|
|
|
|
self.ui.txtQuery.setFocus()
|