Пример #1
0
    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
Пример #2
0
 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()
Пример #3
0
    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
Пример #4
0
    def send(self):
        '''Sends the data inserted in the form'''

        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())

        # Clears the form
        self.ui.txtSystem.clear()
        self.ui.txtCountry.clear()
        self.ui.txtSchool.clear()
        self.ui.txtAge.clear()
        self.ui.txtFind.clear()
        self.ui.txtEmail.clear()
        self.ui.txtComments.clear()

        response = maintenance.send_survey(post)

        if response.status != 200:
            QtGui.QMessageBox.information(None, QtGui.QApplication.translate(
                "Form", "Error"), QtGui.QApplication.translate("Form", "Unable to send the data!"))
        else:
            QtGui.QMessageBox.information(None, QtGui.QApplication.translate(
                "Form", "Thanks"), QtGui.QApplication.translate("Form", "Thanks for sending!"))

        self.hide()
Пример #5
0
    def clearLastRelations(self):

        for i in range(0,self.ui.lstRelations.count()):
            j=self.ui.lstRelations.item(i)
            if j.text().__str__().startswith("_"):
                del self.relations[compatibility.get_py_str(j.text())]
        self.updateRelations()
        self.clearHistory()
        self.resetLastCounter()
Пример #6
0
    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__()))
Пример #7
0
    def create_relation(self):
        hlist = []

        for i in range(self.table.columnCount()):
            hlist.append(
                compatibility.get_py_str(self.table.item(0, i).text()))
        try:
            header = relation.header(hlist)
        except Exception, e:
            QtGui.QMessageBox.information(None, QtGui.QApplication.translate("Form", "Error"), "%s\n%s" % (
                QtGui.QApplication.translate("Form", "Header error!"), e.__str__()))
            return None
Пример #8
0
    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
Пример #9
0
    def create_relation(self):
        hlist = []

        for i in range(self.table.columnCount()):
            hlist.append(compatibility.get_py_str(
                self.table.item(0, i).text()))
        try:
            header = relation.header(hlist)
        except Exception, e:
            QtGui.QMessageBox.information(
                None, QtGui.QApplication.translate("Form", "Error"),
                "%s\n%s" % (QtGui.QApplication.translate(
                    "Form", "Header error!"), e.__str__()))
            return None
Пример #10
0
    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
Пример #11
0
    def send(self):
        '''Sends the data inserted in the form'''

        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())

        #Clears the form
        self.ui.txtSystem.clear()
        self.ui.txtCountry.clear()
        self.ui.txtSchool.clear()
        self.ui.txtAge.clear()
        self.ui.txtFind.clear()
        self.ui.txtEmail.clear()
        self.ui.txtComments.clear()

        response = maintenance.send_survey(post)

        if response.status != 200:
            QtGui.QMessageBox.information(
                None, QtGui.QApplication.translate("Form", "Error"),
                QtGui.QApplication.translate("Form",
                                             "Unable to send the data!"))
        else:
            QtGui.QMessageBox.information(
                None, QtGui.QApplication.translate("Form", "Thanks"),
                QtGui.QApplication.translate("Form", "Thanks for sending!"))

        self.hide()
Пример #12
0
 def unloadRelation(self):
     for i in self.ui.lstRelations.selectedItems():
         del self.relations[compatibility.get_py_str(i.text())]
     self.updateRelations()
Пример #13
0
 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)
Пример #14
0
            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
Пример #15
0
 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])
Пример #16
0
 def printRelation(self, item):
     self.selectedRelation = self.relations[
         compatibility.get_py_str(item.text())]
     self.showRelation(self.selectedRelation)
Пример #17
0
class creatorForm(QtGui.QDialog):
    def __init__(self, rel=None):
        QtGui.QDialog.__init__(self)

        self.setSizeGripEnabled(True)
        self.result_relation = None
        self.rel = rel

    def setUi(self, ui):
        self.ui = ui
        self.table = self.ui.table

        if self.rel == None:
            self.setup_empty()
        else:
            self.setup_relation(self.rel)

    def setup_relation(self, rel):

        self.table.insertRow(0)

        for i in rel.header.attributes:
            item = QtGui.QTableWidgetItem()
            item.setText(i)
            self.table.insertColumn(self.table.columnCount())
            self.table.setItem(0, self.table.columnCount() - 1, item)

        for i in rel.content:
            self.table.insertRow(self.table.rowCount())
            for j in range(len(i)):
                item = QtGui.QTableWidgetItem()
                item.setText(i[j])
                self.table.setItem(self.table.rowCount() - 1, j, item)

        pass

    def setup_empty(self):
        self.table.insertColumn(0)
        self.table.insertColumn(0)
        self.table.insertRow(0)
        self.table.insertRow(0)

        i00 = QtGui.QTableWidgetItem()
        i01 = QtGui.QTableWidgetItem()
        i10 = QtGui.QTableWidgetItem()
        i11 = QtGui.QTableWidgetItem()
        i00.setText('Field name 1')
        i01.setText('Field name 2')
        i10.setText('Value 1')
        i11.setText('Value 2')

        self.table.setItem(0, 0, i00)
        self.table.setItem(0, 1, i01)
        self.table.setItem(1, 0, i10)
        self.table.setItem(1, 1, i11)

    def create_relation(self):
        hlist = []

        for i in range(self.table.columnCount()):
            hlist.append(compatibility.get_py_str(
                self.table.item(0, i).text()))
        try:
            header = relation.header(hlist)
        except Exception, e:
            QtGui.QMessageBox.information(
                None, QtGui.QApplication.translate("Form", "Error"),
                "%s\n%s" % (QtGui.QApplication.translate(
                    "Form", "Header error!"), e.__str__()))
            return None
        r = relation.relation()
        r.header = header

        for i in range(1, self.table.rowCount()):
            hlist = []
            for j in range(self.table.columnCount()):
                try:
                    hlist.append(
                        compatibility.get_py_str(self.table.item(i, j).text()))
                except:
                    QtGui.QMessageBox.information(
                        None, QtGui.QApplication.translate("Form", "Error"),
                        QtGui.QApplication.translate(
                            "Form", "Unset value in %d,%d!" % (i + 1, j + 1)))
                    return None
            r.content.add(tuple(hlist))
        return r