コード例 #1
0
    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
コード例 #2
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
コード例 #3
0
ファイル: guihandler.py プロジェクト: tilakchandlo/relational
    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
コード例 #4
0
    def loadRelation(self, filename=None, name=None):
        '''Hack.
        Will run first and intercept normal behaviour when filename is none.
        '''
        if filename == None:
            files = QtGui.QFileDialog.getOpenFileNames(
                    self, 
                    QtGui.QApplication.translate("Form", "Load Relation(s)"), 
                    "", 
                    QtGui.QApplication.translate("Form", "Relations (*.csv);;Text Files (*.txt);;All Files (*)"))

            
            for tempfilename in files:       
                tmp = compatibility.get_filename(tempfilename)
                if files.count() == 1: #if we only have one element to loop through, don't react on name.
                    self.loadRelationx(tmp,name)
                    return    
                self.loadRelationx(tmp,u"")
            return
        self.loadRelationx(filename,name)